Thomas Vachuska | 7d693f5 | 2014-10-21 19:17:57 -0700 | [diff] [blame] | 1 | /* |
Ray Milkey | 34c9590 | 2015-04-15 09:47:53 -0700 | [diff] [blame] | 2 | * Copyright 2014-2015 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 | */ |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 16 | package org.onosproject.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 | |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 20 | import org.onosproject.cluster.ControllerNode; |
Thomas Vachuska | ebf5e54 | 2015-02-03 19:38:13 -0800 | [diff] [blame] | 21 | import org.onosproject.core.Application; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 22 | import org.onosproject.core.ApplicationId; |
| 23 | import org.onosproject.net.ConnectPoint; |
| 24 | import org.onosproject.net.Element; |
| 25 | import org.onosproject.net.ElementId; |
| 26 | import org.onosproject.net.Port; |
| 27 | import org.onosproject.net.flow.FlowRule; |
Srikanth Vavilapalli | 10e75cd | 2015-04-13 16:21:24 -0700 | [diff] [blame] | 28 | import org.onosproject.net.group.Group; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 29 | import org.onosproject.net.host.PortAddresses; |
| 30 | import org.onosproject.net.topology.TopologyCluster; |
tom | 1380eee | 2014-09-24 09:22:02 -0700 | [diff] [blame] | 31 | |
tom | 1380eee | 2014-09-24 09:22:02 -0700 | [diff] [blame] | 32 | /** |
| 33 | * Various comparators. |
| 34 | */ |
| 35 | public final class Comparators { |
| 36 | |
| 37 | // Ban construction |
| 38 | private Comparators() { |
| 39 | } |
| 40 | |
Thomas Vachuska | e0f804a | 2014-10-27 23:40:48 -0700 | [diff] [blame] | 41 | public static final Comparator<ApplicationId> APP_ID_COMPARATOR = new Comparator<ApplicationId>() { |
| 42 | @Override |
| 43 | public int compare(ApplicationId id1, ApplicationId id2) { |
| 44 | return id1.id() - id2.id(); |
| 45 | } |
| 46 | }; |
| 47 | |
Thomas Vachuska | ebf5e54 | 2015-02-03 19:38:13 -0800 | [diff] [blame] | 48 | public static final Comparator<Application> APP_COMPARATOR = new Comparator<Application>() { |
| 49 | @Override |
| 50 | public int compare(Application app1, Application app2) { |
| 51 | return app1.id().id() - app2.id().id(); |
| 52 | } |
| 53 | }; |
| 54 | |
tom | 1380eee | 2014-09-24 09:22:02 -0700 | [diff] [blame] | 55 | public static final Comparator<ElementId> ELEMENT_ID_COMPARATOR = new Comparator<ElementId>() { |
| 56 | @Override |
| 57 | public int compare(ElementId id1, ElementId id2) { |
tom | 545708e | 2014-10-09 17:10:02 -0700 | [diff] [blame] | 58 | return id1.toString().compareTo(id2.toString()); |
tom | 1380eee | 2014-09-24 09:22:02 -0700 | [diff] [blame] | 59 | } |
| 60 | }; |
| 61 | |
| 62 | public static final Comparator<Element> ELEMENT_COMPARATOR = new Comparator<Element>() { |
| 63 | @Override |
| 64 | public int compare(Element e1, Element e2) { |
tom | 545708e | 2014-10-09 17:10:02 -0700 | [diff] [blame] | 65 | return e1.id().toString().compareTo(e2.id().toString()); |
tom | 1380eee | 2014-09-24 09:22:02 -0700 | [diff] [blame] | 66 | } |
| 67 | }; |
| 68 | |
| 69 | public static final Comparator<FlowRule> FLOW_RULE_COMPARATOR = new Comparator<FlowRule>() { |
| 70 | @Override |
| 71 | public int compare(FlowRule f1, FlowRule f2) { |
| 72 | return Long.valueOf(f1.id().value()).compareTo(f2.id().value()); |
| 73 | } |
| 74 | }; |
| 75 | |
Srikanth Vavilapalli | 10e75cd | 2015-04-13 16:21:24 -0700 | [diff] [blame] | 76 | public static final Comparator<Group> GROUP_COMPARATOR = new Comparator<Group>() { |
| 77 | @Override |
| 78 | public int compare(Group g1, Group g2) { |
| 79 | return Long.valueOf(g1.id().id()).compareTo(Long.valueOf(g2.id().id())); |
| 80 | } |
| 81 | }; |
| 82 | |
tom | 1380eee | 2014-09-24 09:22:02 -0700 | [diff] [blame] | 83 | public static final Comparator<Port> PORT_COMPARATOR = new Comparator<Port>() { |
| 84 | @Override |
| 85 | public int compare(Port p1, Port p2) { |
| 86 | long delta = p1.number().toLong() - p2.number().toLong(); |
| 87 | return delta == 0 ? 0 : (delta < 0 ? -1 : +1); |
| 88 | } |
| 89 | }; |
| 90 | |
| 91 | public static final Comparator<TopologyCluster> CLUSTER_COMPARATOR = new Comparator<TopologyCluster>() { |
| 92 | @Override |
| 93 | public int compare(TopologyCluster c1, TopologyCluster c2) { |
| 94 | return c1.id().index() - c2.id().index(); |
| 95 | } |
| 96 | }; |
| 97 | |
| 98 | public static final Comparator<ControllerNode> NODE_COMPARATOR = new Comparator<ControllerNode>() { |
| 99 | @Override |
| 100 | public int compare(ControllerNode ci1, ControllerNode ci2) { |
| 101 | return ci1.id().toString().compareTo(ci2.id().toString()); |
| 102 | } |
| 103 | }; |
| 104 | |
Jonathan Hart | 61d4ebc | 2014-10-29 11:08:26 -0700 | [diff] [blame] | 105 | public static final Comparator<ConnectPoint> CONNECT_POINT_COMPARATOR = new Comparator<ConnectPoint>() { |
| 106 | @Override |
| 107 | public int compare(ConnectPoint o1, ConnectPoint o2) { |
| 108 | int compareId = ELEMENT_ID_COMPARATOR.compare(o1.elementId(), o2.elementId()); |
| 109 | return (compareId != 0) ? |
| 110 | compareId : |
| 111 | Long.signum(o1.port().toLong() - o2.port().toLong()); |
| 112 | } |
| 113 | }; |
| 114 | |
| 115 | public static final Comparator<PortAddresses> ADDRESSES_COMPARATOR = new Comparator<PortAddresses>() { |
| 116 | @Override |
| 117 | public int compare(PortAddresses arg0, PortAddresses arg1) { |
| 118 | return CONNECT_POINT_COMPARATOR.compare(arg0.connectPoint(), arg1.connectPoint()); |
| 119 | } |
| 120 | }; |
| 121 | |
tom | 1380eee | 2014-09-24 09:22:02 -0700 | [diff] [blame] | 122 | } |