blob: 80b31d5f8a8a2e17ccb7e0ff3a187b06eb0f8189 [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
Thomas Vachuskae0f804a2014-10-27 23:40:48 -070021import org.onlab.onos.core.ApplicationId;
tom1380eee2014-09-24 09:22:02 -070022import org.onlab.onos.cluster.ControllerNode;
23import org.onlab.onos.net.Element;
24import org.onlab.onos.net.ElementId;
25import org.onlab.onos.net.Port;
26import org.onlab.onos.net.flow.FlowRule;
27import org.onlab.onos.net.topology.TopologyCluster;
28
29import java.util.Comparator;
30
31/**
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
tom1380eee2014-09-24 09:22:02 -070047 public static final Comparator<ElementId> ELEMENT_ID_COMPARATOR = new Comparator<ElementId>() {
48 @Override
49 public int compare(ElementId id1, ElementId id2) {
tom545708e2014-10-09 17:10:02 -070050 return id1.toString().compareTo(id2.toString());
tom1380eee2014-09-24 09:22:02 -070051 }
52 };
53
54 public static final Comparator<Element> ELEMENT_COMPARATOR = new Comparator<Element>() {
55 @Override
56 public int compare(Element e1, Element e2) {
tom545708e2014-10-09 17:10:02 -070057 return e1.id().toString().compareTo(e2.id().toString());
tom1380eee2014-09-24 09:22:02 -070058 }
59 };
60
61 public static final Comparator<FlowRule> FLOW_RULE_COMPARATOR = new Comparator<FlowRule>() {
62 @Override
63 public int compare(FlowRule f1, FlowRule f2) {
64 return Long.valueOf(f1.id().value()).compareTo(f2.id().value());
65 }
66 };
67
68 public static final Comparator<Port> PORT_COMPARATOR = new Comparator<Port>() {
69 @Override
70 public int compare(Port p1, Port p2) {
71 long delta = p1.number().toLong() - p2.number().toLong();
72 return delta == 0 ? 0 : (delta < 0 ? -1 : +1);
73 }
74 };
75
76 public static final Comparator<TopologyCluster> CLUSTER_COMPARATOR = new Comparator<TopologyCluster>() {
77 @Override
78 public int compare(TopologyCluster c1, TopologyCluster c2) {
79 return c1.id().index() - c2.id().index();
80 }
81 };
82
83 public static final Comparator<ControllerNode> NODE_COMPARATOR = new Comparator<ControllerNode>() {
84 @Override
85 public int compare(ControllerNode ci1, ControllerNode ci2) {
86 return ci1.id().toString().compareTo(ci2.id().toString());
87 }
88 };
89
90}