blob: cb8ddd8a001b9377914f2125ae0ec8035eafbc39 [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> {
Toshio Koidea8e8c542014-07-31 12:10:12 -070015 private List<BatchOperationEntry<T>> ops;
Toshio Koidea03915e2014-07-01 18:39:52 -070016
17 /**
18 * Constructor.
19 */
20 public BatchOperation() {
Toshio Koidea8e8c542014-07-31 12:10:12 -070021 ops = new LinkedList<>();
Toshio Koidea03915e2014-07-01 18:39:52 -070022 }
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 *
Toshio Koidea8e8c542014-07-31 12:10:12 -070034 * @return the number of operations in this object
Toshio Koidecff5d982014-07-31 11:41:56 -070035 */
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 *
Toshio Koidea8e8c542014-07-31 12:10:12 -070043 * @return an iterator over the operations in this object
Toshio Koidea03915e2014-07-01 18:39:52 -070044 */
Toshio Koidea8e8c542014-07-31 12:10:12 -070045 public Iterator<BatchOperationEntry<T>> iterator() {
Toshio Koidea03915e2014-07-01 18:39:52 -070046 return ops.iterator();
47 }
48
49 /**
Toshio Koidecff5d982014-07-31 11:41:56 -070050 * Returns the operations in this object.
51 *
Toshio Koidea8e8c542014-07-31 12:10:12 -070052 * @return the operations in this object
Toshio Koidecff5d982014-07-31 11:41:56 -070053 */
Toshio Koidea8e8c542014-07-31 12:10:12 -070054 public List<BatchOperationEntry<T>> getOperations() {
Toshio Koidecff5d982014-07-31 11:41:56 -070055 return Collections.unmodifiableList(ops);
56 }
57
58 /**
Toshio Koidea03915e2014-07-01 18:39:52 -070059 * Adds an add-operation.
60 *
Toshio Koidea8e8c542014-07-31 12:10:12 -070061 * @param target IBatchOperationTarget object to be added
62 * @return true if succeeded, false otherwise
Toshio Koidea03915e2014-07-01 18:39:52 -070063 */
64 public boolean addAddOperation(T target) {
Toshio Koidea8e8c542014-07-31 12:10:12 -070065 return ops.add(new AddOperation<T>(target));
Toshio Koidea03915e2014-07-01 18:39:52 -070066 }
67
68 /**
69 * Adds a remove-operation.
70 *
Toshio Koidea8e8c542014-07-31 12:10:12 -070071 * @param id ID of the target to be removed
72 * @return true if succeeded, false otherwise
Toshio Koidea03915e2014-07-01 18:39:52 -070073 */
Toshio Koide025a9152014-07-21 11:00:34 -070074 public boolean addRemoveOperation(BatchOperationTargetId id) {
Toshio Koidea8e8c542014-07-31 12:10:12 -070075 return ops.add(new RemoveOperation<T>(id));
Toshio Koidea03915e2014-07-01 18:39:52 -070076 }
77}