Define ID representation for Intent, IFlow and MatchAction

- Defines BatchOperationTargetId abstract class.
- The above class is the base class of IntentId, FlowId, and MatchActionId.
 -- Intent objects use IntentId class for its ID.
 -- IFlow objects use FlowId class for its ID.
 -- MatchAction objects use MatchActionId class for its ID.
- BatchOperation classes requires the BatchOperationTargetId as the target object's ID.
- This work is a part of ONOS-1758.

Change-Id: I71bb4e6acd3836d1ced3beb6fb331bca451abdc3
diff --git a/src/main/java/net/onrc/onos/api/batchoperation/AddOperation.java b/src/main/java/net/onrc/onos/api/batchoperation/AddOperation.java
index 556a0cb..7e8b97a 100644
--- a/src/main/java/net/onrc/onos/api/batchoperation/AddOperation.java
+++ b/src/main/java/net/onrc/onos/api/batchoperation/AddOperation.java
@@ -4,7 +4,7 @@
  * An add-operation entry of a batch operation.
  */
 public class AddOperation implements BatchOperationEntry {
-    protected IBatchOperationTarget target;
+    private final IBatchOperationTarget target;
 
     /**
      * Creates a add-operation with specified target.
diff --git a/src/main/java/net/onrc/onos/api/batchoperation/BatchOperation.java b/src/main/java/net/onrc/onos/api/batchoperation/BatchOperation.java
index b51c8eb..cea0b7e 100644
--- a/src/main/java/net/onrc/onos/api/batchoperation/BatchOperation.java
+++ b/src/main/java/net/onrc/onos/api/batchoperation/BatchOperation.java
@@ -52,7 +52,7 @@
      * @param id ID of the target to be removed.
      * @return true if succeeded, false otherwise.
      */
-    public boolean addRemoveOperation(String id) {
+    public boolean addRemoveOperation(BatchOperationTargetId id) {
         return ops.add(new RemoveOperation(id));
     }
 
@@ -63,7 +63,7 @@
      * @param newTarget The new target to be added.
      * @return true if succeeded, false otherwise.
      */
-    public boolean addUpdateOperation(String oldTargetId, T newTarget) {
+    public boolean addUpdateOperation(BatchOperationTargetId oldTargetId, T newTarget) {
         return ops.add(new UpdateOperation(oldTargetId, newTarget));
     }
 }
diff --git a/src/main/java/net/onrc/onos/api/batchoperation/BatchOperationTargetId.java b/src/main/java/net/onrc/onos/api/batchoperation/BatchOperationTargetId.java
new file mode 100644
index 0000000..dfa3da9
--- /dev/null
+++ b/src/main/java/net/onrc/onos/api/batchoperation/BatchOperationTargetId.java
@@ -0,0 +1,23 @@
+package net.onrc.onos.api.batchoperation;
+
+/**
+ * An abstract class to represent ID of the batch operation target.
+ * <p>
+ * The sub-classes must implement equals() and hashCode() methods so that
+ * instance of this interface could be used as Map keys.
+ */
+public abstract class BatchOperationTargetId {
+    /**
+     * Returns a string representation of the target object's ID.
+     *
+     * @return a string representation of the target object's ID.
+     */
+    @Override
+    public abstract String toString();
+
+    @Override
+    public abstract int hashCode();
+
+    @Override
+    public abstract boolean equals(Object obj);
+}
diff --git a/src/main/java/net/onrc/onos/api/batchoperation/IBatchOperationTarget.java b/src/main/java/net/onrc/onos/api/batchoperation/IBatchOperationTarget.java
index d08528f..45e05ea 100644
--- a/src/main/java/net/onrc/onos/api/batchoperation/IBatchOperationTarget.java
+++ b/src/main/java/net/onrc/onos/api/batchoperation/IBatchOperationTarget.java
@@ -9,5 +9,5 @@
      *
      * @return ID of the object.
      */
-    public String getId();
+    public BatchOperationTargetId getId();
 }
diff --git a/src/main/java/net/onrc/onos/api/batchoperation/RemoveOperation.java b/src/main/java/net/onrc/onos/api/batchoperation/RemoveOperation.java
index c86e427..bafe926 100644
--- a/src/main/java/net/onrc/onos/api/batchoperation/RemoveOperation.java
+++ b/src/main/java/net/onrc/onos/api/batchoperation/RemoveOperation.java
@@ -4,16 +4,16 @@
  * A remove-operation entry of a batch operation.
  */
 public class RemoveOperation implements BatchOperationEntry {
-    protected String targetId;
+    private final BatchOperationTargetId targetId;
 
     /**
      * Creates a remove-operation with specified target.
      *
-     * @param targetId The target object ID to be assigned to this
+     * @param id The target object ID to be assigned to this
      *        remove-operation.
      */
-    public RemoveOperation(String targetId) {
-        this.targetId = targetId;
+    public RemoveOperation(BatchOperationTargetId id) {
+        this.targetId = id;
     }
 
     @Override
@@ -26,7 +26,7 @@
      *
      * @return The target ID to be removed.
      */
-    public String getTargetId() {
+    public BatchOperationTargetId getTargetId() {
         return targetId;
     }
 }
diff --git a/src/main/java/net/onrc/onos/api/batchoperation/UpdateOperation.java b/src/main/java/net/onrc/onos/api/batchoperation/UpdateOperation.java
index 45772ce..aaf649a 100644
--- a/src/main/java/net/onrc/onos/api/batchoperation/UpdateOperation.java
+++ b/src/main/java/net/onrc/onos/api/batchoperation/UpdateOperation.java
@@ -4,8 +4,8 @@
  * An update-operation entry of a batch operation.
  */
 public class UpdateOperation implements BatchOperationEntry {
-    public String oldTargetId;
-    public IBatchOperationTarget newTarget;
+    private final BatchOperationTargetId oldTargetId;
+    private final IBatchOperationTarget newTarget;
 
     /**
      * Creates a update-operation with specified targets.
@@ -13,7 +13,7 @@
      * @param oldTargetId The ID to be overwritten.
      * @param newTarget The new target to be added.
      */
-    public UpdateOperation(String oldTargetId, IBatchOperationTarget newTarget) {
+    public UpdateOperation(BatchOperationTargetId oldTargetId, IBatchOperationTarget newTarget) {
         this.oldTargetId = oldTargetId;
         this.newTarget = newTarget;
     }
@@ -28,7 +28,7 @@
      *
      * @return The old target ID to be overwritten
      */
-    public String getOldTargetId() {
+    public BatchOperationTargetId getOldTargetId() {
         return oldTargetId;
     }
 
diff --git a/src/main/java/net/onrc/onos/api/flowmanager/FlowId.java b/src/main/java/net/onrc/onos/api/flowmanager/FlowId.java
new file mode 100644
index 0000000..b3c42d6
--- /dev/null
+++ b/src/main/java/net/onrc/onos/api/flowmanager/FlowId.java
@@ -0,0 +1,38 @@
+package net.onrc.onos.api.flowmanager;
+
+import net.onrc.onos.api.batchoperation.BatchOperationTargetId;
+
+/**
+ * Represents ID for IFlow objects.
+ */
+public class FlowId extends BatchOperationTargetId {
+    private final String value;
+
+    /**
+     * Creates new instance with string ID.
+     *
+     * @param id String representation of the ID.
+     */
+    public FlowId(String id) {
+        value = id;
+    }
+
+    @Override
+    public String toString() {
+        return value;
+    }
+
+    @Override
+    public int hashCode() {
+        return value.hashCode();
+    }
+
+    @Override
+    public boolean equals(Object obj) {
+        if (obj instanceof FlowId) {
+            FlowId other = (FlowId) obj;
+            return (this.value.equals(other.value));
+        }
+        return false;
+    }
+}
diff --git a/src/main/java/net/onrc/onos/api/flowmanager/IFlow.java b/src/main/java/net/onrc/onos/api/flowmanager/IFlow.java
index 66f116a..25b9aea 100644
--- a/src/main/java/net/onrc/onos/api/flowmanager/IFlow.java
+++ b/src/main/java/net/onrc/onos/api/flowmanager/IFlow.java
@@ -18,7 +18,7 @@
      * @return ID for this object.
      */
     @Override
-    public String getId();
+    public FlowId getId();
 
     /**
      * Gets traffic filter for this flow object.
diff --git a/src/main/java/net/onrc/onos/api/flowmanager/IFlowManagerService.java b/src/main/java/net/onrc/onos/api/flowmanager/IFlowManagerService.java
index edd3c85..ca4e5f7 100644
--- a/src/main/java/net/onrc/onos/api/flowmanager/IFlowManagerService.java
+++ b/src/main/java/net/onrc/onos/api/flowmanager/IFlowManagerService.java
@@ -31,7 +31,7 @@
      * @param id ID for IFlow object to be removed.
      * @return true if succeeded, false otherwise.
      */
-    boolean removeFlow(String id);
+    boolean removeFlow(FlowId id);
 
     /**
      * Updates IFlow object, calculates match-action plan and executes it.
@@ -50,7 +50,7 @@
      * @param id ID of IFlow object.
      * @return IFlow object if found, null otherwise.
      */
-    IFlow getFlow(String id);
+    IFlow getFlow(FlowId id);
 
     /**
      * Gets All IFlow objects.
diff --git a/src/main/java/net/onrc/onos/api/flowmanager/PathFlow.java b/src/main/java/net/onrc/onos/api/flowmanager/PathFlow.java
index baf163f..50db020 100644
--- a/src/main/java/net/onrc/onos/api/flowmanager/PathFlow.java
+++ b/src/main/java/net/onrc/onos/api/flowmanager/PathFlow.java
@@ -14,7 +14,7 @@
  * have only the PacketPathFlow and OpticalPathFlow classes?
  */
 public class PathFlow implements IFlow {
-    protected final String id;
+    protected final FlowId id;
     protected IMatch match;
     protected PortNumber ingressPort;
     protected Path path;
@@ -32,7 +32,7 @@
      */
     public PathFlow(String id,
             IMatch match, PortNumber ingressPort, Path path, List<IAction> edgeActions) {
-        this.id = id;
+        this.id = new FlowId(id);
         this.match = match;
         this.ingressPort = ingressPort;
         this.path = path;
@@ -40,7 +40,7 @@
     }
 
     @Override
-    public String getId() {
+    public FlowId getId() {
         return id;
     }
 
diff --git a/src/main/java/net/onrc/onos/api/flowmanager/SingleDstTreeFlow.java b/src/main/java/net/onrc/onos/api/flowmanager/SingleDstTreeFlow.java
index 82a9b50..473b7e8 100644
--- a/src/main/java/net/onrc/onos/api/flowmanager/SingleDstTreeFlow.java
+++ b/src/main/java/net/onrc/onos/api/flowmanager/SingleDstTreeFlow.java
@@ -18,7 +18,7 @@
  * address modifications or other the label-switching-like schemes.
  */
 public class SingleDstTreeFlow implements IFlow {
-    protected String id;
+    protected final FlowId id;
     protected PacketMatch match;
     protected Set<SwitchPort> ingressPorts;
     protected Tree tree;
@@ -35,7 +35,7 @@
      */
     public SingleDstTreeFlow(String id, PacketMatch match,
             Collection<SwitchPort> ingressPorts, Tree tree, OutputAction outputAction) {
-        this.id = id;
+        this.id = new FlowId(id);
         this.match = match;
         this.ingressPorts = new HashSet<SwitchPort>(ingressPorts);
         this.tree = tree;
@@ -46,7 +46,7 @@
     }
 
     @Override
-    public String getId() {
+    public FlowId getId() {
         return id;
     }
 
diff --git a/src/main/java/net/onrc/onos/api/flowmanager/SingleSrcTreeFlow.java b/src/main/java/net/onrc/onos/api/flowmanager/SingleSrcTreeFlow.java
index cecb605..e401bdc 100644
--- a/src/main/java/net/onrc/onos/api/flowmanager/SingleSrcTreeFlow.java
+++ b/src/main/java/net/onrc/onos/api/flowmanager/SingleSrcTreeFlow.java
@@ -14,7 +14,7 @@
  * layer.
  */
 public class SingleSrcTreeFlow implements IFlow {
-    protected String id;
+    protected final FlowId id;
     protected PacketMatch match;
     protected SwitchPort ingressPort;
     protected Tree tree;
@@ -32,7 +32,7 @@
      */
     public SingleSrcTreeFlow(String id, PacketMatch match,
             SwitchPort ingressPort, Tree tree, Set<Pair<Dpid, OutputAction>> outputActions) {
-        this.id = id;
+        this.id = new FlowId(id);
         this.match = match;
         this.ingressPort = ingressPort;
         this.tree = tree;
@@ -43,7 +43,7 @@
     }
 
     @Override
-    public String getId() {
+    public FlowId getId() {
         return id;
     }
 
diff --git a/src/main/java/net/onrc/onos/api/intent/IIntentRuntimeService.java b/src/main/java/net/onrc/onos/api/intent/IIntentRuntimeService.java
index 5e9ed52..2b8774b 100644
--- a/src/main/java/net/onrc/onos/api/intent/IIntentRuntimeService.java
+++ b/src/main/java/net/onrc/onos/api/intent/IIntentRuntimeService.java
@@ -32,7 +32,7 @@
      * @param id ID of the intent to be removed.
      * @return true if succeeded, false otherwise.
      */
-    boolean removeIntent(String id);
+    boolean removeIntent(IntentId id);
 
     /**
      * Overwrites existing intent by new specified intent.
@@ -41,7 +41,7 @@
      * @param intent The new intent to be added.
      * @return true if succeeded, false otherwise.
      */
-    boolean updateIntent(String id, Intent intent);
+    boolean updateIntent(IntentId id, Intent intent);
 
     /**
      * Gets specific intent.
@@ -49,7 +49,7 @@
      * @param id ID of the intent should be retrieved
      * @return Intent if it exists, null otherwise.
      */
-    Intent getIntent(String id);
+    Intent getIntent(IntentId id);
 
     /**
      * Gets all intents.
diff --git a/src/main/java/net/onrc/onos/api/intent/Intent.java b/src/main/java/net/onrc/onos/api/intent/Intent.java
index 93d6459..048bdee 100644
--- a/src/main/java/net/onrc/onos/api/intent/Intent.java
+++ b/src/main/java/net/onrc/onos/api/intent/Intent.java
@@ -20,7 +20,7 @@
  * data-plane to satisfy those constraints.
  */
 public abstract class Intent implements IBatchOperationTarget {
-    protected String id;
+    protected final IntentId id;
 
     /**
      * Constructor.
@@ -28,7 +28,7 @@
      * @param id ID for this Intent object.
      */
     public Intent(String id) {
-        this.id = id;
+        this.id = new IntentId(id);
     }
 
     /**
@@ -37,7 +37,7 @@
      * @return ID for this Intent object.
      */
     @Override
-    public String getId() {
+    public IntentId getId() {
         return id;
     }
 
diff --git a/src/main/java/net/onrc/onos/api/intent/IntentId.java b/src/main/java/net/onrc/onos/api/intent/IntentId.java
new file mode 100644
index 0000000..d488183
--- /dev/null
+++ b/src/main/java/net/onrc/onos/api/intent/IntentId.java
@@ -0,0 +1,30 @@
+package net.onrc.onos.api.intent;
+
+import net.onrc.onos.api.batchoperation.BatchOperationTargetId;
+
+public class IntentId extends BatchOperationTargetId {
+    private final String value;
+
+    public IntentId(String id) {
+        value = id;
+    }
+
+    @Override
+    public String toString() {
+        return value;
+    }
+
+    @Override
+    public int hashCode() {
+        return value.hashCode();
+    }
+
+    @Override
+    public boolean equals(Object obj) {
+        if (obj instanceof IntentId) {
+            IntentId other = (IntentId) obj;
+            return (this.value.equals(other.value));
+        }
+        return false;
+    }
+}