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 | |
Jonathan Hart | 61d4ebc | 2014-10-29 11:08:26 -0700 | [diff] [blame] | 18 | import java.util.Comparator; |
| 19 | |
tom | 1380eee | 2014-09-24 09:22:02 -0700 | [diff] [blame] | 20 | import org.onlab.onos.cluster.ControllerNode; |
Jonathan Hart | 61d4ebc | 2014-10-29 11:08:26 -0700 | [diff] [blame] | 21 | import org.onlab.onos.core.ApplicationId; |
| 22 | import org.onlab.onos.net.ConnectPoint; |
tom | 1380eee | 2014-09-24 09:22:02 -0700 | [diff] [blame] | 23 | import org.onlab.onos.net.Element; |
| 24 | import org.onlab.onos.net.ElementId; |
| 25 | import org.onlab.onos.net.Port; |
| 26 | import org.onlab.onos.net.flow.FlowRule; |
Jonathan Hart | 61d4ebc | 2014-10-29 11:08:26 -0700 | [diff] [blame] | 27 | import org.onlab.onos.net.host.PortAddresses; |
tom | 1380eee | 2014-09-24 09:22:02 -0700 | [diff] [blame] | 28 | import org.onlab.onos.net.topology.TopologyCluster; |
| 29 | |
tom | 1380eee | 2014-09-24 09:22:02 -0700 | [diff] [blame] | 30 | /** |
| 31 | * Various comparators. |
| 32 | */ |
| 33 | public final class Comparators { |
| 34 | |
| 35 | // Ban construction |
| 36 | private Comparators() { |
| 37 | } |
| 38 | |
Thomas Vachuska | e0f804a | 2014-10-27 23:40:48 -0700 | [diff] [blame] | 39 | 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 | |
tom | 1380eee | 2014-09-24 09:22:02 -0700 | [diff] [blame] | 46 | public static final Comparator<ElementId> ELEMENT_ID_COMPARATOR = new Comparator<ElementId>() { |
| 47 | @Override |
| 48 | public int compare(ElementId id1, ElementId id2) { |
tom | 545708e | 2014-10-09 17:10:02 -0700 | [diff] [blame] | 49 | return id1.toString().compareTo(id2.toString()); |
tom | 1380eee | 2014-09-24 09:22:02 -0700 | [diff] [blame] | 50 | } |
| 51 | }; |
| 52 | |
| 53 | public static final Comparator<Element> ELEMENT_COMPARATOR = new Comparator<Element>() { |
| 54 | @Override |
| 55 | public int compare(Element e1, Element e2) { |
tom | 545708e | 2014-10-09 17:10:02 -0700 | [diff] [blame] | 56 | return e1.id().toString().compareTo(e2.id().toString()); |
tom | 1380eee | 2014-09-24 09:22:02 -0700 | [diff] [blame] | 57 | } |
| 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 Hart | 61d4ebc | 2014-10-29 11:08:26 -0700 | [diff] [blame] | 89 | 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 | |
tom | 1380eee | 2014-09-24 09:22:02 -0700 | [diff] [blame] | 106 | } |