blob: fa32c7d4016a31c6d5aaf0deadf45fcd473bd06d [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
Thomas Vachuskae0f804a2014-10-27 23:40:48 -070018import org.onlab.onos.core.ApplicationId;
tom1380eee2014-09-24 09:22:02 -070019import org.onlab.onos.cluster.ControllerNode;
20import org.onlab.onos.net.Element;
21import org.onlab.onos.net.ElementId;
22import org.onlab.onos.net.Port;
23import org.onlab.onos.net.flow.FlowRule;
24import org.onlab.onos.net.topology.TopologyCluster;
25
26import java.util.Comparator;
27
28/**
29 * Various comparators.
30 */
31public final class Comparators {
32
33 // Ban construction
34 private Comparators() {
35 }
36
Thomas Vachuskae0f804a2014-10-27 23:40:48 -070037 public static final Comparator<ApplicationId> APP_ID_COMPARATOR = new Comparator<ApplicationId>() {
38 @Override
39 public int compare(ApplicationId id1, ApplicationId id2) {
40 return id1.id() - id2.id();
41 }
42 };
43
tom1380eee2014-09-24 09:22:02 -070044 public static final Comparator<ElementId> ELEMENT_ID_COMPARATOR = new Comparator<ElementId>() {
45 @Override
46 public int compare(ElementId id1, ElementId id2) {
tom545708e2014-10-09 17:10:02 -070047 return id1.toString().compareTo(id2.toString());
tom1380eee2014-09-24 09:22:02 -070048 }
49 };
50
51 public static final Comparator<Element> ELEMENT_COMPARATOR = new Comparator<Element>() {
52 @Override
53 public int compare(Element e1, Element e2) {
tom545708e2014-10-09 17:10:02 -070054 return e1.id().toString().compareTo(e2.id().toString());
tom1380eee2014-09-24 09:22:02 -070055 }
56 };
57
58 public static final Comparator<FlowRule> FLOW_RULE_COMPARATOR = new Comparator<FlowRule>() {
59 @Override
60 public int compare(FlowRule f1, FlowRule f2) {
61 return Long.valueOf(f1.id().value()).compareTo(f2.id().value());
62 }
63 };
64
65 public static final Comparator<Port> PORT_COMPARATOR = new Comparator<Port>() {
66 @Override
67 public int compare(Port p1, Port p2) {
68 long delta = p1.number().toLong() - p2.number().toLong();
69 return delta == 0 ? 0 : (delta < 0 ? -1 : +1);
70 }
71 };
72
73 public static final Comparator<TopologyCluster> CLUSTER_COMPARATOR = new Comparator<TopologyCluster>() {
74 @Override
75 public int compare(TopologyCluster c1, TopologyCluster c2) {
76 return c1.id().index() - c2.id().index();
77 }
78 };
79
80 public static final Comparator<ControllerNode> NODE_COMPARATOR = new Comparator<ControllerNode>() {
81 @Override
82 public int compare(ControllerNode ci1, ControllerNode ci2) {
83 return ci1.id().toString().compareTo(ci2.id().toString());
84 }
85 };
86
87}