blob: 9fc20c0637087397a87f2ea246b91d300cd63fa2 [file] [log] [blame]
Toshio Koidea03915e2014-07-01 18:39:52 -07001package net.onrc.onos.api.batchoperation;
2
Toshio Koidecff5d982014-07-31 11:41:56 -07003import java.util.Collections;
Toshio Koidea03915e2014-07-01 18:39:52 -07004import java.util.Iterator;
5import java.util.LinkedList;
6import java.util.List;
7
8/**
9 * A list of BatchOperationEntry.
10 *
11 * @param <T> IBatchOperationTarget. This should be Intent, IFlow, or
12 * MatchAction.
13 */
14public class BatchOperation<T extends IBatchOperationTarget> {
15 private List<BatchOperationEntry> ops;
16
17 /**
18 * Constructor.
19 */
20 public BatchOperation() {
21 ops = new LinkedList<BatchOperationEntry>();
22 }
23
24 /**
25 * Removes all operations maintained in this object.
26 */
27 public void clear() {
28 ops.clear();
29 }
30
31 /**
Toshio Koidecff5d982014-07-31 11:41:56 -070032 * Returns the number of operations in this object.
33 *
34 * @return the number of operations in this object.
35 */
36 public int size() {
37 return ops.size();
38 }
39
40 /**
Toshio Koidea03915e2014-07-01 18:39:52 -070041 * Returns an iterator over the operations in this object.
42 *
43 * @return an iterator over the operations in this object.
44 */
45 public Iterator<BatchOperationEntry> iterator() {
46 return ops.iterator();
47 }
48
49 /**
Toshio Koidecff5d982014-07-31 11:41:56 -070050 * Returns the operations in this object.
51 *
52 * @return the operations in this object.
53 */
54 public List<BatchOperationEntry> getOperations() {
55 return Collections.unmodifiableList(ops);
56 }
57
58 /**
Toshio Koidea03915e2014-07-01 18:39:52 -070059 * Adds an add-operation.
60 *
Toshio Koide473b1f62014-07-31 11:38:15 -070061 * @param target IBatchOperationTarget object to be added.
Toshio Koidea03915e2014-07-01 18:39:52 -070062 * @return true if succeeded, false otherwise.
63 */
64 public boolean addAddOperation(T target) {
65 return ops.add(new AddOperation(target));
66 }
67
68 /**
69 * Adds a remove-operation.
70 *
71 * @param id ID of the target to be removed.
72 * @return true if succeeded, false otherwise.
73 */
Toshio Koide025a9152014-07-21 11:00:34 -070074 public boolean addRemoveOperation(BatchOperationTargetId id) {
Toshio Koidea03915e2014-07-01 18:39:52 -070075 return ops.add(new RemoveOperation(id));
76 }
77
78 /**
Toshio Koide473b1f62014-07-31 11:38:15 -070079 * Adds an update-operation.
80 * <p>
81 * The existing entry having the same ID with the new target is overwritten.
Toshio Koidea03915e2014-07-01 18:39:52 -070082 *
Toshio Koide473b1f62014-07-31 11:38:15 -070083 * @param target The new target to be used for the update.
Toshio Koidea03915e2014-07-01 18:39:52 -070084 * @return true if succeeded, false otherwise.
85 */
Toshio Koide473b1f62014-07-31 11:38:15 -070086 public boolean addUpdateOperation(T target) {
87 return ops.add(new UpdateOperation(target));
Toshio Koidea03915e2014-07-01 18:39:52 -070088 }
89}