blob: 7e0d5b5c3a36a94c41e2a1608993bed99fd94489 [file] [log] [blame]
Thomas Vachuska83e090e2014-10-22 14:25:35 -07001/*
Thomas Vachuska4f1a60c2014-10-28 13:39:07 -07002 * Copyright 2014 Open Networking Laboratory
Thomas Vachuska83e090e2014-10-22 14:25:35 -07003 *
Thomas Vachuska4f1a60c2014-10-28 13:39:07 -07004 * 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 Vachuska83e090e2014-10-22 14:25:35 -07007 *
Thomas Vachuska4f1a60c2014-10-28 13:39:07 -07008 * 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 Vachuska83e090e2014-10-22 14:25:35 -070015 */
Brian O'Connorabafb502014-12-02 22:26:20 -080016package org.onosproject.net.flow;
Brian O'Connorb876bf12014-10-02 14:59:37 -070017
18import java.util.Objects;
19
20import com.google.common.base.MoreObjects;
21
Sho SHIMIZU60e24672015-01-20 16:25:42 -080022import static com.google.common.base.Preconditions.checkNotNull;
23
Brian O'Connorb876bf12014-10-02 14:59:37 -070024/**
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 SHIMIZU5e5d4aa2015-01-26 16:12:11 -080030public class BatchOperationEntry<T extends Enum<?>, U> {
Sho SHIMIZU60e24672015-01-20 16:25:42 -080031
Brian O'Connorb876bf12014-10-02 14:59:37 -070032 private final T operator;
33 private final U target;
34
Brian O'Connorb876bf12014-10-02 14:59:37 -070035 /**
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 SHIMIZU60e24672015-01-20 16:25:42 -080042 this.operator = checkNotNull(operator);
43 this.target = checkNotNull(target);
Brian O'Connorb876bf12014-10-02 14:59:37 -070044 }
45
46 /**
47 * Gets the target object of this operation.
48 *
49 * @return the target object of this operation
50 */
Sho SHIMIZUaba9d002015-01-29 14:51:04 -080051 @Deprecated
Brian O'Connorb876bf12014-10-02 14:59:37 -070052 public U getTarget() {
Sho SHIMIZUaba9d002015-01-29 14:51:04 -080053 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'Connorb876bf12014-10-02 14:59:37 -070062 return target;
63 }
64
65 /**
66 * Gets the operator of this operation.
67 *
68 * @return the operator of this operation
69 */
Sho SHIMIZUaba9d002015-01-29 14:51:04 -080070 @Deprecated
Brian O'Connorb876bf12014-10-02 14:59:37 -070071 public T getOperator() {
Sho SHIMIZUaba9d002015-01-29 14:51:04 -080072 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'Connorb876bf12014-10-02 14:59:37 -070081 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}