Thomas Vachuska | 7d693f5 | 2014-10-21 19:17:57 -0700 | [diff] [blame] | 1 | /* |
Thomas Vachuska | 4f1a60c | 2014-10-28 13:39:07 -0700 | [diff] [blame^] | 2 | * Copyright 2014 Open Networking Laboratory |
Thomas Vachuska | 7d693f5 | 2014-10-21 19:17:57 -0700 | [diff] [blame] | 3 | * |
Thomas Vachuska | 4f1a60c | 2014-10-28 13:39:07 -0700 | [diff] [blame^] | 4 | * 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 Vachuska | 7d693f5 | 2014-10-21 19:17:57 -0700 | [diff] [blame] | 7 | * |
Thomas Vachuska | 4f1a60c | 2014-10-28 13:39:07 -0700 | [diff] [blame^] | 8 | * 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 Vachuska | 7d693f5 | 2014-10-21 19:17:57 -0700 | [diff] [blame] | 15 | */ |
tom | 91c7bd0 | 2014-09-25 22:50:44 -0700 | [diff] [blame] | 16 | package org.onlab.onos.cli; |
tom | 1380eee | 2014-09-24 09:22:02 -0700 | [diff] [blame] | 17 | |
Thomas Vachuska | e0f804a | 2014-10-27 23:40:48 -0700 | [diff] [blame] | 18 | import org.onlab.onos.core.ApplicationId; |
tom | 1380eee | 2014-09-24 09:22:02 -0700 | [diff] [blame] | 19 | import org.onlab.onos.cluster.ControllerNode; |
| 20 | import org.onlab.onos.net.Element; |
| 21 | import org.onlab.onos.net.ElementId; |
| 22 | import org.onlab.onos.net.Port; |
| 23 | import org.onlab.onos.net.flow.FlowRule; |
| 24 | import org.onlab.onos.net.topology.TopologyCluster; |
| 25 | |
| 26 | import java.util.Comparator; |
| 27 | |
| 28 | /** |
| 29 | * Various comparators. |
| 30 | */ |
| 31 | public final class Comparators { |
| 32 | |
| 33 | // Ban construction |
| 34 | private Comparators() { |
| 35 | } |
| 36 | |
Thomas Vachuska | e0f804a | 2014-10-27 23:40:48 -0700 | [diff] [blame] | 37 | 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 | |
tom | 1380eee | 2014-09-24 09:22:02 -0700 | [diff] [blame] | 44 | public static final Comparator<ElementId> ELEMENT_ID_COMPARATOR = new Comparator<ElementId>() { |
| 45 | @Override |
| 46 | public int compare(ElementId id1, ElementId id2) { |
tom | 545708e | 2014-10-09 17:10:02 -0700 | [diff] [blame] | 47 | return id1.toString().compareTo(id2.toString()); |
tom | 1380eee | 2014-09-24 09:22:02 -0700 | [diff] [blame] | 48 | } |
| 49 | }; |
| 50 | |
| 51 | public static final Comparator<Element> ELEMENT_COMPARATOR = new Comparator<Element>() { |
| 52 | @Override |
| 53 | public int compare(Element e1, Element e2) { |
tom | 545708e | 2014-10-09 17:10:02 -0700 | [diff] [blame] | 54 | return e1.id().toString().compareTo(e2.id().toString()); |
tom | 1380eee | 2014-09-24 09:22:02 -0700 | [diff] [blame] | 55 | } |
| 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 | } |