Update BatchOperation class to be more generic and extensible.

- addAddOperation() and addRemoveOperation() methods are removed
  from BatchOperation class, and now the class has just addOperation() method.

- Removed AddOperation and RemoveOperation classes,
  and defined IntentBatchOperation, FlowBatchOperation and MatchActionPhase classes
  as sub-classes of BatchOperation class, for Intent, IFlow and MatchAction objects
  respectively.

- These classes include definitions of add/remove operators and helper methods
  specific to Intent, IFlow and MatchAction objects.

- Removed BatchOperationTargetId class.

- Updated unit tests.

- This task is a part of ONOS-1692.

Change-Id: Iba2f737af1fef6a6555e0e0166836865ed070fa3
diff --git a/src/main/java/net/onrc/onos/api/batchoperation/AddOperation.java b/src/main/java/net/onrc/onos/api/batchoperation/AddOperation.java
deleted file mode 100644
index f8fb8d0..0000000
--- a/src/main/java/net/onrc/onos/api/batchoperation/AddOperation.java
+++ /dev/null
@@ -1,32 +0,0 @@
-package net.onrc.onos.api.batchoperation;
-
-/**
- * An add-operation entry of a batch operation.
- */
-public class AddOperation<T extends IBatchOperationTarget>
-        implements BatchOperationEntry<T> {
-    private final T target;
-
-    /**
-     * Creates a add-operation with specified target.
-     *
-     * @param target the target object to be assigned to this add-operation
-     */
-    public AddOperation(T target) {
-        this.target = target;
-    }
-
-    @Override
-    public BatchOperator getOperator() {
-        return BatchOperator.ADD;
-    }
-
-    /**
-     * Gets the target object which assigned to this add-operation.
-     *
-     * @return the target object which assigned to this add-operation
-     */
-    public T getTarget() {
-        return 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 cb8ddd8..7ef8c45 100644
--- a/src/main/java/net/onrc/onos/api/batchoperation/BatchOperation.java
+++ b/src/main/java/net/onrc/onos/api/batchoperation/BatchOperation.java
@@ -1,18 +1,18 @@
 package net.onrc.onos.api.batchoperation;
 
 import java.util.Collections;
-import java.util.Iterator;
 import java.util.LinkedList;
 import java.util.List;
 
 /**
  * A list of BatchOperationEntry.
  *
- * @param <T> IBatchOperationTarget. This should be Intent, IFlow, or
- *        MatchAction.
+ * @param <T> the enum of operators <br>
+ *        This enum must be defined in each sub-classes.
+ *
  */
-public class BatchOperation<T extends IBatchOperationTarget> {
-    private List<BatchOperationEntry<T>> ops;
+public abstract class BatchOperation<T extends BatchOperationEntry<?, ?>> {
+    private List<T> ops;
 
     /**
      * Constructor.
@@ -38,40 +38,21 @@
     }
 
     /**
-     * Returns an iterator over the operations in this object.
-     *
-     * @return an iterator over the operations in this object
-     */
-    public Iterator<BatchOperationEntry<T>> iterator() {
-        return ops.iterator();
-    }
-
-    /**
      * Returns the operations in this object.
      *
      * @return the operations in this object
      */
-    public List<BatchOperationEntry<T>> getOperations() {
+    public List<T> getOperations() {
         return Collections.unmodifiableList(ops);
     }
 
     /**
-     * Adds an add-operation.
+     * Adds an operation.
      *
-     * @param target IBatchOperationTarget object to be added
-     * @return true if succeeded, false otherwise
+     * @param entry the operation to be added
+     * @return this object if succeeded, null otherwise
      */
-    public boolean addAddOperation(T target) {
-        return ops.add(new AddOperation<T>(target));
-    }
-
-    /**
-     * Adds a remove-operation.
-     *
-     * @param id ID of the target to be removed
-     * @return true if succeeded, false otherwise
-     */
-    public boolean addRemoveOperation(BatchOperationTargetId id) {
-        return ops.add(new RemoveOperation<T>(id));
+    public BatchOperation<T> addOperation(T entry) {
+        return ops.add(entry) ? this : null;
     }
 }
diff --git a/src/main/java/net/onrc/onos/api/batchoperation/BatchOperationEntry.java b/src/main/java/net/onrc/onos/api/batchoperation/BatchOperationEntry.java
index 7274d5f..23b3e39 100644
--- a/src/main/java/net/onrc/onos/api/batchoperation/BatchOperationEntry.java
+++ b/src/main/java/net/onrc/onos/api/batchoperation/BatchOperationEntry.java
@@ -1,16 +1,41 @@
 package net.onrc.onos.api.batchoperation;
 
 /**
- * An interface for batch operation entry classes.
+ * A super class for batch operation entry classes.
  * <p>
- * This is the interface to AddOperation, UpdateOperation and RemoveOperation
- * classes which are the entry maintained by BatchOperation.
+ * This is the interface to classes which are maintained by BatchOperation as
+ * its entries.
  */
-public interface BatchOperationEntry<T extends IBatchOperationTarget> {
+public class BatchOperationEntry<T extends Enum<?>, U extends IBatchOperationTarget> {
+    private final T operator;
+    private final U target;
+
     /**
-     * Gets the BatchOperator of this operation.
+     * Constructs new instance for the entry of the BatchOperation.
      *
-     * @return the BatchOperator of this operation
+     * @param operator the operator of this operation
+     * @param target the target object of this operation
      */
-    public BatchOperator getOperator();
+    public BatchOperationEntry(T operator, U target) {
+        this.operator = operator;
+        this.target = target;
+    }
+
+    /**
+     * Gets the target object of this operation.
+     *
+     * @return the target object of this operation
+     */
+    public U getTarget() {
+        return target;
+    }
+
+    /**
+     * Gets the operator of this operation.
+     *
+     * @return the operator of this operation
+     */
+    public T getOperator() {
+        return operator;
+    }
 }
diff --git a/src/main/java/net/onrc/onos/api/batchoperation/BatchOperationTargetId.java b/src/main/java/net/onrc/onos/api/batchoperation/BatchOperationTargetId.java
deleted file mode 100644
index d2d0ad1..0000000
--- a/src/main/java/net/onrc/onos/api/batchoperation/BatchOperationTargetId.java
+++ /dev/null
@@ -1,23 +0,0 @@
-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/BatchOperator.java b/src/main/java/net/onrc/onos/api/batchoperation/BatchOperator.java
deleted file mode 100644
index 0b9a2ce..0000000
--- a/src/main/java/net/onrc/onos/api/batchoperation/BatchOperator.java
+++ /dev/null
@@ -1,21 +0,0 @@
-package net.onrc.onos.api.batchoperation;
-
-/**
- * Operators used by BatchOperation classes.
- */
-public enum BatchOperator {
-    /**
-     * Adds new target object.
-     */
-    ADD,
-
-    /**
-     * Removes existing object.
-     */
-    REMOVE,
-
-    /**
-     * Unknown operator type.
-     */
-    UNKNOWN,
-}
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 3b2d3d9..d9adaed 100644
--- a/src/main/java/net/onrc/onos/api/batchoperation/IBatchOperationTarget.java
+++ b/src/main/java/net/onrc/onos/api/batchoperation/IBatchOperationTarget.java
@@ -4,10 +4,5 @@
  * An interface of the class which is assigned to BatchOperation.
  */
 public interface IBatchOperationTarget {
-    /**
-     * Gets ID of the object.
-     *
-     * @return ID of the object
-     */
-    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
deleted file mode 100644
index 52eec95..0000000
--- a/src/main/java/net/onrc/onos/api/batchoperation/RemoveOperation.java
+++ /dev/null
@@ -1,32 +0,0 @@
-package net.onrc.onos.api.batchoperation;
-
-/**
- * A remove-operation entry of a batch operation.
- */
-public class RemoveOperation<T extends IBatchOperationTarget>
-        implements BatchOperationEntry<T> {
-    private final BatchOperationTargetId targetId;
-
-    /**
-     * Creates a remove-operation with specified target.
-     *
-     * @param id the target object ID to be assigned to this remove-operation
-     */
-    public RemoveOperation(BatchOperationTargetId id) {
-        this.targetId = id;
-    }
-
-    @Override
-    public BatchOperator getOperator() {
-        return BatchOperator.REMOVE;
-    }
-
-    /**
-     * Gets the target ID to be removed.
-     *
-     * @return the target ID to be removed
-     */
-    public BatchOperationTargetId getTargetId() {
-        return targetId;
-    }
-}
diff --git a/src/main/java/net/onrc/onos/api/flowmanager/FlowBatchOperation.java b/src/main/java/net/onrc/onos/api/flowmanager/FlowBatchOperation.java
new file mode 100644
index 0000000..42eb81d
--- /dev/null
+++ b/src/main/java/net/onrc/onos/api/flowmanager/FlowBatchOperation.java
@@ -0,0 +1,49 @@
+package net.onrc.onos.api.flowmanager;
+
+import net.onrc.onos.api.batchoperation.BatchOperation;
+import net.onrc.onos.api.batchoperation.BatchOperationEntry;
+
+/**
+ * A list of flow operations.
+ */
+public class FlowBatchOperation extends
+        BatchOperation<BatchOperationEntry<FlowBatchOperation.Operator, ?>> {
+    /**
+     * The flow operations' operators.
+     */
+    public enum Operator {
+        /**
+         * Adds new flow.
+         */
+        ADD,
+
+        /**
+         * Removes the existing flow.
+         */
+        REMOVE,
+    }
+
+    /**
+     * Adds an add-flow operation.
+     *
+     * @param flow the flow to be added
+     * @return the FlowBatchOperation object if succeeded, null otherwise
+     */
+    public FlowBatchOperation addAddFlowOperation(IFlow flow) {
+        return (null == super.addOperation(
+                new BatchOperationEntry<Operator, IFlow>(Operator.ADD, flow)))
+                ? null : this;
+    }
+
+    /**
+     * Adds a remove-flow operation.
+     *
+     * @param flowId the ID of flow to be removed
+     * @return the FlowBatchOperation object if succeeded, null otherwise
+     */
+    public FlowBatchOperation addRemoveFlowOperation(FlowId flowId) {
+        return (null == super.addOperation(
+                new BatchOperationEntry<Operator, FlowId>(Operator.REMOVE, flowId)))
+                ? null : this;
+    }
+}
diff --git a/src/main/java/net/onrc/onos/api/flowmanager/FlowId.java b/src/main/java/net/onrc/onos/api/flowmanager/FlowId.java
index b3c42d6..a0ebd2d 100644
--- a/src/main/java/net/onrc/onos/api/flowmanager/FlowId.java
+++ b/src/main/java/net/onrc/onos/api/flowmanager/FlowId.java
@@ -1,11 +1,11 @@
 package net.onrc.onos.api.flowmanager;
 
-import net.onrc.onos.api.batchoperation.BatchOperationTargetId;
+import net.onrc.onos.api.batchoperation.IBatchOperationTarget;
 
 /**
  * Represents ID for IFlow objects.
  */
-public class FlowId extends BatchOperationTargetId {
+public class FlowId implements IBatchOperationTarget {
     private final String value;
 
     /**
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 25b9aea..fbd6b2b 100644
--- a/src/main/java/net/onrc/onos/api/flowmanager/IFlow.java
+++ b/src/main/java/net/onrc/onos/api/flowmanager/IFlow.java
@@ -17,7 +17,6 @@
      *
      * @return ID for this object.
      */
-    @Override
     public FlowId getId();
 
     /**
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 fcfaacb..efd7b98 100644
--- a/src/main/java/net/onrc/onos/api/flowmanager/IFlowManagerService.java
+++ b/src/main/java/net/onrc/onos/api/flowmanager/IFlowManagerService.java
@@ -3,8 +3,6 @@
 import java.util.Collection;
 import java.util.EventListener;
 
-import net.onrc.onos.api.batchoperation.BatchOperation;
-
 /**
  * An interface class for flow manager. The role of the flow manager is to
  * manage a set of Match-Action entries based on the specified IFlow objects.
@@ -51,10 +49,10 @@
     /**
      * Executes batch operation of IFlow object.
      *
-     * @param ops FlowOperations to be executed
+     * @param ops flow operations to be executed
      * @return true if succeeded, false otherwise
      */
-    boolean executeBatch(BatchOperation<IFlow> ops);
+    boolean executeBatch(FlowBatchOperation ops);
 
     /**
      * Sets a conflict detection policy.
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 fc9d788..890bb7f 100644
--- a/src/main/java/net/onrc/onos/api/intent/IIntentRuntimeService.java
+++ b/src/main/java/net/onrc/onos/api/intent/IIntentRuntimeService.java
@@ -3,7 +3,6 @@
 import java.util.Collection;
 import java.util.EventListener;
 
-import net.onrc.onos.api.batchoperation.BatchOperation;
 import net.onrc.onos.api.flowmanager.ConflictDetectionPolicy;
 import net.onrc.onos.api.flowmanager.IFlow;
 
@@ -63,7 +62,7 @@
      * @param ops BatchOperations to be executed.
      * @return true if succeeded, false otherwise.
      */
-    boolean executeBatch(BatchOperation<Intent> ops);
+    boolean executeBatch(IntentBatchOperation ops);
 
     /**
      * Adds an IntentResolver associated with a given intent type.
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 418346a..f8ec5c2 100644
--- a/src/main/java/net/onrc/onos/api/intent/Intent.java
+++ b/src/main/java/net/onrc/onos/api/intent/Intent.java
@@ -42,7 +42,6 @@
      *
      * @return ID for this Intent object.
      */
-    @Override
     public IntentId getId() {
         return id;
     }
diff --git a/src/main/java/net/onrc/onos/api/intent/IntentBatchOperation.java b/src/main/java/net/onrc/onos/api/intent/IntentBatchOperation.java
new file mode 100644
index 0000000..b5ca1aa
--- /dev/null
+++ b/src/main/java/net/onrc/onos/api/intent/IntentBatchOperation.java
@@ -0,0 +1,42 @@
+package net.onrc.onos.api.intent;
+
+import net.onrc.onos.api.batchoperation.BatchOperation;
+import net.onrc.onos.api.batchoperation.BatchOperationEntry;
+
+/**
+ * A list of intent operations.
+ */
+public class IntentBatchOperation extends
+        BatchOperation<BatchOperationEntry<IntentBatchOperation.Operator, ?>> {
+    /**
+     * The intent operators.
+     */
+    public enum Operator {
+        ADD,
+        REMOVE,
+    }
+
+    /**
+     * Adds an add-intent operation.
+     *
+     * @param intent the intent to be added
+     * @return the IntentBatchOperation object if succeeded, null otherwise
+     */
+    public IntentBatchOperation addAddIntentOperation(Intent intent) {
+        return (null == super.addOperation(
+                new BatchOperationEntry<Operator, Intent>(Operator.ADD, intent)))
+                ? null : this;
+    }
+
+    /**
+     * Adds a remove-intent operation.
+     *
+     * @param id the ID of intent to be removed
+     * @return the IntentBatchOperation object if succeeded, null otherwise
+     */
+    public IntentBatchOperation addRemoveIntentOperation(IntentId id) {
+        return (null == super.addOperation(
+                new BatchOperationEntry<Operator, IntentId>(Operator.REMOVE, id)))
+                ? null : this;
+    }
+}
diff --git a/src/main/java/net/onrc/onos/api/intent/IntentId.java b/src/main/java/net/onrc/onos/api/intent/IntentId.java
index a9a9c78..327f2cb 100644
--- a/src/main/java/net/onrc/onos/api/intent/IntentId.java
+++ b/src/main/java/net/onrc/onos/api/intent/IntentId.java
@@ -1,6 +1,6 @@
 package net.onrc.onos.api.intent;
 
-import net.onrc.onos.api.batchoperation.BatchOperationTargetId;
+import net.onrc.onos.api.batchoperation.IBatchOperationTarget;
 
 /**
  * The class representing intent's ID.
@@ -9,7 +9,7 @@
  * This class is immutable.
  * </p>
  */
-public final class IntentId extends BatchOperationTargetId {
+public final class IntentId implements IBatchOperationTarget {
     private final long id;
 
     /**