Fix odlparent 3 Checkstyle issues
[netvirt.git] / vpnservice / 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 java.math.BigInteger;
12 import java.util.List;
13 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid;
14 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.aclservice.rev160608.IpPrefixOrAddress;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.aclservice.rev160608.interfaces._interface.AllowedAddressPairs;
16
17 /**
18  * The Class AclInterface.
19  */
20 public final class AclInterface {
21
22     /** The port security enabled. */
23     private final boolean portSecurityEnabled;
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     /** VPN Id of the interface. */
38     private final Long vpnId;
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     /** The IP broadcast CIDRs. */
47     private final List<IpPrefixOrAddress> subnetIpPrefixes;
48
49     /** The port is marked for delete. */
50     private volatile boolean isMarkedForDelete;
51
52     private AclInterface(Builder builder) {
53         this.portSecurityEnabled = builder.portSecurityEnabled;
54         this.interfaceId = builder.interfaceId;
55         this.lportTag = builder.lportTag;
56         this.dpId = builder.dpId;
57         this.elanId = builder.elanId;
58         this.vpnId = builder.vpnId;
59         this.securityGroups = builder.securityGroups;
60         this.allowedAddressPairs = builder.allowedAddressPairs;
61         this.subnetIpPrefixes = builder.subnetIpPrefixes;
62         this.isMarkedForDelete = builder.isMarkedForDelete;
63     }
64
65     /**
66      * Checks if is port security enabled.
67      *
68      * @return the boolean
69      */
70     public boolean isPortSecurityEnabled() {
71         return portSecurityEnabled;
72     }
73
74     /**
75      * Gets the interface id.
76      *
77      * @return the interface id
78      */
79     public String getInterfaceId() {
80         return interfaceId;
81     }
82
83     /**
84      * Gets the l port tag.
85      *
86      * @return the l port tag
87      */
88     public Integer getLPortTag() {
89         return lportTag;
90     }
91
92     /**
93      * Gets the dp id.
94      *
95      * @return the dp id
96      */
97     public BigInteger getDpId() {
98         return dpId;
99     }
100
101     /**
102      * Gets elan id.
103      *
104      * @return elan id of the interface
105      */
106     public Long getElanId() {
107         return elanId;
108     }
109
110     /**
111      * Gets vpn id.
112      *
113      * @return VPN Id of the interface
114      */
115     public Long getVpnId() {
116         return vpnId;
117     }
118
119     /**
120      * Gets the security groups.
121      *
122      * @return the security groups
123      */
124     public List<Uuid> getSecurityGroups() {
125         return securityGroups;
126     }
127
128     /**
129      * Gets the allowed address pairs.
130      *
131      * @return the allowed address pairs
132      */
133     public List<AllowedAddressPairs> getAllowedAddressPairs() {
134         return allowedAddressPairs;
135     }
136
137     /**
138      * Gets the Subnet IP Prefix.
139      *
140      * @return the Subnet IP Prefix
141      */
142     public List<IpPrefixOrAddress> getSubnetIpPrefixes() {
143         return subnetIpPrefixes;
144     }
145
146     /**
147      * Retrieve isMarkedForDelete.
148      * @return the whether it is marked for delete
149      */
150     public boolean isMarkedForDelete() {
151         return isMarkedForDelete;
152     }
153
154     /**
155      * Sets isMarkedForDelete.
156      * @param isMarkedForDelete boolean value
157      */
158     public void setIsMarkedForDelete(boolean isMarkedForDelete) {
159         this.isMarkedForDelete = isMarkedForDelete;
160     }
161
162     /* (non-Javadoc)
163      * @see java.lang.Object#hashCode()
164      */
165     @Override
166     public int hashCode() {
167         final int prime = 31;
168         int result = 1;
169         result = prime * result + Boolean.hashCode(portSecurityEnabled);
170         result = prime * result + (dpId == null ? 0 : dpId.hashCode());
171         result = prime * result + (interfaceId == null ? 0 : interfaceId.hashCode());
172         result = prime * result + (lportTag == null ? 0 : lportTag.hashCode());
173         result = prime * result + (securityGroups == null ? 0 : securityGroups.hashCode());
174         result = prime * result + (allowedAddressPairs == null ? 0 : allowedAddressPairs.hashCode());
175         result = prime * result + Boolean.hashCode(isMarkedForDelete);
176         return result;
177     }
178
179     /* (non-Javadoc)
180      * @see java.lang.Object#equals(java.lang.Object)
181      */
182     @Override
183     public boolean equals(Object obj) {
184         if (this == obj) {
185             return true;
186         }
187         if (obj == null) {
188             return false;
189         }
190         if (getClass() != obj.getClass()) {
191             return false;
192         }
193         AclInterface other = (AclInterface) obj;
194         if (portSecurityEnabled != other.portSecurityEnabled) {
195             return false;
196         }
197         if (dpId == null) {
198             if (other.dpId != null) {
199                 return false;
200             }
201         } else if (!dpId.equals(other.dpId)) {
202             return false;
203         }
204         if (interfaceId == null) {
205             if (other.interfaceId != null) {
206                 return false;
207             }
208         } else if (!interfaceId.equals(other.interfaceId)) {
209             return false;
210         }
211         if (lportTag == null) {
212             if (other.lportTag != null) {
213                 return false;
214             }
215         } else if (!lportTag.equals(other.lportTag)) {
216             return false;
217         }
218         if (securityGroups == null) {
219             if (other.securityGroups != null) {
220                 return false;
221             }
222         } else if (!securityGroups.equals(other.securityGroups)) {
223             return false;
224         }
225         if (allowedAddressPairs == null) {
226             if (other.allowedAddressPairs != null) {
227                 return false;
228             }
229         } else if (!allowedAddressPairs.equals(other.allowedAddressPairs)) {
230             return false;
231         }
232         if (isMarkedForDelete != other.isMarkedForDelete) {
233             return false;
234         }
235         return true;
236     }
237
238
239     @Override
240     public String toString() {
241         return "AclInterface [interfaceId=" + interfaceId + ", lportTag=" + lportTag + ", dpId=" + dpId + ", elanId="
242                 + elanId + ", vpnId=" + vpnId + ", securityGroups=" + securityGroups + ", allowedAddressPairs="
243                 + allowedAddressPairs + ", subnetIpPrefixes=" + subnetIpPrefixes + ", portSecurityEnabled="
244                 + portSecurityEnabled + ", isMarkedForDelete=" + isMarkedForDelete + "]";
245     }
246
247     public static Builder builder() {
248         return new Builder();
249     }
250
251     public static Builder builder(AclInterface from) {
252         return new Builder(from);
253     }
254
255     public static final class Builder {
256         private boolean portSecurityEnabled;
257         private String interfaceId;
258         private Integer lportTag;
259         private BigInteger dpId;
260         private Long elanId;
261         private Long vpnId;
262         private List<Uuid> securityGroups;
263         private List<AllowedAddressPairs> allowedAddressPairs;
264         private List<IpPrefixOrAddress> subnetIpPrefixes;
265         private boolean isMarkedForDelete;
266
267         private Builder() {
268         }
269
270         private Builder(AclInterface from) {
271             this.portSecurityEnabled = from.portSecurityEnabled;
272             this.interfaceId = from.interfaceId;
273             this.lportTag = from.lportTag;
274             this.dpId = from.dpId;
275             this.elanId = from.elanId;
276             this.vpnId = from.vpnId;
277             this.securityGroups = from.securityGroups;
278             this.allowedAddressPairs = from.allowedAddressPairs;
279             this.subnetIpPrefixes = from.subnetIpPrefixes;
280             this.isMarkedForDelete = from.isMarkedForDelete;
281         }
282
283         public Builder portSecurityEnabled(boolean value) {
284             this.portSecurityEnabled = value;
285             return this;
286         }
287
288         public Builder interfaceId(String value) {
289             this.interfaceId = value;
290             return this;
291         }
292
293         public Builder lPortTag(Integer value) {
294             this.lportTag = value;
295             return this;
296         }
297
298         public Builder dpId(BigInteger value) {
299             this.dpId = value;
300             return this;
301         }
302
303         public Builder elanId(Long value) {
304             this.elanId = value;
305             return this;
306         }
307
308         public Builder vpnId(Long value) {
309             this.vpnId = value;
310             return this;
311         }
312
313         public Builder securityGroups(List<Uuid> list) {
314             this.securityGroups = list == null ? null : ImmutableList.copyOf(list);
315             return this;
316         }
317
318         public Builder allowedAddressPairs(List<AllowedAddressPairs> list) {
319             this.allowedAddressPairs = list == null ? null : ImmutableList.copyOf(list);
320             return this;
321         }
322
323         public Builder subnetIpPrefixes(List<IpPrefixOrAddress> list) {
324             this.subnetIpPrefixes = list == null ? null : ImmutableList.copyOf(list);
325             return this;
326         }
327
328         public Builder isMarkedForDelete(boolean value) {
329             this.isMarkedForDelete = value;
330             return this;
331         }
332
333         public AclInterface build() {
334             return new AclInterface(this);
335         }
336     }
337 }