1 package org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.common;
3 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.Ordered;
4 import java.util.Comparator;
7 * Comparator for comparing objects which extend Ordered.
11 public class OrderComparator<T extends Ordered> implements Comparator<T> {
13 @SuppressWarnings("rawtypes")
14 private static final OrderComparator INSTANCE = new OrderComparator();
16 @SuppressWarnings("unchecked")
17 public static <T extends Ordered> OrderComparator<T> build() {
22 public int compare(T obj1, T obj2) {
23 if(obj1 ==null || obj2==null ) {
24 throw new NullPointerException("Cannot compare null Actions");
25 } else if (obj1.getOrder() == null) {
26 throw new NullPointerException(errorMsg(obj1));
27 } else if (obj2.getOrder() == null) {
28 throw new NullPointerException(errorMsg(obj2));
30 return obj1.getOrder().compareTo(obj2.getOrder());
33 private String errorMsg(T obj) {
34 return "The comparing model " + obj + "has getOrder() == null. An order is mandatory";