2 * Copyright (c) 2010-2023 Contributors to the openHAB project
4 * See the NOTICE file(s) distributed with this work for additional
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
11 * SPDX-License-Identifier: EPL-2.0
13 package org.openhab.binding.dwdunwetter.internal.dto;
15 import java.util.Comparator;
16 import java.util.Objects;
19 * Comperator to sort a Warning first by Severity, second by the onSet date.
21 * @author Martin Koehler - Initial contribution
23 public class SeverityComparator implements Comparator<DwdWarningData> {
26 public int compare(DwdWarningData o1, DwdWarningData o2) {
27 Comparator.comparingInt(d -> ((DwdWarningData) d).getSeverity().getOrder());
28 Comparator.comparing(DwdWarningData::getOnset);
30 int result = Integer.compare(o1.getSeverity().getOrder(), o2.getSeverity().getOrder());
32 if (Objects.equals(o1.getOnset(), o2.getOnset())) {
34 } else if (o1.getOnset() == null) {
36 } else if (o2.getOnset() == null) {
39 return o1.getOnset().compareTo(o2.getOnset());