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 org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.Ordered;
12 import java.util.Comparator;
15 * Comparator for comparing objects which extend Ordered.
19 public class OrderComparator<T extends Ordered> implements Comparator<T> {
21 @SuppressWarnings("rawtypes")
22 private static final OrderComparator INSTANCE = new OrderComparator();
24 @SuppressWarnings("unchecked")
25 public static <T extends Ordered> OrderComparator<T> build() {
30 public int compare(T obj1, T obj2) {
31 if(obj1 ==null || obj2==null ) {
32 throw new NullPointerException("Cannot compare null Actions");
33 } else if (obj1.getOrder() == null) {
34 throw new NullPointerException(errorMsg(obj1));
35 } else if (obj2.getOrder() == null) {
36 throw new NullPointerException(errorMsg(obj2));
38 return obj1.getOrder().compareTo(obj2.getOrder());
41 private String errorMsg(T obj) {
42 return "The comparing model " + obj + "has getOrder() == null. An order is mandatory";