Simon Hunt
Committed by Gerrit Code Review

Replace comparator definitions with their Lambda equivalents.

Change-Id: Ib626e086f78aa950be20cb84e56a3769517bac0a
...@@ -23,13 +23,13 @@ import org.onosproject.incubator.net.virtual.TenantId; ...@@ -23,13 +23,13 @@ import org.onosproject.incubator.net.virtual.TenantId;
23 import org.onosproject.incubator.net.virtual.VirtualDevice; 23 import org.onosproject.incubator.net.virtual.VirtualDevice;
24 import org.onosproject.incubator.net.virtual.VirtualNetwork; 24 import org.onosproject.incubator.net.virtual.VirtualNetwork;
25 import org.onosproject.incubator.net.virtual.VirtualPort; 25 import org.onosproject.incubator.net.virtual.VirtualPort;
26 -import org.onosproject.net.key.DeviceKey;
27 import org.onosproject.net.ConnectPoint; 26 import org.onosproject.net.ConnectPoint;
28 import org.onosproject.net.Element; 27 import org.onosproject.net.Element;
29 import org.onosproject.net.ElementId; 28 import org.onosproject.net.ElementId;
30 import org.onosproject.net.Port; 29 import org.onosproject.net.Port;
31 import org.onosproject.net.flow.FlowRule; 30 import org.onosproject.net.flow.FlowRule;
32 import org.onosproject.net.group.Group; 31 import org.onosproject.net.group.Group;
32 +import org.onosproject.net.key.DeviceKey;
33 import org.onosproject.net.region.Region; 33 import org.onosproject.net.region.Region;
34 import org.onosproject.net.statistic.TypedFlowEntryWithLoad; 34 import org.onosproject.net.statistic.TypedFlowEntryWithLoad;
35 import org.onosproject.net.topology.TopologyCluster; 35 import org.onosproject.net.topology.TopologyCluster;
...@@ -46,37 +46,20 @@ public final class Comparators { ...@@ -46,37 +46,20 @@ public final class Comparators {
46 private Comparators() { 46 private Comparators() {
47 } 47 }
48 48
49 - public static final Comparator<ApplicationId> APP_ID_COMPARATOR = new Comparator<ApplicationId>() { 49 + public static final Comparator<ApplicationId> APP_ID_COMPARATOR =
50 - @Override 50 + (id1, id2) -> id1.id() - id2.id();
51 - public int compare(ApplicationId id1, ApplicationId id2) {
52 - return id1.id() - id2.id();
53 - }
54 - };
55 51
56 - public static final Comparator<Application> APP_COMPARATOR = new Comparator<Application>() { 52 + public static final Comparator<Application> APP_COMPARATOR =
57 - @Override 53 + (app1, app2) -> app1.id().id() - app2.id().id();
58 - public int compare(Application app1, Application app2) {
59 - return app1.id().id() - app2.id().id();
60 - }
61 - };
62 54
63 - public static final Comparator<ElementId> ELEMENT_ID_COMPARATOR = new Comparator<ElementId>() { 55 + public static final Comparator<ElementId> ELEMENT_ID_COMPARATOR =
64 - @Override 56 + (id1, id2) -> id1.toString().compareTo(id2.toString());
65 - public int compare(ElementId id1, ElementId id2) {
66 - return id1.toString().compareTo(id2.toString());
67 - }
68 - };
69 57
70 - public static final Comparator<Element> ELEMENT_COMPARATOR = new Comparator<Element>() { 58 + public static final Comparator<Element> ELEMENT_COMPARATOR =
71 - @Override 59 + (e1, e2) -> e1.id().toString().compareTo(e2.id().toString());
72 - public int compare(Element e1, Element e2) {
73 - return e1.id().toString().compareTo(e2.id().toString());
74 - }
75 - };
76 60
77 - public static final Comparator<FlowRule> FLOW_RULE_COMPARATOR = new Comparator<FlowRule>() { 61 + public static final Comparator<FlowRule> FLOW_RULE_COMPARATOR =
78 - @Override 62 + (f1, f2) -> {
79 - public int compare(FlowRule f1, FlowRule f2) {
80 // Compare table IDs in ascending order 63 // Compare table IDs in ascending order
81 int tableCompare = f1.tableId() - f2.tableId(); 64 int tableCompare = f1.tableId() - f2.tableId();
82 if (tableCompare != 0) { 65 if (tableCompare != 0) {
...@@ -87,105 +70,59 @@ public final class Comparators { ...@@ -87,105 +70,59 @@ public final class Comparators {
87 return (priorityCompare == 0) 70 return (priorityCompare == 0)
88 ? Long.valueOf(f1.id().value()).compareTo(f2.id().value()) 71 ? Long.valueOf(f1.id().value()).compareTo(f2.id().value())
89 : priorityCompare; 72 : priorityCompare;
90 - }
91 }; 73 };
92 74
93 - public static final Comparator<Group> GROUP_COMPARATOR = new Comparator<Group>() { 75 + public static final Comparator<Group> GROUP_COMPARATOR =
94 - @Override 76 + (g1, g2) -> Long.valueOf(g1.id().id()).compareTo((long) g2.id().id());
95 - public int compare(Group g1, Group g2) {
96 - return Long.valueOf(g1.id().id()).compareTo(Long.valueOf(g2.id().id()));
97 - }
98 - };
99 77
100 - public static final Comparator<Port> PORT_COMPARATOR = new Comparator<Port>() { 78 + public static final Comparator<Port> PORT_COMPARATOR =
101 - @Override 79 + (p1, p2) -> {
102 - public int compare(Port p1, Port p2) {
103 long delta = p1.number().toLong() - p2.number().toLong(); 80 long delta = p1.number().toLong() - p2.number().toLong();
104 return delta == 0 ? 0 : (delta < 0 ? -1 : +1); 81 return delta == 0 ? 0 : (delta < 0 ? -1 : +1);
105 - }
106 }; 82 };
107 83
108 - public static final Comparator<TopologyCluster> CLUSTER_COMPARATOR = new Comparator<TopologyCluster>() { 84 + public static final Comparator<TopologyCluster> CLUSTER_COMPARATOR =
109 - @Override 85 + (c1, c2) -> c1.id().index() - c2.id().index();
110 - public int compare(TopologyCluster c1, TopologyCluster c2) {
111 - return c1.id().index() - c2.id().index();
112 - }
113 - };
114 86
115 - public static final Comparator<ControllerNode> NODE_COMPARATOR = new Comparator<ControllerNode>() { 87 + public static final Comparator<ControllerNode> NODE_COMPARATOR =
116 - @Override 88 + (ci1, ci2) -> ci1.id().toString().compareTo(ci2.id().toString());
117 - public int compare(ControllerNode ci1, ControllerNode ci2) {
118 - return ci1.id().toString().compareTo(ci2.id().toString());
119 - }
120 - };
121 89
122 - public static final Comparator<ConnectPoint> CONNECT_POINT_COMPARATOR = new Comparator<ConnectPoint>() { 90 + public static final Comparator<ConnectPoint> CONNECT_POINT_COMPARATOR =
123 - @Override 91 + (o1, o2) -> {
124 - public int compare(ConnectPoint o1, ConnectPoint o2) {
125 int compareId = ELEMENT_ID_COMPARATOR.compare(o1.elementId(), o2.elementId()); 92 int compareId = ELEMENT_ID_COMPARATOR.compare(o1.elementId(), o2.elementId());
126 return (compareId != 0) ? 93 return (compareId != 0) ?
127 compareId : 94 compareId :
128 Long.signum(o1.port().toLong() - o2.port().toLong()); 95 Long.signum(o1.port().toLong() - o2.port().toLong());
129 - }
130 }; 96 };
131 97
132 - public static final Comparator<Interface> INTERFACES_COMPARATOR = (intf1, intf2) -> 98 + public static final Comparator<Interface> INTERFACES_COMPARATOR =
99 + (intf1, intf2) ->
133 CONNECT_POINT_COMPARATOR.compare(intf1.connectPoint(), intf2.connectPoint()); 100 CONNECT_POINT_COMPARATOR.compare(intf1.connectPoint(), intf2.connectPoint());
134 101
135 public static final Comparator<TypedFlowEntryWithLoad> TYPEFLOWENTRY_WITHLOAD_COMPARATOR = 102 public static final Comparator<TypedFlowEntryWithLoad> TYPEFLOWENTRY_WITHLOAD_COMPARATOR =
136 - new Comparator<TypedFlowEntryWithLoad>() { 103 + (fe1, fe2) -> {
137 - @Override
138 - public int compare(TypedFlowEntryWithLoad fe1, TypedFlowEntryWithLoad fe2) {
139 long delta = fe1.load().rate() - fe2.load().rate(); 104 long delta = fe1.load().rate() - fe2.load().rate();
140 return delta == 0 ? 0 : (delta > 0 ? -1 : +1); 105 return delta == 0 ? 0 : (delta > 0 ? -1 : +1);
141 - }
142 }; 106 };
143 107
144 - public static final Comparator<DeviceKey> DEVICE_KEY_COMPARATOR = new Comparator<DeviceKey>() { 108 + public static final Comparator<DeviceKey> DEVICE_KEY_COMPARATOR =
145 - @Override 109 + (dk1, dk2) -> dk1.deviceKeyId().id().compareTo(dk2.deviceKeyId().id());
146 - public int compare(DeviceKey deviceKey1, DeviceKey deviceKey2) {
147 - return deviceKey1.deviceKeyId().id().compareTo(deviceKey2.deviceKeyId().id());
148 - }
149 - };
150 110
151 - public static final Comparator<Region> REGION_COMPARATOR = new Comparator<Region>() { 111 + public static final Comparator<Region> REGION_COMPARATOR =
152 - @Override 112 + (r1, r2) -> r1.id().toString().compareTo(r2.id().toString());
153 - public int compare(Region region1, Region region2) {
154 - return region1.id().toString().compareTo(region2.id().toString());
155 - }
156 - };
157 113
158 - public static final Comparator<UiTopoLayout> LAYOUT_COMPARATOR = new Comparator<UiTopoLayout>() { 114 + public static final Comparator<UiTopoLayout> LAYOUT_COMPARATOR =
159 - @Override 115 + (l1, l2) -> l1.id().toString().compareTo(l2.id().toString());
160 - public int compare(UiTopoLayout l1, UiTopoLayout l2) {
161 - return l1.id().toString().compareTo(l2.id().toString());
162 - }
163 - };
164 - public static final Comparator<TenantId> TENANT_ID_COMPARATOR = new Comparator<TenantId>() {
165 - @Override
166 - public int compare(TenantId tenant1, TenantId tenant2) {
167 - return tenant1.id().compareTo(tenant2.id());
168 - }
169 - };
170 116
171 - public static final Comparator<VirtualNetwork> VIRTUAL_NETWORK_COMPARATOR = new Comparator<VirtualNetwork>() { 117 + public static final Comparator<TenantId> TENANT_ID_COMPARATOR =
172 - @Override 118 + (t1, t2) -> t1.id().compareTo(t2.id());
173 - public int compare(VirtualNetwork virtualNetwork1, VirtualNetwork virtualNetwork2) {
174 - return virtualNetwork1.tenantId().toString().compareTo(virtualNetwork2.tenantId().toString());
175 - }
176 - };
177 119
178 - public static final Comparator<VirtualDevice> VIRTUAL_DEVICE_COMPARATOR = new Comparator<VirtualDevice>() { 120 + public static final Comparator<VirtualNetwork> VIRTUAL_NETWORK_COMPARATOR =
179 - @Override 121 + (v1, v2) -> v1.tenantId().toString().compareTo(v2.tenantId().toString());
180 - public int compare(VirtualDevice virtualDevice1, VirtualDevice virtualDevice2) {
181 - return virtualDevice1.id().toString().compareTo(virtualDevice2.id().toString());
182 - }
183 - };
184 122
185 - public static final Comparator<VirtualPort> VIRTUAL_PORT_COMPARATOR = new Comparator<VirtualPort>() { 123 + public static final Comparator<VirtualDevice> VIRTUAL_DEVICE_COMPARATOR =
186 - @Override 124 + (v1, v2) -> v1.id().toString().compareTo(v2.id().toString());
187 - public int compare(VirtualPort virtualPort1, VirtualPort virtualPort2) { 125 +
188 - return virtualPort1.number().toString().compareTo(virtualPort2.number().toString()); 126 + public static final Comparator<VirtualPort> VIRTUAL_PORT_COMPARATOR =
189 - } 127 + (v1, v2) -> v1.number().toString().compareTo(v2.number().toString());
190 - };
191 } 128 }
......