Toshio Koide | a03915e | 2014-07-01 18:39:52 -0700 | [diff] [blame] | 1 | package net.onrc.onos.api.batchoperation; |
| 2 | |
| 3 | import java.util.Iterator; |
| 4 | import java.util.LinkedList; |
| 5 | import java.util.List; |
| 6 | |
| 7 | /** |
| 8 | * A list of BatchOperationEntry. |
| 9 | * |
| 10 | * @param <T> IBatchOperationTarget. This should be Intent, IFlow, or |
| 11 | * MatchAction. |
| 12 | */ |
| 13 | public 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 | * |
Yuta HIGUCHI | 21ce889 | 2014-07-25 18:08:17 -0700 | [diff] [blame] | 42 | * @param target IBatchOperationTarget to be added. |
Toshio Koide | a03915e | 2014-07-01 18:39:52 -0700 | [diff] [blame] | 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 | */ |
Toshio Koide | 025a915 | 2014-07-21 11:00:34 -0700 | [diff] [blame] | 55 | public boolean addRemoveOperation(BatchOperationTargetId id) { |
Toshio Koide | a03915e | 2014-07-01 18:39:52 -0700 | [diff] [blame] | 56 | return ops.add(new RemoveOperation(id)); |
| 57 | } |
| 58 | |
| 59 | /** |
| 60 | * Adds a update-operation. |
| 61 | * |
Yuta HIGUCHI | 21ce889 | 2014-07-25 18:08:17 -0700 | [diff] [blame] | 62 | * @param oldTargetId ID of the existing target to be overwritten. |
Toshio Koide | a03915e | 2014-07-01 18:39:52 -0700 | [diff] [blame] | 63 | * @param newTarget The new target to be added. |
| 64 | * @return true if succeeded, false otherwise. |
| 65 | */ |
Toshio Koide | 025a915 | 2014-07-21 11:00:34 -0700 | [diff] [blame] | 66 | public boolean addUpdateOperation(BatchOperationTargetId oldTargetId, T newTarget) { |
Toshio Koide | a03915e | 2014-07-01 18:39:52 -0700 | [diff] [blame] | 67 | return ops.add(new UpdateOperation(oldTargetId, newTarget)); |
| 68 | } |
| 69 | } |