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