blob: 9b5549b5389ff19cbadda495288d2629f0f262e5 [file] [log] [blame]
Yi Tsengf4e13e32017-03-30 15:38:39 -07001/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2017-present Open Networking Foundation
Yi Tsengf4e13e32017-03-30 15:38:39 -07003 *
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
7 *
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.
15 */
16
17package org.onosproject.vpls.api;
18
19import com.google.common.base.MoreObjects;
20
21import java.util.Objects;
22
23import static java.util.Objects.*;
24
25/**
26 * Operation for VPLS.
27 */
28public class VplsOperation {
29
30 /**
31 * The operation type.
32 */
33 public enum Operation {
34 REMOVE,
35 ADD,
36 UPDATE
37 }
38
39 private VplsData vplsData;
40 private Operation op;
41
42 /**
43 * Defines a VPLS operation by binding a given VPLS and operation type.
44 *
45 * @param vplsData the VPLS
46 * @param op the operation
47 */
48 protected VplsOperation(VplsData vplsData, Operation op) {
49 requireNonNull(vplsData);
50 requireNonNull(op);
51 // Make a copy of the VPLS data to ensure other thread won't change it.
52 this.vplsData = VplsData.of(vplsData);
53 this.op = op;
54 }
55
56 /**
57 * Defines a VPLS operation by binding a given VPLS and operation type.
58 *
59 * @param vplsData the VPLS
60 * @param op the operation
61 * @return the VPLS operation
62 */
63 public static VplsOperation of(VplsData vplsData, Operation op) {
64 return new VplsOperation(vplsData, op);
65 }
66
67 /**
68 * Retrieves the VPLS from the operation.
69 *
70 * @return the VPLS
71 */
72 public VplsData vpls() {
73 return vplsData;
74 }
75
76 /**
77 * Retrieves the operation type from the operation.
78 *
79 * @return the operation type
80 */
81 public Operation op() {
82 return op;
83 }
84
85 @Override
86 public String toString() {
87 return MoreObjects.toStringHelper(getClass())
88 .add("vplsData", vplsData.toString())
89 .add("op", op.toString())
90 .toString();
91 }
92
93 @Override
94 public boolean equals(Object obj) {
95 if (obj == this) {
96 return true;
97 }
98 if (!(obj instanceof VplsOperation)) {
99 return false;
100 }
101 VplsOperation other = (VplsOperation) obj;
102 return Objects.equals(other.vplsData, this.vplsData) &&
103 Objects.equals(other.op, this.op);
104 }
105
106 @Override
107 public int hashCode() {
108 return hash(vplsData, op);
109 }
110}