Toshio Koide | a03915e | 2014-07-01 18:39:52 -0700 | [diff] [blame] | 1 | package net.onrc.onos.api.batchoperation; |
| 2 | |
Toshio Koide | cff5d98 | 2014-07-31 11:41:56 -0700 | [diff] [blame] | 3 | import java.util.Collections; |
Toshio Koide | a03915e | 2014-07-01 18:39:52 -0700 | [diff] [blame] | 4 | import java.util.Iterator; |
| 5 | import java.util.LinkedList; |
| 6 | import java.util.List; |
| 7 | |
| 8 | /** |
| 9 | * A list of BatchOperationEntry. |
| 10 | * |
| 11 | * @param <T> IBatchOperationTarget. This should be Intent, IFlow, or |
| 12 | * MatchAction. |
| 13 | */ |
| 14 | public class BatchOperation<T extends IBatchOperationTarget> { |
Toshio Koide | a8e8c54 | 2014-07-31 12:10:12 -0700 | [diff] [blame^] | 15 | private List<BatchOperationEntry<T>> ops; |
Toshio Koide | a03915e | 2014-07-01 18:39:52 -0700 | [diff] [blame] | 16 | |
| 17 | /** |
| 18 | * Constructor. |
| 19 | */ |
| 20 | public BatchOperation() { |
Toshio Koide | a8e8c54 | 2014-07-31 12:10:12 -0700 | [diff] [blame^] | 21 | ops = new LinkedList<>(); |
Toshio Koide | a03915e | 2014-07-01 18:39:52 -0700 | [diff] [blame] | 22 | } |
| 23 | |
| 24 | /** |
| 25 | * Removes all operations maintained in this object. |
| 26 | */ |
| 27 | public void clear() { |
| 28 | ops.clear(); |
| 29 | } |
| 30 | |
| 31 | /** |
Toshio Koide | cff5d98 | 2014-07-31 11:41:56 -0700 | [diff] [blame] | 32 | * Returns the number of operations in this object. |
| 33 | * |
Toshio Koide | a8e8c54 | 2014-07-31 12:10:12 -0700 | [diff] [blame^] | 34 | * @return the number of operations in this object |
Toshio Koide | cff5d98 | 2014-07-31 11:41:56 -0700 | [diff] [blame] | 35 | */ |
| 36 | public int size() { |
| 37 | return ops.size(); |
| 38 | } |
| 39 | |
| 40 | /** |
Toshio Koide | a03915e | 2014-07-01 18:39:52 -0700 | [diff] [blame] | 41 | * Returns an iterator over the operations in this object. |
| 42 | * |
Toshio Koide | a8e8c54 | 2014-07-31 12:10:12 -0700 | [diff] [blame^] | 43 | * @return an iterator over the operations in this object |
Toshio Koide | a03915e | 2014-07-01 18:39:52 -0700 | [diff] [blame] | 44 | */ |
Toshio Koide | a8e8c54 | 2014-07-31 12:10:12 -0700 | [diff] [blame^] | 45 | public Iterator<BatchOperationEntry<T>> iterator() { |
Toshio Koide | a03915e | 2014-07-01 18:39:52 -0700 | [diff] [blame] | 46 | return ops.iterator(); |
| 47 | } |
| 48 | |
| 49 | /** |
Toshio Koide | cff5d98 | 2014-07-31 11:41:56 -0700 | [diff] [blame] | 50 | * Returns the operations in this object. |
| 51 | * |
Toshio Koide | a8e8c54 | 2014-07-31 12:10:12 -0700 | [diff] [blame^] | 52 | * @return the operations in this object |
Toshio Koide | cff5d98 | 2014-07-31 11:41:56 -0700 | [diff] [blame] | 53 | */ |
Toshio Koide | a8e8c54 | 2014-07-31 12:10:12 -0700 | [diff] [blame^] | 54 | public List<BatchOperationEntry<T>> getOperations() { |
Toshio Koide | cff5d98 | 2014-07-31 11:41:56 -0700 | [diff] [blame] | 55 | return Collections.unmodifiableList(ops); |
| 56 | } |
| 57 | |
| 58 | /** |
Toshio Koide | a03915e | 2014-07-01 18:39:52 -0700 | [diff] [blame] | 59 | * Adds an add-operation. |
| 60 | * |
Toshio Koide | a8e8c54 | 2014-07-31 12:10:12 -0700 | [diff] [blame^] | 61 | * @param target IBatchOperationTarget object to be added |
| 62 | * @return true if succeeded, false otherwise |
Toshio Koide | a03915e | 2014-07-01 18:39:52 -0700 | [diff] [blame] | 63 | */ |
| 64 | public boolean addAddOperation(T target) { |
Toshio Koide | a8e8c54 | 2014-07-31 12:10:12 -0700 | [diff] [blame^] | 65 | return ops.add(new AddOperation<T>(target)); |
Toshio Koide | a03915e | 2014-07-01 18:39:52 -0700 | [diff] [blame] | 66 | } |
| 67 | |
| 68 | /** |
| 69 | * Adds a remove-operation. |
| 70 | * |
Toshio Koide | a8e8c54 | 2014-07-31 12:10:12 -0700 | [diff] [blame^] | 71 | * @param id ID of the target to be removed |
| 72 | * @return true if succeeded, false otherwise |
Toshio Koide | a03915e | 2014-07-01 18:39:52 -0700 | [diff] [blame] | 73 | */ |
Toshio Koide | 025a915 | 2014-07-21 11:00:34 -0700 | [diff] [blame] | 74 | public boolean addRemoveOperation(BatchOperationTargetId id) { |
Toshio Koide | a8e8c54 | 2014-07-31 12:10:12 -0700 | [diff] [blame^] | 75 | return ops.add(new RemoveOperation<T>(id)); |
Toshio Koide | a03915e | 2014-07-01 18:39:52 -0700 | [diff] [blame] | 76 | } |
| 77 | } |