Fix java check style issue
[msb/discovery.git] / sdclient / discovery-service / src / main / java / org / onap / msb / sdclient / wrapper / consul / model / health / ImmutableService.java
1 /**
2  * Copyright 2016-2017 ZTE, Inc. and others.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
5  * in compliance with the License. You may obtain a copy of the License at
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software distributed under the License
10  * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
11  * or implied. See the License for the specific language governing permissions and limitations under
12  * the License.
13  */
14 package org.onap.msb.sdclient.wrapper.consul.model.health;
15
16 import java.util.List;
17
18 import javax.annotation.Generated;
19
20 import com.fasterxml.jackson.annotation.JsonCreator;
21 import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
22 import com.fasterxml.jackson.annotation.JsonProperty;
23 import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
24 import com.google.common.base.MoreObjects;
25 import com.google.common.base.Preconditions;
26 import com.google.common.collect.ImmutableList;
27 import com.google.common.collect.Lists;
28
29 /**
30  * Immutable implementation of {@link Service}.
31  * <p>
32  * Use the builder to create immutable instances: {@code ImmutableService.builder()}.
33  */
34 @SuppressWarnings("all")
35 @Generated({"Immutables.generator", "Service"})
36 @JsonIgnoreProperties(ignoreUnknown = true)
37 public final class ImmutableService extends Service {
38     private final String id;
39     private final String service;
40     private final ImmutableList<String> tags;
41     private final String address;
42     private final int port;
43
44     private ImmutableService(String id, String service, ImmutableList<String> tags, String address, int port) {
45         this.id = id;
46         this.service = service;
47         this.tags = tags;
48         this.address = address;
49         this.port = port;
50     }
51
52     /**
53      * @return The value of the {@code id} attribute
54      */
55     @JsonProperty(value = "ID")
56     @Override
57     public String getId() {
58         return id;
59     }
60
61     /**
62      * @return The value of the {@code service} attribute
63      */
64     @JsonProperty(value = "Service")
65     @Override
66     public String getService() {
67         return service;
68     }
69
70     /**
71      * @return The value of the {@code tags} attribute
72      */
73     @JsonProperty(value = "Tags")
74     @JsonDeserialize(as = ImmutableList.class, contentAs = String.class)
75     @Override
76     public ImmutableList<String> getTags() {
77         return tags;
78     }
79
80     /**
81      * @return The value of the {@code address} attribute
82      */
83     @JsonProperty(value = "Address")
84     @Override
85     public String getAddress() {
86         return address;
87     }
88
89     /**
90      * @return The value of the {@code port} attribute
91      */
92     @JsonProperty(value = "Port")
93     @Override
94     public int getPort() {
95         return port;
96     }
97
98     /**
99      * Copy the current immutable object by setting a value for the {@link Service#getId() id}
100      * attribute. An equals check used to prevent copying of the same value by returning
101      * {@code this}.
102      * 
103      * @param value A new value for id
104      * @return A modified copy of the {@code this} object
105      */
106     public final ImmutableService withId(String value) {
107         if (this.id.equals(value))
108             return this;
109         return new ImmutableService(Preconditions.checkNotNull(value, "id"), this.service, this.tags, this.address,
110                         this.port);
111     }
112
113     /**
114      * Copy the current immutable object by setting a value for the {@link Service#getService()
115      * service} attribute. An equals check used to prevent copying of the same value by returning
116      * {@code this}.
117      * 
118      * @param value A new value for service
119      * @return A modified copy of the {@code this} object
120      */
121     public final ImmutableService withService(String value) {
122         if (this.service.equals(value))
123             return this;
124         return new ImmutableService(this.id, Preconditions.checkNotNull(value, "service"), this.tags, this.address,
125                         this.port);
126     }
127
128     /**
129      * Copy the current immutable object with elements that replace the content of
130      * {@link Service#getTags() tags}.
131      * 
132      * @param elements The elements to set
133      * @return A modified copy of {@code this} object
134      */
135     public final ImmutableService withTags(String... elements) {
136         ImmutableList<String> newValue = ImmutableList.copyOf(elements);
137         return new ImmutableService(this.id, this.service, newValue, this.address, this.port);
138     }
139
140     /**
141      * Copy the current immutable object with elements that replace the content of
142      * {@link Service#getTags() tags}. A shallow reference equality check is used to prevent copying
143      * of the same value by returning {@code this}.
144      * 
145      * @param elements An iterable of tags elements to set
146      * @return A modified copy of {@code this} object
147      */
148     public final ImmutableService withTags(Iterable<String> elements) {
149         if (this.tags == elements)
150             return this;
151         ImmutableList<String> newValue = ImmutableList.copyOf(elements);
152         return new ImmutableService(this.id, this.service, newValue, this.address, this.port);
153     }
154
155     /**
156      * Copy the current immutable object by setting a value for the {@link Service#getAddress()
157      * address} attribute. An equals check used to prevent copying of the same value by returning
158      * {@code this}.
159      * 
160      * @param value A new value for address
161      * @return A modified copy of the {@code this} object
162      */
163     public final ImmutableService withAddress(String value) {
164         if (this.address.equals(value))
165             return this;
166         return new ImmutableService(this.id, this.service, this.tags, Preconditions.checkNotNull(value, "address"),
167                         this.port);
168     }
169
170     /**
171      * Copy the current immutable object by setting a value for the {@link Service#getPort() port}
172      * attribute. A value equality check is used to prevent copying of the same value by returning
173      * {@code this}.
174      * 
175      * @param value A new value for port
176      * @return A modified copy of the {@code this} object
177      */
178     public final ImmutableService withPort(int value) {
179         if (this.port == value)
180             return this;
181         return new ImmutableService(this.id, this.service, this.tags, this.address, value);
182     }
183
184     /**
185      * This instance is equal to all instances of {@code ImmutableService} that have equal attribute
186      * values.
187      * 
188      * @return {@code true} if {@code this} is equal to {@code another} instance
189      */
190     @Override
191     public boolean equals(Object another) {
192         if (this == another)
193             return true;
194         return another instanceof ImmutableService && equalTo((ImmutableService) another);
195     }
196
197     private boolean equalTo(ImmutableService another) {
198         return id.equals(another.id) && service.equals(another.service) && tags.equals(another.tags)
199                         && address.equals(another.address) && port == another.port;
200     }
201
202     /**
203      * Computes a hash code from attributes: {@code id}, {@code service}, {@code tags},
204      * {@code address}, {@code port}.
205      * 
206      * @return hashCode value
207      */
208     @Override
209     public int hashCode() {
210         int h = 31;
211         h = h * 17 + id.hashCode();
212         h = h * 17 + service.hashCode();
213         h = h * 17 + tags.hashCode();
214         h = h * 17 + address.hashCode();
215         h = h * 17 + port;
216         return h;
217     }
218
219     /**
220      * Prints the immutable value {@code Service...} with all non-generated and non-auxiliary
221      * attribute values.
222      * 
223      * @return A string representation of the value
224      */
225     @Override
226     public String toString() {
227         return MoreObjects.toStringHelper("Service").add("id", id).add("service", service).add("tags", tags)
228                         .add("address", address).add("port", port).toString();
229     }
230
231     /**
232      * Utility type used to correctly read immutable object from JSON representation.
233      * 
234      * @deprecated Do not use this type directly, it exists only for the <em>Jackson</em>-binding
235      *             infrastructure
236      */
237     @Deprecated
238     @JsonDeserialize
239     static final class Json extends Service {
240         String id;
241         String service;
242         List<String> tags = ImmutableList.of();
243         String address;
244         Integer port;
245
246         @JsonProperty(value = "ID")
247         public void setId(String id) {
248             this.id = id;
249         }
250
251         @JsonProperty(value = "Service")
252         public void setService(String service) {
253             this.service = service;
254         }
255
256         @JsonProperty(value = "Tags")
257         @JsonDeserialize(as = ImmutableList.class, contentAs = String.class)
258         public void setTags(List<String> tags) {
259             this.tags = tags;
260         }
261
262         @JsonProperty(value = "Address")
263         public void setAddress(String address) {
264             this.address = address;
265         }
266
267         @JsonProperty(value = "Port")
268         public void setPort(int port) {
269             this.port = port;
270         }
271
272         @Override
273         public String getId() {
274             throw new UnsupportedOperationException();
275         }
276
277         @Override
278         public String getService() {
279             throw new UnsupportedOperationException();
280         }
281
282         @Override
283         public List<String> getTags() {
284             throw new UnsupportedOperationException();
285         }
286
287         @Override
288         public String getAddress() {
289             throw new UnsupportedOperationException();
290         }
291
292         @Override
293         public int getPort() {
294             throw new UnsupportedOperationException();
295         }
296     }
297
298     /**
299      * @param json A JSON-bindable data structure
300      * @return An immutable value type
301      * @deprecated Do not use this method directly, it exists only for the <em>Jackson</em>-binding
302      *             infrastructure
303      */
304     @Deprecated
305     @JsonCreator
306     static ImmutableService fromJson(Json json) {
307         ImmutableService.Builder builder = ImmutableService.builder();
308         if (json.id != null) {
309             builder.id(json.id);
310         }
311         if (json.service != null) {
312             builder.service(json.service);
313         }
314         if (json.tags != null) {
315             builder.addAllTags(json.tags);
316         }
317         if (json.address != null) {
318             builder.address(json.address);
319         }
320         if (json.port != null) {
321             builder.port(json.port);
322         }
323         return builder.build();
324     }
325
326     /**
327      * Creates an immutable copy of a {@link Service} value. Uses accessors to get values to
328      * initialize the new immutable instance. If an instance is already immutable, it is returned as
329      * is.
330      * 
331      * @param instance The instance to copy
332      * @return A copied immutable Service instance
333      */
334     public static ImmutableService copyOf(Service instance) {
335         if (instance instanceof ImmutableService) {
336             return (ImmutableService) instance;
337         }
338         return ImmutableService.builder().from(instance).build();
339     }
340
341     /**
342      * Creates a builder for {@link ImmutableService ImmutableService}.
343      * 
344      * @return A new ImmutableService builder
345      */
346     public static ImmutableService.Builder builder() {
347         return new ImmutableService.Builder();
348     }
349
350     /**
351      * Builds instances of type {@link ImmutableService ImmutableService}. Initialize attributes and
352      * then invoke the {@link #build()} method to create an immutable instance.
353      * <p>
354      * <em>{@code Builder} is not thread-safe and generally should not be stored in a field or
355      * collection, but instead used immediately to create instances.</em>
356      */
357     public static final class Builder {
358         private static final long INIT_BIT_ID = 0x1L;
359         private static final long INIT_BIT_SERVICE = 0x2L;
360         private static final long INIT_BIT_ADDRESS = 0x4L;
361         private static final long INIT_BIT_PORT = 0x8L;
362         private long initBits = 0xf;
363
364         private String id;
365         private String service;
366         private ImmutableList.Builder<String> tagsBuilder = ImmutableList.builder();
367         private String address;
368         private int port;
369
370         private Builder() {}
371
372         /**
373          * Fill a builder with attribute values from the provided {@code Service} instance. Regular
374          * attribute values will be replaced with those from the given instance. Absent optional
375          * values will not replace present values. Collection elements and entries will be added,
376          * not replaced.
377          * 
378          * @param instance The instance from which to copy values
379          * @return {@code this} builder for use in a chained invocation
380          */
381         public final Builder from(Service instance) {
382             Preconditions.checkNotNull(instance, "instance");
383             id(instance.getId());
384             service(instance.getService());
385             addAllTags(instance.getTags());
386             address(instance.getAddress());
387             port(instance.getPort());
388             return this;
389         }
390
391         /**
392          * Initializes the value for the {@link Service#getId() id} attribute.
393          * 
394          * @param id The value for id
395          * @return {@code this} builder for use in a chained invocation
396          */
397         public final Builder id(String id) {
398             this.id = Preconditions.checkNotNull(id, "id");
399             initBits &= ~INIT_BIT_ID;
400             return this;
401         }
402
403         /**
404          * Initializes the value for the {@link Service#getService() service} attribute.
405          * 
406          * @param service The value for service
407          * @return {@code this} builder for use in a chained invocation
408          */
409         public final Builder service(String service) {
410             this.service = Preconditions.checkNotNull(service, "service");
411             initBits &= ~INIT_BIT_SERVICE;
412             return this;
413         }
414
415         /**
416          * Adds one element to {@link Service#getTags() tags} list.
417          * 
418          * @param element A tags element
419          * @return {@code this} builder for use in a chained invocation
420          */
421         public final Builder addTags(String element) {
422             tagsBuilder.add(element);
423             return this;
424         }
425
426         /**
427          * Adds elements to {@link Service#getTags() tags} list.
428          * 
429          * @param elements An array of tags elements
430          * @return {@code this} builder for use in a chained invocation
431          */
432         public final Builder addTags(String... elements) {
433             tagsBuilder.add(elements);
434             return this;
435         }
436
437         /**
438          * Sets or replaces all elements for {@link Service#getTags() tags} list.
439          * 
440          * @param elements An iterable of tags elements
441          * @return {@code this} builder for use in a chained invocation
442          */
443         public final Builder tags(Iterable<String> elements) {
444             tagsBuilder = ImmutableList.builder();
445             return addAllTags(elements);
446         }
447
448         /**
449          * Adds elements to {@link Service#getTags() tags} list.
450          * 
451          * @param elements An iterable of tags elements
452          * @return {@code this} builder for use in a chained invocation
453          */
454         public final Builder addAllTags(Iterable<String> elements) {
455             tagsBuilder.addAll(elements);
456             return this;
457         }
458
459         /**
460          * Initializes the value for the {@link Service#getAddress() address} attribute.
461          * 
462          * @param address The value for address
463          * @return {@code this} builder for use in a chained invocation
464          */
465         public final Builder address(String address) {
466             this.address = Preconditions.checkNotNull(address, "address");
467             initBits &= ~INIT_BIT_ADDRESS;
468             return this;
469         }
470
471         /**
472          * Initializes the value for the {@link Service#getPort() port} attribute.
473          * 
474          * @param port The value for port
475          * @return {@code this} builder for use in a chained invocation
476          */
477         public final Builder port(int port) {
478             this.port = port;
479             initBits &= ~INIT_BIT_PORT;
480             return this;
481         }
482
483         /**
484          * Builds a new {@link ImmutableService ImmutableService}.
485          * 
486          * @return An immutable instance of Service
487          * @throws java.lang.IllegalStateException if any required attributes are missing
488          */
489         public ImmutableService build() throws IllegalStateException {
490             if (initBits != 0) {
491                 throw new IllegalStateException(formatRequiredAttributesMessage());
492             }
493             return new ImmutableService(id, service, tagsBuilder.build(), address, port);
494         }
495
496         private String formatRequiredAttributesMessage() {
497             List<String> attributes = Lists.newArrayList();
498             if ((initBits & INIT_BIT_ID) != 0)
499                 attributes.add("id");
500             if ((initBits & INIT_BIT_SERVICE) != 0)
501                 attributes.add("service");
502             if ((initBits & INIT_BIT_ADDRESS) != 0)
503                 attributes.add("address");
504             if ((initBits & INIT_BIT_PORT) != 0)
505                 attributes.add("port");
506             return "Cannot build Service, some of required attributes are not set " + attributes;
507         }
508     }
509 }