]> git.basschouten.com Git - openhab-addons.git/blob
6efb210418cc6bae0a4442affe218885716c2e27
[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 import org.apache.commons.lang.ObjectUtils;
18
19 /**
20  * Comperator to sort a Warning first by Severity, second by the onSet date.
21  *
22  * @author Martin Koehler - Initial contribution
23  */
24 public class SeverityComparator implements Comparator<DwdWarningData> {
25
26     @Override
27     public int compare(DwdWarningData o1, DwdWarningData o2) {
28         Comparator.comparingInt(d -> ((DwdWarningData) d).getSeverity().getOrder());
29         Comparator.comparing(DwdWarningData::getOnset);
30
31         int result = Integer.compare(o1.getSeverity().getOrder(), o2.getSeverity().getOrder());
32         if (result == 0) {
33             result = ObjectUtils.compare(o1.getOnset(), o2.getOnset());
34         }
35         return result;
36     }
37 }