Thomas Vachuska | 83e090e | 2014-10-22 14:25:35 -0700 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2014-present Open Networking Foundation |
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 | public U target() { |
Brian O'Connor | b876bf1 | 2014-10-02 14:59:37 -0700 | [diff] [blame] | 52 | return target; |
| 53 | } |
| 54 | |
| 55 | /** |
| 56 | * Gets the operator of this operation. |
| 57 | * |
| 58 | * @return the operator of this operation |
| 59 | */ |
Sho SHIMIZU | aba9d00 | 2015-01-29 14:51:04 -0800 | [diff] [blame] | 60 | public T operator() { |
Brian O'Connor | b876bf1 | 2014-10-02 14:59:37 -0700 | [diff] [blame] | 61 | return operator; |
| 62 | } |
| 63 | |
| 64 | @Override |
| 65 | public boolean equals(Object o) { |
| 66 | if (this == o) { |
| 67 | return true; |
| 68 | } |
| 69 | if (o == null || getClass() != o.getClass()) { |
| 70 | return false; |
| 71 | } |
| 72 | |
| 73 | BatchOperationEntry<?, ?> other = (BatchOperationEntry<?, ?>) o; |
| 74 | return (this.operator == other.operator) && |
| 75 | Objects.equals(this.target, other.target); |
| 76 | } |
| 77 | |
| 78 | @Override |
| 79 | public int hashCode() { |
| 80 | return Objects.hash(operator, target); |
| 81 | } |
| 82 | |
| 83 | @Override |
| 84 | public String toString() { |
| 85 | return MoreObjects.toStringHelper(this) |
| 86 | .add("operator", operator) |
| 87 | .add("target", target) |
| 88 | .toString(); |
| 89 | } |
| 90 | } |