blob: 74664666bad107e77fc04fe5f5d1236402e88b67 [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 */
tom91c7bd02014-09-25 22:50:44 -070016package org.onlab.onos.cli;
tom1380eee2014-09-24 09:22:02 -070017
Jonathan Hart61d4ebc2014-10-29 11:08:26 -070018import java.util.Comparator;
19
tom1380eee2014-09-24 09:22:02 -070020import org.onlab.onos.cluster.ControllerNode;
Jonathan Hart61d4ebc2014-10-29 11:08:26 -070021import org.onlab.onos.core.ApplicationId;
22import org.onlab.onos.net.ConnectPoint;
tom1380eee2014-09-24 09:22:02 -070023import org.onlab.onos.net.Element;
24import org.onlab.onos.net.ElementId;
25import org.onlab.onos.net.Port;
26import org.onlab.onos.net.flow.FlowRule;
Jonathan Hart61d4ebc2014-10-29 11:08:26 -070027import org.onlab.onos.net.host.PortAddresses;
tom1380eee2014-09-24 09:22:02 -070028import org.onlab.onos.net.topology.TopologyCluster;
29
tom1380eee2014-09-24 09:22:02 -070030/**
31 * Various comparators.
32 */
33public final class Comparators {
34
35 // Ban construction
36 private Comparators() {
37 }
38
Thomas Vachuskae0f804a2014-10-27 23:40:48 -070039 public static final Comparator<ApplicationId> APP_ID_COMPARATOR = new Comparator<ApplicationId>() {
40 @Override
41 public int compare(ApplicationId id1, ApplicationId id2) {
42 return id1.id() - id2.id();
43 }
44 };
45
tom1380eee2014-09-24 09:22:02 -070046 public static final Comparator<ElementId> ELEMENT_ID_COMPARATOR = new Comparator<ElementId>() {
47 @Override
48 public int compare(ElementId id1, ElementId id2) {
tom545708e2014-10-09 17:10:02 -070049 return id1.toString().compareTo(id2.toString());
tom1380eee2014-09-24 09:22:02 -070050 }
51 };
52
53 public static final Comparator<Element> ELEMENT_COMPARATOR = new Comparator<Element>() {
54 @Override
55 public int compare(Element e1, Element e2) {
tom545708e2014-10-09 17:10:02 -070056 return e1.id().toString().compareTo(e2.id().toString());
tom1380eee2014-09-24 09:22:02 -070057 }
58 };
59
60 public static final Comparator<FlowRule> FLOW_RULE_COMPARATOR = new Comparator<FlowRule>() {
61 @Override
62 public int compare(FlowRule f1, FlowRule f2) {
63 return Long.valueOf(f1.id().value()).compareTo(f2.id().value());
64 }
65 };
66
67 public static final Comparator<Port> PORT_COMPARATOR = new Comparator<Port>() {
68 @Override
69 public int compare(Port p1, Port p2) {
70 long delta = p1.number().toLong() - p2.number().toLong();
71 return delta == 0 ? 0 : (delta < 0 ? -1 : +1);
72 }
73 };
74
75 public static final Comparator<TopologyCluster> CLUSTER_COMPARATOR = new Comparator<TopologyCluster>() {
76 @Override
77 public int compare(TopologyCluster c1, TopologyCluster c2) {
78 return c1.id().index() - c2.id().index();
79 }
80 };
81
82 public static final Comparator<ControllerNode> NODE_COMPARATOR = new Comparator<ControllerNode>() {
83 @Override
84 public int compare(ControllerNode ci1, ControllerNode ci2) {
85 return ci1.id().toString().compareTo(ci2.id().toString());
86 }
87 };
88
Jonathan Hart61d4ebc2014-10-29 11:08:26 -070089 public static final Comparator<ConnectPoint> CONNECT_POINT_COMPARATOR = new Comparator<ConnectPoint>() {
90 @Override
91 public int compare(ConnectPoint o1, ConnectPoint o2) {
92 int compareId = ELEMENT_ID_COMPARATOR.compare(o1.elementId(), o2.elementId());
93 return (compareId != 0) ?
94 compareId :
95 Long.signum(o1.port().toLong() - o2.port().toLong());
96 }
97 };
98
99 public static final Comparator<PortAddresses> ADDRESSES_COMPARATOR = new Comparator<PortAddresses>() {
100 @Override
101 public int compare(PortAddresses arg0, PortAddresses arg1) {
102 return CONNECT_POINT_COMPARATOR.compare(arg0.connectPoint(), arg1.connectPoint());
103 }
104 };
105
tom1380eee2014-09-24 09:22:02 -0700106}