Fix odlparent 3 Checkstyle issues
[groupbasedpolicy.git] / neutron-ovsdb / src / main / java / org / opendaylight / groupbasedpolicy / neutron / ovsdb / util / InventoryHelper.java
index 5621ca00ca5cb31965b70acc8cdf9a784b04156a..173d2e1430e9a29c5765eb414cab9267a496629d 100755 (executable)
@@ -12,11 +12,11 @@ import static org.opendaylight.groupbasedpolicy.neutron.ovsdb.util.OvsdbHelper.g
 import static org.opendaylight.groupbasedpolicy.util.DataStoreHelper.readFromDs;
 import static org.opendaylight.groupbasedpolicy.util.DataStoreHelper.submitToDs;
 
+import com.google.common.base.Optional;
 import java.util.ArrayList;
 import java.util.HashSet;
 import java.util.List;
 import java.util.Set;
-
 import org.apache.commons.lang3.StringUtils;
 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
 import org.opendaylight.controller.md.sal.binding.api.ReadWriteTransaction;
@@ -44,24 +44,25 @@ import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-import com.google.common.base.Optional;
-
-public class InventoryHelper {
+public final class InventoryHelper {
 
     private static final Logger LOG = LoggerFactory.getLogger(InventoryHelper.class);
     private static final String HEX = "0x";
 
+    private InventoryHelper() {
+    }
+
     /**
-     * Convert an OpenFlow Datapath ID to a Long
+     * Convert an OpenFlow Datapath ID to a Long.
      *
      * @param dpid The OpenFlow Datapath ID
      * @return The Long representation of the DPID
      */
     public static Long getLongFromDpid(String dpid) {
         String[] addressInBytes = dpid.split(":");
-        Long address = (Long.decode(HEX + addressInBytes[2]) << 40) | (Long.decode(HEX + addressInBytes[3]) << 32)
-                | (Long.decode(HEX + addressInBytes[4]) << 24) | (Long.decode(HEX + addressInBytes[5]) << 16)
-                | (Long.decode(HEX + addressInBytes[6]) << 8) | (Long.decode(HEX + addressInBytes[7]));
+        Long address = Long.decode(HEX + addressInBytes[2]) << 40 | Long.decode(HEX + addressInBytes[3]) << 32
+                | Long.decode(HEX + addressInBytes[4]) << 24 | Long.decode(HEX + addressInBytes[5]) << 16
+                | Long.decode(HEX + addressInBytes[6]) << 8 | Long.decode(HEX + addressInBytes[7]);
         return address;
     }
 
@@ -140,7 +141,7 @@ public class InventoryHelper {
     /**
      * Read the {@link OfOverlayNodeConfig} augmentation from the
      * Inventory Node, and verify that the tunnel types we need
-     * are present
+     * are present.
      *
      * @param nodeIdString The inventory node id string
      * @param requiredTunnelTypes the list of tunnel types
@@ -174,7 +175,8 @@ public class InventoryHelper {
         return true;
     }
 
-    public static InstanceIdentifier<ExternalInterfaces> addOfOverlayExternalPort(NodeId nodeId, NodeConnectorId ncId, DataBroker dataBroker) {
+    public static InstanceIdentifier<ExternalInterfaces> addOfOverlayExternalPort(NodeId nodeId, NodeConnectorId ncId,
+        DataBroker dataBroker) {
         InstanceIdentifier<ExternalInterfaces> nodeExternalInterfacesIid = InstanceIdentifier.builder(Nodes.class)
             .child(Node.class, new NodeKey(nodeId))
             .augmentation(OfOverlayNodeConfig.class)
@@ -219,7 +221,7 @@ public class InventoryHelper {
     public static void updateOfOverlayConfig(IpAddress ip, String nodeIdString, String nodeConnectorIdString,
             AbstractTunnelType tunnelType, DataBroker dataBroker) {
 
-        if ((ip == null) || (nodeIdString == null) || (nodeConnectorIdString == null)) {
+        if (ip == null || nodeIdString == null || nodeConnectorIdString == null) {
             LOG.debug("Can't update OfOverlay: requisite information not present");
             return;
         }
@@ -231,10 +233,10 @@ public class InventoryHelper {
 
         // If it exists, use it in new augmentation constructor, else new augmentation
         OfOverlayNodeConfigBuilder ofOverlayNodeConfigBuilder;
-        Set<Tunnel> existingTunnels = new HashSet<Tunnel>();
+        Set<Tunnel> existingTunnels = new HashSet<>();
         if (ofConfig != null) {
             ofOverlayNodeConfigBuilder = new OfOverlayNodeConfigBuilder(ofConfig);
-            if(ofConfig.getTunnel() != null) {
+            if (ofConfig.getTunnel() != null) {
                 existingTunnels.addAll(ofConfig.getTunnel());
             }
         } else {
@@ -276,12 +278,12 @@ public class InventoryHelper {
 
         // Update the OfOverlayNodeConfig with the new tunnel information
         if (!existingTunnels.isEmpty()) {
-            ofOverlayNodeConfigBuilder.setTunnel(new ArrayList<Tunnel>(existingTunnels));
+            ofOverlayNodeConfigBuilder.setTunnel(new ArrayList<>(existingTunnels));
         }
         OfOverlayNodeConfig newConfig = ofOverlayNodeConfigBuilder.build();
         if (addOfOverlayConfig(newConfig, new NodeId(nodeIdString), dataBroker)) {
-            LOG.trace("updateOfOverlayConfig - Added Tunnel: {} to Node: {} at NodeConnector: {}",tunnelBuilder.build(), nodeIdString, nodeConnectorIdString);
-            return;
+            LOG.trace("updateOfOverlayConfig - Added Tunnel: {} to Node: {} at NodeConnector: {}",
+                tunnelBuilder.build(), nodeIdString, nodeConnectorIdString);
         } else {
             LOG.error("updateOfOverlayConfig - could not write OfOverlayNodeConfig: {} to datastore.", newConfig);
         }
@@ -311,42 +313,42 @@ public class InventoryHelper {
 
         // runs only if some tunnels were really removed
         if (existingTunnels.removeAll(tunnelsToRemove)) {
-            ReadWriteTransaction wTx = dataBroker.newReadWriteTransaction();
+            ReadWriteTransaction writeTx = dataBroker.newReadWriteTransaction();
             for (Tunnel tunnel : tunnelsToRemove) {
                 InstanceIdentifier<Tunnel> tunnelIid = InstanceIdentifier.builder(Nodes.class)
                     .child(Node.class, new NodeKey(new NodeId(nodeIdString)))
                     .augmentation(OfOverlayNodeConfig.class)
                     .child(Tunnel.class, tunnel.getKey())
                     .build();
-                wTx.delete(LogicalDatastoreType.CONFIGURATION, tunnelIid);
+                writeTx.delete(LogicalDatastoreType.CONFIGURATION, tunnelIid);
                 LOG.trace("Removing tunnel: {} from node {}",tunnel, nodeIdString);
             }
-            submitToDs(wTx);
+            submitToDs(writeTx);
         }
     }
 
     private static boolean addOfOverlayConfig(OfOverlayNodeConfig newConfig, NodeId nodeId, DataBroker dataBroker) {
-        ReadWriteTransaction wTx = dataBroker.newReadWriteTransaction();
+        ReadWriteTransaction writeTx = dataBroker.newReadWriteTransaction();
         InstanceIdentifier<OfOverlayNodeConfig> ofOverlayNodeIid = InstanceIdentifier.builder(Nodes.class)
             .child(Node.class, new NodeKey(nodeId))
             .augmentation(OfOverlayNodeConfig.class)
             .build();
-        wTx.put(LogicalDatastoreType.CONFIGURATION, ofOverlayNodeIid, newConfig, true);
+        writeTx.put(LogicalDatastoreType.CONFIGURATION, ofOverlayNodeIid, newConfig, true);
         LOG.trace("Adding tunnel: {} to node {}", newConfig, nodeId.getValue());
-        return submitToDs(wTx);
+        return submitToDs(writeTx);
     }
 
     private static boolean addTunnelsOfOverlayConfig(List<Tunnel> tunnels, NodeId nodeId, DataBroker dataBroker) {
-        ReadWriteTransaction wTx = dataBroker.newReadWriteTransaction();
+        ReadWriteTransaction writeTx = dataBroker.newReadWriteTransaction();
         for (Tunnel tunnel : tunnels) {
             InstanceIdentifier<Tunnel> tunnelIid = InstanceIdentifier.builder(Nodes.class)
                 .child(Node.class, new NodeKey(nodeId))
                 .augmentation(OfOverlayNodeConfig.class)
                 .child(Tunnel.class, tunnel.getKey())
                 .build();
-            wTx.put(LogicalDatastoreType.CONFIGURATION, tunnelIid, tunnel, true);
+            writeTx.put(LogicalDatastoreType.CONFIGURATION, tunnelIid, tunnel, true);
             LOG.trace("Adding tunnel: {} to node {}",tunnel, nodeId.getValue());
         }
-        return submitToDs(wTx);
+        return submitToDs(writeTx);
     }
 }