blob: 807af279370c7d8df7c74b0666f16c5c4740aa22 [file] [log] [blame]
Thomas Vachuska7d693f52014-10-21 19:17:57 -07001/*
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing,
13 * software distributed under the License is distributed on an
14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 * KIND, either express or implied. See the License for the
16 * specific language governing permissions and limitations
17 * under the License.
18 */
tom91c7bd02014-09-25 22:50:44 -070019package org.onlab.onos.cli;
tom1380eee2014-09-24 09:22:02 -070020
21import org.onlab.onos.cluster.ControllerNode;
22import org.onlab.onos.net.Element;
23import org.onlab.onos.net.ElementId;
24import org.onlab.onos.net.Port;
25import org.onlab.onos.net.flow.FlowRule;
26import org.onlab.onos.net.topology.TopologyCluster;
27
28import java.util.Comparator;
29
30/**
31 * Various comparators.
32 */
33public final class Comparators {
34
35 // Ban construction
36 private Comparators() {
37 }
38
39 public static final Comparator<ElementId> ELEMENT_ID_COMPARATOR = new Comparator<ElementId>() {
40 @Override
41 public int compare(ElementId id1, ElementId id2) {
tom545708e2014-10-09 17:10:02 -070042 return id1.toString().compareTo(id2.toString());
tom1380eee2014-09-24 09:22:02 -070043 }
44 };
45
46 public static final Comparator<Element> ELEMENT_COMPARATOR = new Comparator<Element>() {
47 @Override
48 public int compare(Element e1, Element e2) {
tom545708e2014-10-09 17:10:02 -070049 return e1.id().toString().compareTo(e2.id().toString());
tom1380eee2014-09-24 09:22:02 -070050 }
51 };
52
53 public static final Comparator<FlowRule> FLOW_RULE_COMPARATOR = new Comparator<FlowRule>() {
54 @Override
55 public int compare(FlowRule f1, FlowRule f2) {
56 return Long.valueOf(f1.id().value()).compareTo(f2.id().value());
57 }
58 };
59
60 public static final Comparator<Port> PORT_COMPARATOR = new Comparator<Port>() {
61 @Override
62 public int compare(Port p1, Port p2) {
63 long delta = p1.number().toLong() - p2.number().toLong();
64 return delta == 0 ? 0 : (delta < 0 ? -1 : +1);
65 }
66 };
67
68 public static final Comparator<TopologyCluster> CLUSTER_COMPARATOR = new Comparator<TopologyCluster>() {
69 @Override
70 public int compare(TopologyCluster c1, TopologyCluster c2) {
71 return c1.id().index() - c2.id().index();
72 }
73 };
74
75 public static final Comparator<ControllerNode> NODE_COMPARATOR = new Comparator<ControllerNode>() {
76 @Override
77 public int compare(ControllerNode ci1, ControllerNode ci2) {
78 return ci1.id().toString().compareTo(ci2.id().toString());
79 }
80 };
81
82}