Fix raw types in Neutron northbound 51/12651/4
authorRobert Varga <rovarga@cisco.com>
Fri, 7 Nov 2014 20:14:17 +0000 (21:14 +0100)
committerRobert Varga <rovarga@cisco.com>
Sat, 8 Nov 2014 10:47:50 +0000 (11:47 +0100)
Adds proper use of types and suppression magic to the factory method.

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

index a4c113c2c1803081409e61c4132770482d51f3c0..2001fb758af68801ef5f17d26cb13264438087df 100644 (file)
@@ -9,17 +9,15 @@
 package org.opendaylight.controller.networkconfig.neutron.northbound;
 
 import java.util.List;
-
 import javax.xml.bind.annotation.XmlAccessType;
 import javax.xml.bind.annotation.XmlAccessorType;
 import javax.xml.bind.annotation.XmlElement;
 import javax.xml.bind.annotation.XmlRootElement;
-
 import org.opendaylight.controller.networkconfig.neutron.NeutronNetwork;
 
 @XmlRootElement
 @XmlAccessorType(XmlAccessType.NONE)
-public class NeutronNetworkRequest implements INeutronRequest {
+public class NeutronNetworkRequest implements INeutronRequest<NeutronNetwork> {
     // See OpenStack Network API v2.0 Reference for description of
     // annotated attributes
 
@@ -50,14 +48,17 @@ public class NeutronNetworkRequest implements INeutronRequest {
         singletonNetwork = net;
     }
 
+    @Override
     public NeutronNetwork getSingleton() {
         return singletonNetwork;
     }
 
+    @Override
     public boolean isSingleton() {
         return (singletonNetwork != null);
     }
 
+    @Override
     public List<NeutronNetwork> getBulk() {
         return bulkRequest;
     }
index 12b58aa2abc54e30799fd0458a4e126b9185124a..3bfac8a4fdf4d04a8131f10c6bf74f8df017ef03 100644 (file)
@@ -9,17 +9,15 @@
 package org.opendaylight.controller.networkconfig.neutron.northbound;
 
 import java.util.List;
-
 import javax.xml.bind.annotation.XmlAccessType;
 import javax.xml.bind.annotation.XmlAccessorType;
 import javax.xml.bind.annotation.XmlElement;
 import javax.xml.bind.annotation.XmlRootElement;
-
 import org.opendaylight.controller.networkconfig.neutron.NeutronPort;
 
 @XmlRootElement
 @XmlAccessorType(XmlAccessType.NONE)
-public class NeutronPortRequest implements INeutronRequest {
+public class NeutronPortRequest implements INeutronRequest<NeutronPort> {
     // See OpenStack Network API v2.0 Reference for description of
     // annotated attributes
 
@@ -50,14 +48,17 @@ public class NeutronPortRequest implements INeutronRequest {
         singletonPort = port;
     }
 
+    @Override
     public NeutronPort getSingleton() {
         return singletonPort;
     }
 
+    @Override
     public boolean isSingleton() {
         return (singletonPort != null);
     }
 
+    @Override
     public List<NeutronPort> getBulk() {
         return bulkRequest;
     }
index 57a724c1cc60936b3a15ed80ba0c1b9bc6d53288..4c230c525bcb79ffed8fe700110bf6af34e8260a 100644 (file)
@@ -9,18 +9,15 @@
 package org.opendaylight.controller.networkconfig.neutron.northbound;
 
 import java.util.List;
-
 import javax.xml.bind.annotation.XmlAccessType;
 import javax.xml.bind.annotation.XmlAccessorType;
 import javax.xml.bind.annotation.XmlElement;
 import javax.xml.bind.annotation.XmlRootElement;
-
 import org.opendaylight.controller.networkconfig.neutron.NeutronSubnet;
 
 @XmlRootElement
 @XmlAccessorType(XmlAccessType.NONE)
-
-public class NeutronSubnetRequest implements INeutronRequest {
+public class NeutronSubnetRequest implements INeutronRequest<NeutronSubnet> {
     // See OpenStack Network API v2.0 Reference for description of
     // annotated attributes
 
@@ -54,14 +51,17 @@ public class NeutronSubnetRequest implements INeutronRequest {
         links = null;
     }
 
+    @Override
     public NeutronSubnet getSingleton() {
         return singletonSubnet;
     }
 
+    @Override
     public List<NeutronSubnet> getBulk() {
         return bulkRequest;
     }
 
+    @Override
     public boolean isSingleton() {
         return (singletonSubnet != null);
     }
index 8f05e76e1839d9c10d630635f2e4d160b43a9908..5f9653f9029776b6a8f75892502de265908d086e 100644 (file)
 
 package org.opendaylight.controller.networkconfig.neutron.northbound;
 
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.List;
+import javax.ws.rs.core.UriInfo;
 import org.opendaylight.controller.networkconfig.neutron.INeutronObject;
 import org.opendaylight.controller.networkconfig.neutron.NeutronNetwork;
 import org.opendaylight.controller.networkconfig.neutron.NeutronPort;
@@ -17,12 +22,6 @@ import org.opendaylight.controller.networkconfig.neutron.NeutronSubnet;
 import org.opendaylight.controller.northbound.commons.exception.BadRequestException;
 import org.opendaylight.controller.northbound.commons.exception.ResourceNotFoundException;
 
-import javax.ws.rs.core.UriInfo;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.Comparator;
-import java.util.List;
-
 public class PaginatedRequestFactory {
 
     public static class PaginationResults<T extends INeutronObject> {
@@ -35,26 +34,33 @@ public class PaginatedRequestFactory {
         }
     }
 
-    public static <T extends INeutronObject> INeutronRequest createRequest(Integer limit, String marker,
+    /*
+     * SuppressWarnings is needed because the compiler does not understand that we
+     * are actually safe here.
+     *
+     * FIXME: the only caller performs a cast back, so this is not actually necessary.
+     */
+    @SuppressWarnings("unchecked")
+    public static <T extends INeutronObject> INeutronRequest<T> createRequest(Integer limit, String marker,
                                                                            Boolean pageReverse,
                                                                            UriInfo uriInfo,
                                                                            List<T> collection,
                                                                            Class<T> clazz) {
-        PaginationResults results = _paginate(limit, marker, pageReverse, uriInfo, collection);
+        PaginationResults<T> results = _paginate(limit, marker, pageReverse, uriInfo, collection);
 
         if (clazz.equals(NeutronNetwork.class)){
-            return new NeutronNetworkRequest(results.collection, results.links);
+            return (INeutronRequest<T>) new NeutronNetworkRequest((List<NeutronNetwork>) results.collection, results.links);
         }
         if (clazz.equals(NeutronSubnet.class)){
-            return new NeutronSubnetRequest(results.collection, results.links);
+            return (INeutronRequest<T>) new NeutronSubnetRequest((List<NeutronSubnet>) results.collection, results.links);
         }
         if (clazz.equals(NeutronPort.class)){
-            return new NeutronPortRequest(results.collection, results.links);
+            return (INeutronRequest<T>) new NeutronPortRequest((List<NeutronPort>) results.collection, results.links);
         }
         return null;
     }
 
-    private static <T extends INeutronObject> PaginationResults _paginate(Integer limit, String marker, Boolean pageReverse, UriInfo uriInfo, List<T> collection) {
+    private static <T extends INeutronObject> PaginationResults<T> _paginate(Integer limit, String marker, Boolean pageReverse, UriInfo uriInfo, List<T> collection) {
         List<NeutronPageLink> links = new ArrayList<>();
         Integer startPos = null;
         String startMarker;
@@ -80,10 +86,12 @@ public class PaginatedRequestFactory {
             class MarkerObject implements INeutronObject {
                 private String id;
 
+                @Override
                 public String getID() {
                     return id;
                 }
 
+                @Override
                 public void setID(String id) {
                     this.id = id;
                 }
@@ -149,6 +157,6 @@ public class PaginatedRequestFactory {
             links.add(previous);
         }
 
-        return new PaginationResults(collection, links);
+        return new PaginationResults<T>(collection, links);
     }
 }