Reuse NeutronObject comparator 52/12652/4
authorRobert Varga <rovarga@cisco.com>
Fri, 7 Nov 2014 20:23:58 +0000 (21:23 +0100)
committerRobert Varga <rovarga@cisco.com>
Sat, 8 Nov 2014 10:47:50 +0000 (11:47 +0100)
This is a static object, which is thread-safe and can therefore be
reused betwen instances and requests.

Change-Id: Ib920ff6736ab451b402e4691717eb2f4eee59a4c
Signed-off-by: Robert Varga <rovarga@cisco.com>
opendaylight/northbound/networkconfiguration/neutron/src/main/java/org/opendaylight/controller/networkconfig/neutron/northbound/PaginatedRequestFactory.java

index 5f9653f9029776b6a8f75892502de265908d086e..0e8e605527fb3ca726cfaf07779ff1bad68b5876 100644 (file)
@@ -23,6 +23,12 @@ import org.opendaylight.controller.northbound.commons.exception.BadRequestExcept
 import org.opendaylight.controller.northbound.commons.exception.ResourceNotFoundException;
 
 public class PaginatedRequestFactory {
+    private static final Comparator<INeutronObject> NEUTRON_OBJECT_COMPARATOR = new Comparator<INeutronObject>() {
+        @Override
+        public int compare(INeutronObject o1, INeutronObject o2) {
+            return o1.getID().compareTo(o2.getID());
+        }
+    };
 
     public static class PaginationResults<T extends INeutronObject> {
         List<T> collection;
@@ -68,14 +74,7 @@ public class PaginatedRequestFactory {
         Boolean firstPage = false;
         Boolean lastPage = false;
 
-        Comparator<INeutronObject> neutronObjectComparator = new Comparator<INeutronObject>() {
-            @Override
-            public int compare(INeutronObject o1, INeutronObject o2) {
-                return o1.getID().compareTo(o2.getID());
-            }
-        };
-
-        Collections.sort(collection, neutronObjectComparator);
+        Collections.sort(collection, NEUTRON_OBJECT_COMPARATOR);
 
         if (marker == null) {
             startPos = 0;
@@ -101,7 +100,7 @@ public class PaginatedRequestFactory {
 
             markerObject.setID(marker);
 
-            startPos = Collections.binarySearch(collection, markerObject, neutronObjectComparator);
+            startPos = Collections.binarySearch(collection, markerObject, NEUTRON_OBJECT_COMPARATOR);
 
             if (!pageReverse){
                 startPos = startPos + 1;