blob: 7b577697b2f99c2aac7b93a4d0496a31125c9ed9 [file] [log] [blame]
Brian O'Connorb876bf12014-10-02 14:59:37 -07001package org.onlab.onos.net.intent;
Brian O'Connorf3d06162014-10-02 15:54:12 -07002//TODO is this the right package?
Brian O'Connorb876bf12014-10-02 14:59:37 -07003
alshabib902d41b2014-10-07 16:52:05 -07004import static com.google.common.base.Preconditions.checkNotNull;
5
6import java.util.Collection;
Brian O'Connorb876bf12014-10-02 14:59:37 -07007import java.util.Collections;
8import java.util.LinkedList;
9import java.util.List;
10
11/**
12 * A list of BatchOperationEntry.
13 *
14 * @param <T> the enum of operators <br>
toma1d16b62014-10-02 23:45:11 -070015 * This enum must be defined in each sub-classes.
Brian O'Connorb876bf12014-10-02 14:59:37 -070016 */
Thomas Vachuska1fb982f2014-10-22 14:09:17 -070017@Deprecated
Brian O'Connorb876bf12014-10-02 14:59:37 -070018public abstract class BatchOperation<T extends BatchOperationEntry<?, ?>> {
toma1d16b62014-10-02 23:45:11 -070019
alshabib902d41b2014-10-07 16:52:05 -070020 private final List<T> ops;
Brian O'Connorb876bf12014-10-02 14:59:37 -070021
22 /**
23 * Creates new {@link BatchOperation} object.
24 */
25 public BatchOperation() {
26 ops = new LinkedList<>();
27 }
28
29 /**
30 * Creates {@link BatchOperation} object from a list of batch operation
31 * entries.
32 *
33 * @param batchOperations the list of batch operation entries.
34 */
alshabib902d41b2014-10-07 16:52:05 -070035 public BatchOperation(Collection<T> batchOperations) {
Brian O'Connorb876bf12014-10-02 14:59:37 -070036 ops = new LinkedList<>(checkNotNull(batchOperations));
37 }
38
39 /**
40 * Removes all operations maintained in this object.
41 */
42 public void clear() {
43 ops.clear();
44 }
45
46 /**
47 * Returns the number of operations in this object.
48 *
49 * @return the number of operations in this object
50 */
51 public int size() {
52 return ops.size();
53 }
54
55 /**
56 * Returns the operations in this object.
57 *
58 * @return the operations in this object
59 */
60 public List<T> getOperations() {
61 return Collections.unmodifiableList(ops);
62 }
63
64 /**
65 * Adds an operation.
alshabib902d41b2014-10-07 16:52:05 -070066 * FIXME: Brian promises that the Intent Framework
67 * will not modify the batch operation after it has submitted it.
68 * Ali would prefer immutablity, but trusts brian for better or
69 * for worse.
Brian O'Connorb876bf12014-10-02 14:59:37 -070070 *
71 * @param entry the operation to be added
72 * @return this object if succeeded, null otherwise
73 */
74 public BatchOperation<T> addOperation(T entry) {
75 return ops.add(entry) ? this : null;
76 }
77
78 @Override
79 public boolean equals(Object o) {
80 if (this == o) {
81 return true;
82 }
83
84 if (o == null) {
85 return false;
86 }
87
88 if (getClass() != o.getClass()) {
89 return false;
90 }
91 BatchOperation<?> other = (BatchOperation<?>) o;
92
93 return this.ops.equals(other.ops);
94 }
95
96 @Override
97 public int hashCode() {
98 return ops.hashCode();
99 }
100
101 @Override
102 public String toString() {
103 return ops.toString();
104 }
105}