blob: b51c8eb440f0feebce9f617acd992cde01808544 [file] [log] [blame]
Toshio Koidea03915e2014-07-01 18:39:52 -07001package net.onrc.onos.api.batchoperation;
2
3import java.util.Iterator;
4import java.util.LinkedList;
5import java.util.List;
6
7/**
8 * A list of BatchOperationEntry.
9 *
10 * @param <T> IBatchOperationTarget. This should be Intent, IFlow, or
11 * MatchAction.
12 */
13public class BatchOperation<T extends IBatchOperationTarget> {
14 private List<BatchOperationEntry> ops;
15
16 /**
17 * Constructor.
18 */
19 public BatchOperation() {
20 ops = new LinkedList<BatchOperationEntry>();
21 }
22
23 /**
24 * Removes all operations maintained in this object.
25 */
26 public void clear() {
27 ops.clear();
28 }
29
30 /**
31 * Returns an iterator over the operations in this object.
32 *
33 * @return an iterator over the operations in this object.
34 */
35 public Iterator<BatchOperationEntry> iterator() {
36 return ops.iterator();
37 }
38
39 /**
40 * Adds an add-operation.
41 *
42 * @param intent Intent to be added.
43 * @return true if succeeded, false otherwise.
44 */
45 public boolean addAddOperation(T target) {
46 return ops.add(new AddOperation(target));
47 }
48
49 /**
50 * Adds a remove-operation.
51 *
52 * @param id ID of the target to be removed.
53 * @return true if succeeded, false otherwise.
54 */
55 public boolean addRemoveOperation(String id) {
56 return ops.add(new RemoveOperation(id));
57 }
58
59 /**
60 * Adds a update-operation.
61 *
62 * @param oldtargetId ID of the existing target to be overwritten.
63 * @param newTarget The new target to be added.
64 * @return true if succeeded, false otherwise.
65 */
66 public boolean addUpdateOperation(String oldTargetId, T newTarget) {
67 return ops.add(new UpdateOperation(oldTargetId, newTarget));
68 }
69}