Thomas Vachuska | 7d693f5 | 2014-10-21 19:17:57 -0700 | [diff] [blame^] | 1 | /* |
| 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 | */ |
tom | 91c7bd0 | 2014-09-25 22:50:44 -0700 | [diff] [blame] | 19 | package org.onlab.onos.cli; |
tom | 1380eee | 2014-09-24 09:22:02 -0700 | [diff] [blame] | 20 | |
| 21 | import org.onlab.onos.cluster.ControllerNode; |
| 22 | import org.onlab.onos.net.Element; |
| 23 | import org.onlab.onos.net.ElementId; |
| 24 | import org.onlab.onos.net.Port; |
| 25 | import org.onlab.onos.net.flow.FlowRule; |
| 26 | import org.onlab.onos.net.topology.TopologyCluster; |
| 27 | |
| 28 | import java.util.Comparator; |
| 29 | |
| 30 | /** |
| 31 | * Various comparators. |
| 32 | */ |
| 33 | public 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) { |
tom | 545708e | 2014-10-09 17:10:02 -0700 | [diff] [blame] | 42 | return id1.toString().compareTo(id2.toString()); |
tom | 1380eee | 2014-09-24 09:22:02 -0700 | [diff] [blame] | 43 | } |
| 44 | }; |
| 45 | |
| 46 | public static final Comparator<Element> ELEMENT_COMPARATOR = new Comparator<Element>() { |
| 47 | @Override |
| 48 | public int compare(Element e1, Element e2) { |
tom | 545708e | 2014-10-09 17:10:02 -0700 | [diff] [blame] | 49 | return e1.id().toString().compareTo(e2.id().toString()); |
tom | 1380eee | 2014-09-24 09:22:02 -0700 | [diff] [blame] | 50 | } |
| 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 | } |