Thomas Vachuska | 83e090e | 2014-10-22 14:25:35 -0700 | [diff] [blame] | 1 | /* |
Thomas Vachuska | 4f1a60c | 2014-10-28 13:39:07 -0700 | [diff] [blame] | 2 | * Copyright 2014 Open Networking Laboratory |
Thomas Vachuska | 83e090e | 2014-10-22 14:25:35 -0700 | [diff] [blame] | 3 | * |
Thomas Vachuska | 4f1a60c | 2014-10-28 13:39:07 -0700 | [diff] [blame] | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
Thomas Vachuska | 83e090e | 2014-10-22 14:25:35 -0700 | [diff] [blame] | 7 | * |
Thomas Vachuska | 4f1a60c | 2014-10-28 13:39:07 -0700 | [diff] [blame] | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
Thomas Vachuska | 83e090e | 2014-10-22 14:25:35 -0700 | [diff] [blame] | 15 | */ |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 16 | package org.onosproject.net.flow; |
Brian O'Connor | b876bf1 | 2014-10-02 14:59:37 -0700 | [diff] [blame] | 17 | |
| 18 | import java.util.Objects; |
| 19 | |
| 20 | import com.google.common.base.MoreObjects; |
| 21 | |
Sho SHIMIZU | 60e2467 | 2015-01-20 16:25:42 -0800 | [diff] [blame] | 22 | import static com.google.common.base.Preconditions.checkNotNull; |
| 23 | |
Brian O'Connor | b876bf1 | 2014-10-02 14:59:37 -0700 | [diff] [blame] | 24 | /** |
| 25 | * A super class for batch operation entry classes. |
| 26 | * <p> |
| 27 | * This is the interface to classes which are maintained by BatchOperation as |
| 28 | * its entries. |
| 29 | */ |
Sho SHIMIZU | 5e5d4aa | 2015-01-26 16:12:11 -0800 | [diff] [blame] | 30 | public class BatchOperationEntry<T extends Enum<?>, U> { |
Sho SHIMIZU | 60e2467 | 2015-01-20 16:25:42 -0800 | [diff] [blame] | 31 | |
Brian O'Connor | b876bf1 | 2014-10-02 14:59:37 -0700 | [diff] [blame] | 32 | private final T operator; |
| 33 | private final U target; |
| 34 | |
Brian O'Connor | b876bf1 | 2014-10-02 14:59:37 -0700 | [diff] [blame] | 35 | /** |
| 36 | * Constructs new instance for the entry of the BatchOperation. |
| 37 | * |
| 38 | * @param operator the operator of this operation |
| 39 | * @param target the target object of this operation |
| 40 | */ |
| 41 | public BatchOperationEntry(T operator, U target) { |
Sho SHIMIZU | 60e2467 | 2015-01-20 16:25:42 -0800 | [diff] [blame] | 42 | this.operator = checkNotNull(operator); |
| 43 | this.target = checkNotNull(target); |
Brian O'Connor | b876bf1 | 2014-10-02 14:59:37 -0700 | [diff] [blame] | 44 | } |
| 45 | |
| 46 | /** |
| 47 | * Gets the target object of this operation. |
| 48 | * |
| 49 | * @return the target object of this operation |
| 50 | */ |
Sho SHIMIZU | aba9d00 | 2015-01-29 14:51:04 -0800 | [diff] [blame] | 51 | @Deprecated |
Brian O'Connor | b876bf1 | 2014-10-02 14:59:37 -0700 | [diff] [blame] | 52 | public U getTarget() { |
Sho SHIMIZU | aba9d00 | 2015-01-29 14:51:04 -0800 | [diff] [blame] | 53 | return target(); |
| 54 | } |
| 55 | |
| 56 | /** |
| 57 | * Gets the target object of this operation. |
| 58 | * |
| 59 | * @return the target object of this operation |
| 60 | */ |
| 61 | public U target() { |
Brian O'Connor | b876bf1 | 2014-10-02 14:59:37 -0700 | [diff] [blame] | 62 | return target; |
| 63 | } |
| 64 | |
| 65 | /** |
| 66 | * Gets the operator of this operation. |
| 67 | * |
| 68 | * @return the operator of this operation |
| 69 | */ |
Sho SHIMIZU | aba9d00 | 2015-01-29 14:51:04 -0800 | [diff] [blame] | 70 | @Deprecated |
Brian O'Connor | b876bf1 | 2014-10-02 14:59:37 -0700 | [diff] [blame] | 71 | public T getOperator() { |
Sho SHIMIZU | aba9d00 | 2015-01-29 14:51:04 -0800 | [diff] [blame] | 72 | return operator(); |
| 73 | } |
| 74 | |
| 75 | /** |
| 76 | * Gets the operator of this operation. |
| 77 | * |
| 78 | * @return the operator of this operation |
| 79 | */ |
| 80 | public T operator() { |
Brian O'Connor | b876bf1 | 2014-10-02 14:59:37 -0700 | [diff] [blame] | 81 | return operator; |
| 82 | } |
| 83 | |
| 84 | @Override |
| 85 | public boolean equals(Object o) { |
| 86 | if (this == o) { |
| 87 | return true; |
| 88 | } |
| 89 | if (o == null || getClass() != o.getClass()) { |
| 90 | return false; |
| 91 | } |
| 92 | |
| 93 | BatchOperationEntry<?, ?> other = (BatchOperationEntry<?, ?>) o; |
| 94 | return (this.operator == other.operator) && |
| 95 | Objects.equals(this.target, other.target); |
| 96 | } |
| 97 | |
| 98 | @Override |
| 99 | public int hashCode() { |
| 100 | return Objects.hash(operator, target); |
| 101 | } |
| 102 | |
| 103 | @Override |
| 104 | public String toString() { |
| 105 | return MoreObjects.toStringHelper(this) |
| 106 | .add("operator", operator) |
| 107 | .add("target", target) |
| 108 | .toString(); |
| 109 | } |
| 110 | } |