blob: 6232a86c2759255548b8ff93c540da2b17c5193a [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.LinkedList;
5import java.util.List;
6
7/**
8 * A list of BatchOperationEntry.
9 *
Toshio Koide4ea84192014-07-31 12:10:12 -070010 * @param <T> the enum of operators <br>
11 * This enum must be defined in each sub-classes.
12 *
Toshio Koidea03915e2014-07-01 18:39:52 -070013 */
Toshio Koide4ea84192014-07-31 12:10:12 -070014public abstract class BatchOperation<T extends BatchOperationEntry<?, ?>> {
15 private List<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 Koidecff5d982014-07-31 11:41:56 -070041 * Returns the operations in this object.
42 *
Toshio Koidea8e8c542014-07-31 12:10:12 -070043 * @return the operations in this object
Toshio Koidecff5d982014-07-31 11:41:56 -070044 */
Toshio Koide4ea84192014-07-31 12:10:12 -070045 public List<T> getOperations() {
Toshio Koidecff5d982014-07-31 11:41:56 -070046 return Collections.unmodifiableList(ops);
47 }
48
49 /**
Toshio Koide4ea84192014-07-31 12:10:12 -070050 * Adds an operation.
Toshio Koidea03915e2014-07-01 18:39:52 -070051 *
Toshio Koide4ea84192014-07-31 12:10:12 -070052 * @param entry the operation to be added
53 * @return this object if succeeded, null otherwise
Toshio Koidea03915e2014-07-01 18:39:52 -070054 */
Toshio Koide4ea84192014-07-31 12:10:12 -070055 public BatchOperation<T> addOperation(T entry) {
56 return ops.add(entry) ? this : null;
Toshio Koidea03915e2014-07-01 18:39:52 -070057 }
Pavlin Radoslavovdd08e8c2014-08-14 11:02:57 -070058
59 @Override
60 public boolean equals(Object o) {
61 if (this == o) {
62 return true;
63 }
64
65 if (o == null) {
66 return false;
67 }
68
69 if (getClass() != o.getClass()) {
70 return false;
71 }
72 BatchOperation<?> other = (BatchOperation<?>) o;
73
74 return this.ops.equals(other.ops);
75 }
76
77 @Override
78 public int hashCode() {
79 return ops.hashCode();
80 }
81
82 @Override
83 public String toString() {
84 return ops.toString();
85 }
Toshio Koidea03915e2014-07-01 18:39:52 -070086}