blob: 6efb1390d9129c51df0139a8e8fd31d70f993610 [file] [log] [blame]
Thomas Vachuska7d693f52014-10-21 19:17:57 -07001/*
Thomas Vachuska4f1a60c2014-10-28 13:39:07 -07002 * Copyright 2014 Open Networking Laboratory
Thomas Vachuska7d693f52014-10-21 19:17:57 -07003 *
Thomas Vachuska4f1a60c2014-10-28 13:39:07 -07004 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
Thomas Vachuska7d693f52014-10-21 19:17:57 -07007 *
Thomas Vachuska4f1a60c2014-10-28 13:39:07 -07008 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
Thomas Vachuska7d693f52014-10-21 19:17:57 -070015 */
Brian O'Connorabafb502014-12-02 22:26:20 -080016package org.onosproject.cli;
tom1380eee2014-09-24 09:22:02 -070017
Jonathan Hart61d4ebc2014-10-29 11:08:26 -070018import java.util.Comparator;
19
Brian O'Connorabafb502014-12-02 22:26:20 -080020import org.onosproject.cluster.ControllerNode;
Thomas Vachuskaebf5e542015-02-03 19:38:13 -080021import org.onosproject.core.Application;
Brian O'Connorabafb502014-12-02 22:26:20 -080022import org.onosproject.core.ApplicationId;
23import org.onosproject.net.ConnectPoint;
24import org.onosproject.net.Element;
25import org.onosproject.net.ElementId;
26import org.onosproject.net.Port;
27import org.onosproject.net.flow.FlowRule;
28import org.onosproject.net.host.PortAddresses;
29import org.onosproject.net.topology.TopologyCluster;
tom1380eee2014-09-24 09:22:02 -070030
tom1380eee2014-09-24 09:22:02 -070031/**
32 * Various comparators.
33 */
34public final class Comparators {
35
36 // Ban construction
37 private Comparators() {
38 }
39
Thomas Vachuskae0f804a2014-10-27 23:40:48 -070040 public static final Comparator<ApplicationId> APP_ID_COMPARATOR = new Comparator<ApplicationId>() {
41 @Override
42 public int compare(ApplicationId id1, ApplicationId id2) {
43 return id1.id() - id2.id();
44 }
45 };
46
Thomas Vachuskaebf5e542015-02-03 19:38:13 -080047 public static final Comparator<Application> APP_COMPARATOR = new Comparator<Application>() {
48 @Override
49 public int compare(Application app1, Application app2) {
50 return app1.id().id() - app2.id().id();
51 }
52 };
53
tom1380eee2014-09-24 09:22:02 -070054 public static final Comparator<ElementId> ELEMENT_ID_COMPARATOR = new Comparator<ElementId>() {
55 @Override
56 public int compare(ElementId id1, ElementId id2) {
tom545708e2014-10-09 17:10:02 -070057 return id1.toString().compareTo(id2.toString());
tom1380eee2014-09-24 09:22:02 -070058 }
59 };
60
61 public static final Comparator<Element> ELEMENT_COMPARATOR = new Comparator<Element>() {
62 @Override
63 public int compare(Element e1, Element e2) {
tom545708e2014-10-09 17:10:02 -070064 return e1.id().toString().compareTo(e2.id().toString());
tom1380eee2014-09-24 09:22:02 -070065 }
66 };
67
68 public static final Comparator<FlowRule> FLOW_RULE_COMPARATOR = new Comparator<FlowRule>() {
69 @Override
70 public int compare(FlowRule f1, FlowRule f2) {
71 return Long.valueOf(f1.id().value()).compareTo(f2.id().value());
72 }
73 };
74
75 public static final Comparator<Port> PORT_COMPARATOR = new Comparator<Port>() {
76 @Override
77 public int compare(Port p1, Port p2) {
78 long delta = p1.number().toLong() - p2.number().toLong();
79 return delta == 0 ? 0 : (delta < 0 ? -1 : +1);
80 }
81 };
82
83 public static final Comparator<TopologyCluster> CLUSTER_COMPARATOR = new Comparator<TopologyCluster>() {
84 @Override
85 public int compare(TopologyCluster c1, TopologyCluster c2) {
86 return c1.id().index() - c2.id().index();
87 }
88 };
89
90 public static final Comparator<ControllerNode> NODE_COMPARATOR = new Comparator<ControllerNode>() {
91 @Override
92 public int compare(ControllerNode ci1, ControllerNode ci2) {
93 return ci1.id().toString().compareTo(ci2.id().toString());
94 }
95 };
96
Jonathan Hart61d4ebc2014-10-29 11:08:26 -070097 public static final Comparator<ConnectPoint> CONNECT_POINT_COMPARATOR = new Comparator<ConnectPoint>() {
98 @Override
99 public int compare(ConnectPoint o1, ConnectPoint o2) {
100 int compareId = ELEMENT_ID_COMPARATOR.compare(o1.elementId(), o2.elementId());
101 return (compareId != 0) ?
102 compareId :
103 Long.signum(o1.port().toLong() - o2.port().toLong());
104 }
105 };
106
107 public static final Comparator<PortAddresses> ADDRESSES_COMPARATOR = new Comparator<PortAddresses>() {
108 @Override
109 public int compare(PortAddresses arg0, PortAddresses arg1) {
110 return CONNECT_POINT_COMPARATOR.compare(arg0.connectPoint(), arg1.connectPoint());
111 }
112 };
113
tom1380eee2014-09-24 09:22:02 -0700114}