package net.onrc.onos.api.batchoperation;

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.
 */
public class BatchOperation<T extends IBatchOperationTarget> {
    private List<BatchOperationEntry> ops;

    /**
     * Constructor.
     */
    public BatchOperation() {
        ops = new LinkedList<BatchOperationEntry>();
    }

    /**
     * Removes all operations maintained in this object.
     */
    public void clear() {
        ops.clear();
    }

    /**
     * Returns an iterator over the operations in this object.
     *
     * @return an iterator over the operations in this object.
     */
    public Iterator<BatchOperationEntry> iterator() {
        return ops.iterator();
    }

    /**
     * Adds an add-operation.
     *
     * @param target IBatchOperationTarget object to be added.
     * @return true if succeeded, false otherwise.
     */
    public boolean addAddOperation(T target) {
        return ops.add(new AddOperation(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(id));
    }

    /**
     * Adds an update-operation.
     * <p>
     * The existing entry having the same ID with the new target is overwritten.
     *
     * @param target The new target to be used for the update.
     * @return true if succeeded, false otherwise.
     */
    public boolean addUpdateOperation(T target) {
        return ops.add(new UpdateOperation(target));
    }
}

@@ -36,16 +36,46 @@
 ation;%0A%0A
+import java.util.Collections;%0A
 import j
@@ -93,16 +93,16 @@
 erator;%0A
-
 import j
@@ -636,32 +636,225 @@
 clear();%0A    %7D%0A%0A
+    /**%0A     * Returns the number of operations in this object.%0A     *%0A     * @return the number of operations in this object.%0A     */%0A    public int size() %7B%0A        return ops.size();%0A    %7D%0A%0A
     /**%0A     * R
@@ -1036,24 +1036,24 @@
 terator() %7B%0A
-
         retu
@@ -1070,32 +1070,259 @@
 rator();%0A    %7D%0A%0A
+    /**%0A     * Returns the operations in this object.%0A     *%0A     * @return the operations in this object.%0A     */%0A    public List%3CBatchOperationEntry%3E getOperations() %7B%0A        return Collections.unmodifiableList(ops);%0A    %7D%0A%0A
     /**%0A     * A

Add size() and getOperations() method to BatchOperation class.