Merge "SONAR TD - Group actions redundancy"
[openflowplugin.git] / openflowplugin-impl / src / main / java / org / opendaylight / openflowplugin / impl / registry / flow / FlowRegistryKeyFactory.java
index 1a9948a2bd1137036ce9af73f678550595784c57..889e30a2c21f606852e154ce7ca14394973ee74b 100644 (file)
@@ -13,6 +13,7 @@ import com.google.common.base.Preconditions;
 import java.math.BigInteger;
 import org.opendaylight.openflowplugin.api.OFConstants;
 import org.opendaylight.openflowplugin.api.openflow.registry.flow.FlowRegistryKey;
+import org.opendaylight.openflowplugin.impl.util.MatchComparatorFactory;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.Flow;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.Match;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.MatchBuilder;
@@ -22,8 +23,8 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.M
  */
 public class FlowRegistryKeyFactory {
 
-
-    public FlowRegistryKeyFactory() {
+    private FlowRegistryKeyFactory() {
+        // Hide implicit constructor
     }
 
     public static FlowRegistryKey create(final Flow flow) {
@@ -31,17 +32,16 @@ public class FlowRegistryKeyFactory {
     }
 
     private static final class FlowRegistryKeyDto implements FlowRegistryKey {
-
         private final short tableId;
         private final int priority;
         private final BigInteger cookie;
         private final Match match;
 
-        public FlowRegistryKeyDto(final Flow flow) {
+        private FlowRegistryKeyDto(final Flow flow) {
             //TODO: mandatory flow input values (or default values) should be specified via yang model
             tableId = Preconditions.checkNotNull(flow.getTableId(), "flow tableId must not be null");
             priority = MoreObjects.firstNonNull(flow.getPriority(), OFConstants.DEFAULT_FLOW_PRIORITY);
-            match = flow.getMatch()==null? new MatchBuilder().build(): flow.getMatch();
+            match = MoreObjects.firstNonNull(flow.getMatch(), OFConstants.EMPTY_MATCH);
             cookie = MoreObjects.firstNonNull(flow.getCookie(), OFConstants.DEFAULT_FLOW_COOKIE).getValue();
         }
 
@@ -59,13 +59,15 @@ public class FlowRegistryKeyFactory {
 
             return getPriority() == that.getPriority() &&
                     getTableId() == that.getTableId() &&
-                    getMatch().equals(that.getMatch());
+                    getCookie().equals(that.getCookie()) &&
+                    MatchComparatorFactory.createMatch().areObjectsEqual(getMatch(), that.getMatch());
         }
 
         @Override
         public int hashCode() {
             int result = tableId;
             result = 31 * result + priority;
+            result = 31 * result + cookie.hashCode();
             result = 31 * result + match.hashCode();
             return result;
         }