Change return type of groupId() in FlowRule not to misusing underlying type

Change-Id: Ide90973380f79046650bc372b9ecee00cb290f6a
diff --git a/core/api/src/main/java/org/onlab/onos/net/flow/DefaultFlowRule.java b/core/api/src/main/java/org/onlab/onos/net/flow/DefaultFlowRule.java
index deef14e..4bbcca1 100644
--- a/core/api/src/main/java/org/onlab/onos/net/flow/DefaultFlowRule.java
+++ b/core/api/src/main/java/org/onlab/onos/net/flow/DefaultFlowRule.java
@@ -21,6 +21,8 @@
 import java.util.Objects;
 
 import org.onlab.onos.core.ApplicationId;
+import org.onlab.onos.core.DefaultGroupId;
+import org.onlab.onos.core.GroupId;
 import org.onlab.onos.net.DeviceId;
 import org.slf4j.Logger;
 
@@ -40,7 +42,7 @@
 
     private final int timeout;
     private final boolean permanent;
-    private final short groupId;
+    private final GroupId groupId;
 
 
     public DefaultFlowRule(DeviceId deviceId, TrafficSelector selector,
@@ -55,19 +57,26 @@
         this.created = System.currentTimeMillis();
 
         this.appId = (short) (flowId >>> 48);
-        this.groupId = (short) ((flowId >>> 32) & 0xFFFF);
+        this.groupId = new DefaultGroupId((short) ((flowId >>> 32) & 0xFFFF));
         this.id = FlowId.valueOf(flowId);
     }
 
     public DefaultFlowRule(DeviceId deviceId, TrafficSelector selector,
                            TrafficTreatment treatment, int priority, ApplicationId appId,
                            int timeout, boolean permanent) {
-        this(deviceId, selector, treatment, priority, appId, (short) 0, timeout, permanent);
+        this(deviceId, selector, treatment, priority, appId, new DefaultGroupId(0), timeout, permanent);
+    }
+
+    @Deprecated
+    public DefaultFlowRule(DeviceId deviceId, TrafficSelector selector,
+                           TrafficTreatment treatment, int priority, ApplicationId appId,
+                           short groupId, int timeout, boolean permanent) {
+        this(deviceId, selector, treatment, priority, appId, new DefaultGroupId(groupId), timeout, permanent);
     }
 
     public DefaultFlowRule(DeviceId deviceId, TrafficSelector selector,
                            TrafficTreatment treatment, int priority, ApplicationId appId,
-                           short groupId, int timeout, boolean permanent) {
+                           GroupId groupId, int timeout, boolean permanent) {
 
         if (priority < FlowRule.MIN_PRIORITY) {
             throw new IllegalArgumentException("Priority cannot be less than " + MIN_PRIORITY);
@@ -87,8 +96,8 @@
          * id consists of the following.
          * | appId (16 bits) | groupId (16 bits) | flowId (32 bits) |
          */
-        this.id = FlowId.valueOf((((long) this.appId) << 48) | (((long) this.groupId) << 32)
-                                         | (this.hash() & 0xffffffffL));
+        this.id = FlowId.valueOf((((long) this.appId) << 48) | (((long) this.groupId.id()) << 32)
+                | (this.hash() & 0xffffffffL));
     }
 
     public DefaultFlowRule(FlowRule rule) {
@@ -117,7 +126,7 @@
     }
 
     @Override
-    public short groupId() {
+    public GroupId groupId() {
         return groupId;
     }
 
diff --git a/core/api/src/main/java/org/onlab/onos/net/flow/FlowRule.java b/core/api/src/main/java/org/onlab/onos/net/flow/FlowRule.java
index fd605fc..2124768 100644
--- a/core/api/src/main/java/org/onlab/onos/net/flow/FlowRule.java
+++ b/core/api/src/main/java/org/onlab/onos/net/flow/FlowRule.java
@@ -15,6 +15,7 @@
  */
 package org.onlab.onos.net.flow;
 
+import org.onlab.onos.core.GroupId;
 import org.onlab.onos.net.DeviceId;
 
 /**
@@ -46,7 +47,7 @@
      *
      * @return an groupId
      */
-    short groupId();
+    GroupId groupId();
 
     /**
      * Returns the flow rule priority given in natural order; higher numbers
diff --git a/core/api/src/test/java/org/onlab/onos/net/intent/IntentTestsMocks.java b/core/api/src/test/java/org/onlab/onos/net/intent/IntentTestsMocks.java
index 0e22a79..4e44c2d 100644
--- a/core/api/src/test/java/org/onlab/onos/net/intent/IntentTestsMocks.java
+++ b/core/api/src/test/java/org/onlab/onos/net/intent/IntentTestsMocks.java
@@ -29,6 +29,8 @@
 import java.util.Objects;
 import java.util.Set;
 
+import org.onlab.onos.core.DefaultGroupId;
+import org.onlab.onos.core.GroupId;
 import org.onlab.onos.net.DeviceId;
 import org.onlab.onos.net.ElementId;
 import org.onlab.onos.net.Link;
@@ -309,8 +311,8 @@
         }
 
         @Override
-        public short groupId() {
-            return 0;
+        public GroupId groupId() {
+            return new DefaultGroupId(0);
         }
 
         @Override
diff --git a/core/net/src/main/java/org/onlab/onos/net/statistic/impl/StatisticManager.java b/core/net/src/main/java/org/onlab/onos/net/statistic/impl/StatisticManager.java
index fd4b741..f1ac9b16 100644
--- a/core/net/src/main/java/org/onlab/onos/net/statistic/impl/StatisticManager.java
+++ b/core/net/src/main/java/org/onlab/onos/net/statistic/impl/StatisticManager.java
@@ -357,7 +357,7 @@
                 }
                 // FIXME: The left hand type and right hand type don't match
                 // FlowEntry.groupId() still returns a short value, not int.
-                return flowEntry.groupId() == groupId.get().id();
+                return flowEntry.groupId().equals(groupId.get());
             }
         };
     }