blob: 877cc6c95635f203cedc545a1123871bddd92daa [file] [log] [blame]
Phaneendra Manda63fecef2015-10-26 22:21:03 +05301/*
2 * Copyright 2015 Open Networking Laboratory
3 *
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 */
16package org.onosproject.vtnrsc;
17
18import static com.google.common.base.MoreObjects.toStringHelper;
19import static com.google.common.base.Preconditions.checkNotNull;
20
21import java.util.List;
22import java.util.Objects;
23
24import com.google.common.collect.ImmutableList;
25
26/**
27 * Implementation of port pair group.
28 */
29public final class DefaultPortPairGroup implements PortPairGroup {
30
31 private final PortPairGroupId portPairGroupId;
32 private final TenantId tenantId;
33 private final String name;
34 private final String description;
35 private final List<PortPairId> portPairList;
36
37 /**
38 * Default constructor to create Port Pair Group.
39 *
40 * @param portPairGroupId port pair group id
41 * @param tenantId tenant id
42 * @param name name of port pair group
43 * @param description description of port pair group
44 * @param portPairList list of port pairs
45 */
46 private DefaultPortPairGroup(PortPairGroupId portPairGroupId, TenantId tenantId,
47 String name, String description,
48 List<PortPairId> portPairList) {
49
50 this.portPairGroupId = portPairGroupId;
51 this.tenantId = tenantId;
52 this.name = name;
53 this.description = description;
54 this.portPairList = portPairList;
55 }
56
57 @Override
58 public PortPairGroupId portPairGroupId() {
59 return portPairGroupId;
60 }
61
62 @Override
63 public TenantId tenantId() {
64 return tenantId;
65 }
66
67 @Override
68 public String name() {
69 return name;
70 }
71
72 @Override
73 public String description() {
74 return description;
75 }
76
77 @Override
78 public List<PortPairId> portPairs() {
79 return ImmutableList.copyOf(portPairList);
80 }
81
82 @Override
83 public int hashCode() {
84 return Objects.hash(portPairGroupId, tenantId, name, description,
85 portPairList);
86 }
87
88 @Override
89 public boolean equals(Object obj) {
90 if (this == obj) {
91 return true;
92 }
93 if (obj instanceof DefaultPortPairGroup) {
94 DefaultPortPairGroup that = (DefaultPortPairGroup) obj;
95 return Objects.equals(portPairGroupId, that.portPairGroupId) &&
96 Objects.equals(tenantId, that.tenantId) &&
97 Objects.equals(name, that.name) &&
98 Objects.equals(description, that.description) &&
99 Objects.equals(portPairList, that.portPairList);
100 }
101 return false;
102 }
103
104 @Override
105 public boolean exactMatch(PortPairGroup portPairGroup) {
106 return this.equals(portPairGroup) &&
107 Objects.equals(this.portPairGroupId, portPairGroup.portPairGroupId()) &&
108 Objects.equals(this.tenantId, portPairGroup.tenantId());
109 }
110
111 @Override
112 public String toString() {
113 return toStringHelper(this)
114 .add("id", portPairGroupId.toString())
115 .add("tenantId", tenantId.toString())
116 .add("name", name)
117 .add("description", description)
118 .add("portPairGroupList", portPairList)
119 .toString();
120 }
121
122 /**
123 * To create an instance of the builder.
124 *
125 * @return instance of builder
126 */
127 public static Builder builder() {
128 return new Builder();
129 }
130
131 /**
132 * Builder class for Port pair group.
133 */
134 public static final class Builder implements PortPairGroup.Builder {
135
136 private PortPairGroupId portPairGroupId;
137 private TenantId tenantId;
138 private String name;
139 private String description;
140 private List<PortPairId> portPairList;
141
142 @Override
143 public Builder setId(PortPairGroupId portPairGroupId) {
144 this.portPairGroupId = portPairGroupId;
145 return this;
146 }
147
148 @Override
149 public Builder setTenantId(TenantId tenantId) {
150 this.tenantId = tenantId;
151 return this;
152 }
153
154 @Override
155 public Builder setName(String name) {
156 this.name = name;
157 return this;
158 }
159
160 @Override
161 public Builder setDescription(String description) {
162 this.description = description;
163 return this;
164 }
165
166 @Override
167 public Builder setPortPairs(List<PortPairId> portPairs) {
168 this.portPairList = portPairs;
169 return this;
170 }
171
172 @Override
173 public PortPairGroup build() {
174
175 checkNotNull(portPairGroupId, "Port pair group id cannot be null");
176 checkNotNull(tenantId, "Tenant id cannot be null");
177 checkNotNull(portPairList, "Port pairs cannot be null");
178
179 return new DefaultPortPairGroup(portPairGroupId, tenantId, name, description,
180 portPairList);
181 }
182 }
183}