FlowHash renamed to FlowRegistryKey
[openflowplugin.git] / openflowplugin-impl / src / main / java / org / opendaylight / openflowplugin / impl / registry / flow / FlowHashFactory.java
index 9747d014409ea774bd0fd9f3616431c627bee453..4e1601a00b8ba384941e8a6553561b3503106eca 100644 (file)
@@ -8,11 +8,13 @@
 
 package org.opendaylight.openflowplugin.impl.registry.flow;
 
+import com.google.common.base.MoreObjects;
+import com.google.common.base.Preconditions;
 import com.google.common.primitives.Longs;
 import java.math.BigInteger;
 import java.util.Objects;
-import org.opendaylight.openflowplugin.api.openflow.device.DeviceContext;
-import org.opendaylight.openflowplugin.api.openflow.registry.flow.FlowHash;
+import org.opendaylight.openflowplugin.api.OFConstants;
+import org.opendaylight.openflowplugin.api.openflow.registry.flow.FlowRegistryKey;
 import org.opendaylight.openflowplugin.impl.util.HashUtil;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.Flow;
 
@@ -25,17 +27,17 @@ public class FlowHashFactory {
     public FlowHashFactory() {
     }
 
-    public static FlowHash create(Flow flow, DeviceContext deviceContext) {
-        long hash = calculateHash(flow, deviceContext);
-        return new FlowHashDto(hash, flow);
+    public static FlowRegistryKey create(Flow flow, short version) {
+        long hash = calculateHash(flow, version);
+        return new FlowRegistryKeyDto(hash, flow);
     }
 
-    private static long calculateHash(Flow flow, DeviceContext deviceContext) {
-        return HashUtil.calculateMatchHash(flow.getMatch(), deviceContext);
+    private static long calculateHash(Flow flow, short version) {
+        return HashUtil.calculateMatchHash(flow.getMatch(), version);
     }
 
 
-    private static final class FlowHashDto implements FlowHash {
+    private static final class FlowRegistryKeyDto implements FlowRegistryKey {
 
         private final long flowHash;
         private final int intHashCode;
@@ -44,12 +46,12 @@ public class FlowHashFactory {
         private final int priority;
         private final BigInteger cookie;
 
-        public FlowHashDto(final long flowHash, final Flow flow) {
+        public FlowRegistryKeyDto(final long flowHash, final Flow flow) {
             this.flowHash = flowHash;
             this.intHashCode = Longs.hashCode(flowHash);
-            tableId = flow.getTableId();
-            priority = flow.getPriority();
-            cookie = flow.getCookie().getValue();
+            tableId = Preconditions.checkNotNull(flow.getTableId(), "flow tableId must not be null");
+            priority = Preconditions.checkNotNull(flow.getPriority(), "flow priority must not be null");
+            cookie = MoreObjects.firstNonNull(flow.getCookie(), OFConstants.DEFAULT_FLOW_COOKIE).getValue();
         }
 
 
@@ -63,10 +65,10 @@ public class FlowHashFactory {
             if (null == obj) {
                 return false;
             }
-            if (!(obj instanceof FlowHash)) {
+            if (!(obj instanceof FlowRegistryKey)) {
                 return false;
             }
-            FlowHash that = (FlowHash) obj;
+            FlowRegistryKey that = (FlowRegistryKey) obj;
             if (this.flowHash == that.getFlowHash()
                     && this.tableId == that.getTableId()
                     && this.priority == that.getPriority()