blob: cb174eb9a82cddec7baf031fab792356bec84fea [file] [log] [blame]
Thomas Vachuska83e090e2014-10-22 14:25:35 -07001/*
Brian O'Connor5ab426f2016-04-09 01:19:45 -07002 * Copyright 2014-present 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 public U target() {
Brian O'Connorb876bf12014-10-02 14:59:37 -070052 return target;
53 }
54
55 /**
56 * Gets the operator of this operation.
57 *
58 * @return the operator of this operation
59 */
Sho SHIMIZUaba9d002015-01-29 14:51:04 -080060 public T operator() {
Brian O'Connorb876bf12014-10-02 14:59:37 -070061 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}