2 * Copyright (c) 2014, 2015 Cisco Systems, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
9 package org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.common;
11 import java.io.Serializable;
12 import java.util.Comparator;
13 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.Ordered;
16 * Comparator for comparing objects which extend Ordered.
20 public class OrderComparator<T extends Ordered> implements Comparator<T>, Serializable {
21 private static final long serialVersionUID = 1L;
23 @SuppressWarnings("rawtypes")
24 private static final OrderComparator INSTANCE = new OrderComparator();
26 @SuppressWarnings("unchecked")
27 public static <T extends Ordered> OrderComparator<T> build() {
32 public int compare(T obj1, T obj2) {
33 if (obj1 == null || obj2 == null) {
34 throw new NullPointerException("Cannot compare null Actions");
35 } else if (obj1.getOrder() == null) {
36 throw new NullPointerException(errorMsg(obj1));
37 } else if (obj2.getOrder() == null) {
38 throw new NullPointerException(errorMsg(obj2));
40 return obj1.getOrder().compareTo(obj2.getOrder());
43 private String errorMsg(T obj) {
44 return "The comparing model " + obj + "has getOrder() == null. An order is mandatory";