BUG2608: Using the right buffer id for no buffer
[openflowplugin.git] / openflowplugin / src / main / java / org / opendaylight / openflowplugin / openflow / md / core / sal / convertor / common / OrderComparator.java
1 package org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.common;
2
3 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.Ordered;
4
5 import java.util.Comparator;
6
7 /**
8  * Comparator for comparing objects which extend Ordered.
9  *
10  * @param <T>
11  */
12 public class OrderComparator<T extends Ordered> implements Comparator<T> {
13
14     private static OrderComparator instance = new OrderComparator();
15     public static OrderComparator build() {
16         return instance;
17     }
18
19     @Override
20     public int compare(T obj1, T obj2) {
21         if(obj1 ==null || obj2==null ) {
22             throw new NullPointerException("Cannot compare null Actions");
23         } else if (obj1.getOrder() == null) {
24             throw new NullPointerException(errorMsg(obj1));
25         } else if (obj2.getOrder() == null) {
26             throw new NullPointerException(errorMsg(obj2));
27         }
28         return obj1.getOrder().compareTo(obj2.getOrder());
29     }
30
31     private String errorMsg(T obj) {
32         return "The comparing model " + obj + "has getOrder() == null. An order is mandatory";
33     }
34 }