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;
- }
-}