Toshio Koide | a03915e | 2014-07-01 18:39:52 -0700 | [diff] [blame] | 1 | package net.onrc.onos.api.batchoperation; |
| 2 | |
Pavlin Radoslavov | dd08e8c | 2014-08-14 11:02:57 -0700 | [diff] [blame] | 3 | import com.google.common.base.Objects; |
| 4 | |
Toshio Koide | a03915e | 2014-07-01 18:39:52 -0700 | [diff] [blame] | 5 | /** |
Toshio Koide | 4ea8419 | 2014-07-31 12:10:12 -0700 | [diff] [blame] | 6 | * A super class for batch operation entry classes. |
Toshio Koide | a03915e | 2014-07-01 18:39:52 -0700 | [diff] [blame] | 7 | * <p> |
Toshio Koide | 4ea8419 | 2014-07-31 12:10:12 -0700 | [diff] [blame] | 8 | * This is the interface to classes which are maintained by BatchOperation as |
| 9 | * its entries. |
Toshio Koide | a03915e | 2014-07-01 18:39:52 -0700 | [diff] [blame] | 10 | */ |
Toshio Koide | fad1cd5 | 2014-08-07 17:10:07 -0700 | [diff] [blame] | 11 | public class BatchOperationEntry<T extends Enum<?>, U extends BatchOperationTarget> { |
Toshio Koide | 4ea8419 | 2014-07-31 12:10:12 -0700 | [diff] [blame] | 12 | private final T operator; |
| 13 | private final U target; |
| 14 | |
Toshio Koide | a03915e | 2014-07-01 18:39:52 -0700 | [diff] [blame] | 15 | /** |
Pavlin Radoslavov | 63559e9 | 2014-08-13 14:18:56 -0700 | [diff] [blame] | 16 | * Default constructor for serializer. |
| 17 | */ |
| 18 | @Deprecated |
| 19 | protected BatchOperationEntry() { |
| 20 | this.operator = null; |
| 21 | this.target = null; |
| 22 | } |
| 23 | |
| 24 | /** |
Toshio Koide | 4ea8419 | 2014-07-31 12:10:12 -0700 | [diff] [blame] | 25 | * Constructs new instance for the entry of the BatchOperation. |
Toshio Koide | a03915e | 2014-07-01 18:39:52 -0700 | [diff] [blame] | 26 | * |
Toshio Koide | 4ea8419 | 2014-07-31 12:10:12 -0700 | [diff] [blame] | 27 | * @param operator the operator of this operation |
| 28 | * @param target the target object of this operation |
Toshio Koide | a03915e | 2014-07-01 18:39:52 -0700 | [diff] [blame] | 29 | */ |
Toshio Koide | 4ea8419 | 2014-07-31 12:10:12 -0700 | [diff] [blame] | 30 | 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 Radoslavov | dd08e8c | 2014-08-14 11:02:57 -0700 | [diff] [blame] | 52 | |
| 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 Koide | a03915e | 2014-07-01 18:39:52 -0700 | [diff] [blame] | 79 | } |