Switch to JDT annotations for Nullable and NonNull
[netvirt.git] / aclservice / api / src / main / java / org / opendaylight / netvirt / aclservice / api / utils / AclInterface.java
1 /*
2  * Copyright (c) 2016 Ericsson India Global Services Pvt Ltd. and others. All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8 package org.opendaylight.netvirt.aclservice.api.utils;
9
10 import com.google.common.collect.ImmutableList;
11 import com.google.common.collect.ImmutableSortedSet;
12 import java.math.BigInteger;
13 import java.util.List;
14 import java.util.SortedSet;
15 import org.eclipse.jdt.annotation.Nullable;
16 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.aclservice.rev160608.interfaces._interface.AllowedAddressPairs;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.aclservice.rev160608.interfaces._interface.SubnetInfo;
19
20 /**
21  * The Class AclInterface.
22  */
23 public final class AclInterface {
24
25     /** The interface id. */
26     private final String interfaceId;
27
28     /** The l port tag. */
29     private final Integer lportTag;
30
31     /** The dp id. */
32     private final BigInteger dpId;
33
34     /** Elan tag of the interface. */
35     private final Long elanId;
36
37     /** The port security enabled. */
38     private final boolean portSecurityEnabled;
39
40     /** The security groups. */
41     private final List<Uuid> securityGroups;
42
43     /** The allowed address pairs. */
44     private final List<AllowedAddressPairs> allowedAddressPairs;
45
46     /** List to contain subnet IP CIDRs along with subnet gateway IP. */
47     List<SubnetInfo> subnetInfo;
48
49     /** The ingress remote acl tags. */
50     private final SortedSet<Integer> ingressRemoteAclTags;
51
52     /** The egress remote acl tags. */
53     private final SortedSet<Integer> egressRemoteAclTags;
54
55     /** The port is marked for delete. */
56     private volatile boolean isMarkedForDelete;
57
58     private AclInterface(Builder builder) {
59         this.interfaceId = builder.interfaceId;
60         this.lportTag = builder.lportTag;
61         this.dpId = builder.dpId;
62         this.elanId = builder.elanId;
63         this.portSecurityEnabled = builder.portSecurityEnabled;
64         this.securityGroups = builder.securityGroups;
65         this.allowedAddressPairs = builder.allowedAddressPairs;
66         this.subnetInfo = builder.subnetInfo;
67         this.ingressRemoteAclTags = builder.ingressRemoteAclTags;
68         this.egressRemoteAclTags = builder.egressRemoteAclTags;
69         this.isMarkedForDelete = builder.isMarkedForDelete;
70     }
71
72     /**
73      * Checks if is port security enabled.
74      *
75      * @return the boolean
76      */
77     public boolean isPortSecurityEnabled() {
78         return portSecurityEnabled;
79     }
80
81     /**
82      * Gets the interface id.
83      *
84      * @return the interface id
85      */
86     public String getInterfaceId() {
87         return interfaceId;
88     }
89
90     /**
91      * Gets the l port tag.
92      *
93      * @return the l port tag
94      */
95     public Integer getLPortTag() {
96         return lportTag;
97     }
98
99     /**
100      * Gets the dp id.
101      *
102      * @return the dp id
103      */
104     public BigInteger getDpId() {
105         return dpId;
106     }
107
108     /**
109      * Gets elan id.
110      *
111      * @return elan id of the interface
112      */
113     public Long getElanId() {
114         return elanId;
115     }
116
117     /**
118      * Gets the security groups.
119      *
120      * @return the security groups
121      */
122     public List<Uuid> getSecurityGroups() {
123         return securityGroups;
124     }
125
126     /**
127      * Gets the allowed address pairs.
128      *
129      * @return the allowed address pairs
130      */
131     public List<AllowedAddressPairs> getAllowedAddressPairs() {
132         return allowedAddressPairs;
133     }
134
135     /**
136      * Gets the Subnet info.
137      *
138      * @return the Subnet info
139      */
140     public List<SubnetInfo> getSubnetInfo() {
141         return subnetInfo;
142     }
143
144     /**
145      * Gets the egress remote acl tags.
146      *
147      * @return the egress remote acl tags
148      */
149     public SortedSet<Integer> getEgressRemoteAclTags() {
150         return egressRemoteAclTags;
151     }
152
153     /**
154      * Gets the ingress remote acl tags.
155      *
156      * @return the ingress remote acl tags
157      */
158     public SortedSet<Integer> getIngressRemoteAclTags() {
159         return ingressRemoteAclTags;
160     }
161
162     /**
163      * Retrieve isMarkedForDelete.
164      * @return the whether it is marked for delete
165      */
166     public boolean isMarkedForDelete() {
167         return isMarkedForDelete;
168     }
169
170     /**
171      * Sets isMarkedForDelete.
172      * @param isMarkedForDelete boolean value
173      */
174     public void setIsMarkedForDelete(boolean isMarkedForDelete) {
175         this.isMarkedForDelete = isMarkedForDelete;
176     }
177
178     /* (non-Javadoc)
179      * @see java.lang.Object#hashCode()
180      */
181     @Override
182     public int hashCode() {
183         final int prime = 31;
184         int result = 1;
185         result = prime * result + Boolean.hashCode(portSecurityEnabled);
186         result = prime * result + (dpId == null ? 0 : dpId.hashCode());
187         result = prime * result + (interfaceId == null ? 0 : interfaceId.hashCode());
188         result = prime * result + (lportTag == null ? 0 : lportTag.hashCode());
189         result = prime * result + (securityGroups == null ? 0 : securityGroups.hashCode());
190         result = prime * result + (allowedAddressPairs == null ? 0 : allowedAddressPairs.hashCode());
191         result = prime * result + Boolean.hashCode(isMarkedForDelete);
192         return result;
193     }
194
195     /* (non-Javadoc)
196      * @see java.lang.Object#equals(java.lang.Object)
197      */
198     @Override
199     public boolean equals(Object obj) {
200         if (this == obj) {
201             return true;
202         }
203         if (obj == null) {
204             return false;
205         }
206         if (getClass() != obj.getClass()) {
207             return false;
208         }
209         AclInterface other = (AclInterface) obj;
210         if (portSecurityEnabled != other.portSecurityEnabled) {
211             return false;
212         }
213         if (dpId == null) {
214             if (other.dpId != null) {
215                 return false;
216             }
217         } else if (!dpId.equals(other.dpId)) {
218             return false;
219         }
220         if (interfaceId == null) {
221             if (other.interfaceId != null) {
222                 return false;
223             }
224         } else if (!interfaceId.equals(other.interfaceId)) {
225             return false;
226         }
227         if (lportTag == null) {
228             if (other.lportTag != null) {
229                 return false;
230             }
231         } else if (!lportTag.equals(other.lportTag)) {
232             return false;
233         }
234         if (securityGroups == null) {
235             if (other.securityGroups != null) {
236                 return false;
237             }
238         } else if (!securityGroups.equals(other.securityGroups)) {
239             return false;
240         }
241         if (allowedAddressPairs == null) {
242             if (other.allowedAddressPairs != null) {
243                 return false;
244             }
245         } else if (!allowedAddressPairs.equals(other.allowedAddressPairs)) {
246             return false;
247         }
248         if (isMarkedForDelete != other.isMarkedForDelete) {
249             return false;
250         }
251         return true;
252     }
253
254     @Override
255     public String toString() {
256         return "AclInterface [interfaceId=" + interfaceId + ", lportTag=" + lportTag + ", dpId=" + dpId + ", elanId="
257                 + elanId + ", portSecurityEnabled=" + portSecurityEnabled + ", securityGroups=" + securityGroups
258                 + ", allowedAddressPairs=" + allowedAddressPairs + ", subnetInfo=" + subnetInfo
259                 + ", ingressRemoteAclTags=" + ingressRemoteAclTags + ", egressRemoteAclTags=" + egressRemoteAclTags
260                 + ", isMarkedForDelete=" + isMarkedForDelete + "]";
261     }
262
263     public static Builder builder() {
264         return new Builder();
265     }
266
267     public static Builder builder(AclInterface from) {
268         return new Builder(from);
269     }
270
271     public static final class Builder {
272         private String interfaceId;
273         private Integer lportTag;
274         private BigInteger dpId;
275         private Long elanId;
276         private boolean portSecurityEnabled;
277         private @Nullable List<Uuid> securityGroups;
278         private @Nullable List<AllowedAddressPairs> allowedAddressPairs;
279         private @Nullable List<SubnetInfo> subnetInfo;
280         private @Nullable SortedSet<Integer> ingressRemoteAclTags;
281         private @Nullable SortedSet<Integer> egressRemoteAclTags;
282         private boolean isMarkedForDelete;
283
284         private Builder() {
285         }
286
287         private Builder(AclInterface from) {
288             this.interfaceId = from.interfaceId;
289             this.lportTag = from.lportTag;
290             this.dpId = from.dpId;
291             this.elanId = from.elanId;
292             this.portSecurityEnabled = from.portSecurityEnabled;
293             this.securityGroups = from.securityGroups;
294             this.allowedAddressPairs = from.allowedAddressPairs;
295             this.subnetInfo = from.subnetInfo;
296             this.ingressRemoteAclTags = from.ingressRemoteAclTags;
297             this.egressRemoteAclTags = from.egressRemoteAclTags;
298             this.isMarkedForDelete = from.isMarkedForDelete;
299         }
300
301         public Builder portSecurityEnabled(boolean value) {
302             this.portSecurityEnabled = value;
303             return this;
304         }
305
306         public Builder interfaceId(String value) {
307             this.interfaceId = value;
308             return this;
309         }
310
311         public Builder lPortTag(Integer value) {
312             this.lportTag = value;
313             return this;
314         }
315
316         public Builder dpId(BigInteger value) {
317             this.dpId = value;
318             return this;
319         }
320
321         public Builder elanId(Long value) {
322             this.elanId = value;
323             return this;
324         }
325
326         public Builder securityGroups(@Nullable List<Uuid> list) {
327             this.securityGroups = list == null ? null : ImmutableList.copyOf(list);
328             return this;
329         }
330
331         public Builder allowedAddressPairs(@Nullable List<AllowedAddressPairs> list) {
332             this.allowedAddressPairs = list == null ? null : ImmutableList.copyOf(list);
333             return this;
334         }
335
336         public Builder subnetInfo(@Nullable List<SubnetInfo> list) {
337             this.subnetInfo = list == null ? null : ImmutableList.copyOf(list);
338             return this;
339         }
340
341         public Builder ingressRemoteAclTags(@Nullable SortedSet<Integer> list) {
342             this.ingressRemoteAclTags = list == null ? null : ImmutableSortedSet.copyOf(list);
343             return this;
344         }
345
346         public Builder egressRemoteAclTags(@Nullable SortedSet<Integer> list) {
347             this.egressRemoteAclTags = list == null ? null : ImmutableSortedSet.copyOf(list);
348             return this;
349         }
350
351         public Builder isMarkedForDelete(boolean value) {
352             this.isMarkedForDelete = value;
353             return this;
354         }
355
356         public AclInterface build() {
357             return new AclInterface(this);
358         }
359     }
360 }