]> git.basschouten.com Git - openhab-addons.git/blob
4c9854f1a69a91e6b702beb8527e9702e48f2956
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2020 Contributors to the openHAB project
3  *
4  * See the NOTICE file(s) distributed with this work for additional
5  * information.
6  *
7  * This program and the accompanying materials are made available under the
8  * terms of the Eclipse Public License 2.0 which is available at
9  * http://www.eclipse.org/legal/epl-2.0
10  *
11  * SPDX-License-Identifier: EPL-2.0
12  */
13 package org.openhab.binding.dwdunwetter.internal.data;
14
15 import java.util.Comparator;
16
17 /**
18  * Comperator to sort a Warning first by Severity, second by the onSet date.
19  *
20  * @author Martin Koehler - Initial contribution
21  */
22 public class SeverityComparator implements Comparator<DwdWarningData> {
23
24     @Override
25     public int compare(DwdWarningData o1, DwdWarningData o2) {
26         Comparator.comparingInt(d -> ((DwdWarningData) d).getSeverity().getOrder());
27         Comparator.comparing(DwdWarningData::getOnset);
28
29         int result = Integer.compare(o1.getSeverity().getOrder(), o2.getSeverity().getOrder());
30         if (result == 0) {
31             if (o1.getOnset() == o2.getOnset()) {
32                 return 0;
33             } else if (o1.getOnset() == null) {
34                 return -1;
35             } else if (o2.getOnset() == null) {
36                 return 1;
37             }
38             return o1.getOnset().compareTo(o2.getOnset());
39         }
40         return result;
41     }
42 }