blob: 928a502d2a2a947ef2fe3d7f14a0a8dc2a6d6218 [file] [log] [blame]
Toshio Koidea03915e2014-07-01 18:39:52 -07001package net.onrc.onos.api.batchoperation;
2
Pavlin Radoslavovdd08e8c2014-08-14 11:02:57 -07003import com.google.common.base.Objects;
4
Toshio Koidea03915e2014-07-01 18:39:52 -07005/**
Toshio Koide4ea84192014-07-31 12:10:12 -07006 * A super class for batch operation entry classes.
Toshio Koidea03915e2014-07-01 18:39:52 -07007 * <p>
Toshio Koide4ea84192014-07-31 12:10:12 -07008 * This is the interface to classes which are maintained by BatchOperation as
9 * its entries.
Toshio Koidea03915e2014-07-01 18:39:52 -070010 */
Toshio Koidefad1cd52014-08-07 17:10:07 -070011public class BatchOperationEntry<T extends Enum<?>, U extends BatchOperationTarget> {
Toshio Koide4ea84192014-07-31 12:10:12 -070012 private final T operator;
13 private final U target;
14
Toshio Koidea03915e2014-07-01 18:39:52 -070015 /**
Pavlin Radoslavov63559e92014-08-13 14:18:56 -070016 * Default constructor for serializer.
17 */
18 @Deprecated
19 protected BatchOperationEntry() {
20 this.operator = null;
21 this.target = null;
22 }
23
24 /**
Toshio Koide4ea84192014-07-31 12:10:12 -070025 * Constructs new instance for the entry of the BatchOperation.
Toshio Koidea03915e2014-07-01 18:39:52 -070026 *
Toshio Koide4ea84192014-07-31 12:10:12 -070027 * @param operator the operator of this operation
28 * @param target the target object of this operation
Toshio Koidea03915e2014-07-01 18:39:52 -070029 */
Toshio Koide4ea84192014-07-31 12:10:12 -070030 public BatchOperationEntry(T operator, U target) {
31 this.operator = operator;
32 this.target = target;
33 }
34
35 /**
36 * Gets the target object of this operation.
37 *
38 * @return the target object of this operation
39 */
40 public U getTarget() {
41 return target;
42 }
43
44 /**
45 * Gets the operator of this operation.
46 *
47 * @return the operator of this operation
48 */
49 public T getOperator() {
50 return operator;
51 }
Pavlin Radoslavovdd08e8c2014-08-14 11:02:57 -070052
53 @Override
54 public boolean equals(Object o) {
55 if (this == o) {
56 return true;
57 }
58 if (o == null || getClass() != o.getClass()) {
59 return false;
60 }
61
62 BatchOperationEntry<?, ?> other = (BatchOperationEntry<?, ?>) o;
63 return (this.operator == other.operator) &&
64 Objects.equal(this.target, other.target);
65 }
66
67 @Override
68 public int hashCode() {
69 return Objects.hashCode(operator, target);
70 }
71
72 @Override
73 public String toString() {
74 return Objects.toStringHelper(this)
75 .add("operator", operator)
76 .add("target", target)
77 .toString();
78 }
Toshio Koidea03915e2014-07-01 18:39:52 -070079}