remove not required docs and .readthedocs.yaml
[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     /**
233      * Creates an immutable copy of a {@link Service} value. Uses accessors to get values to
234      * initialize the new immutable instance. If an instance is already immutable, it is returned as
235      * is.
236      * 
237      * @param instance The instance to copy
238      * @return A copied immutable Service instance
239      */
240     public static ImmutableService copyOf(Service instance) {
241         if (instance instanceof ImmutableService) {
242             return (ImmutableService) instance;
243         }
244         return ImmutableService.builder().from(instance).build();
245     }
246
247     /**
248      * Creates a builder for {@link ImmutableService ImmutableService}.
249      * 
250      * @return A new ImmutableService builder
251      */
252     public static ImmutableService.Builder builder() {
253         return new ImmutableService.Builder();
254     }
255
256     /**
257      * Builds instances of type {@link ImmutableService ImmutableService}. Initialize attributes and
258      * then invoke the {@link #build()} method to create an immutable instance.
259      * <p>
260      * <em>{@code Builder} is not thread-safe and generally should not be stored in a field or
261      * collection, but instead used immediately to create instances.</em>
262      */
263     public static final class Builder {
264         private static final long INIT_BIT_ID = 0x1L;
265         private static final long INIT_BIT_SERVICE = 0x2L;
266         private static final long INIT_BIT_ADDRESS = 0x4L;
267         private static final long INIT_BIT_PORT = 0x8L;
268         private long initBits = 0xf;
269
270         private String id;
271         private String service;
272         private ImmutableList.Builder<String> tagsBuilder = ImmutableList.builder();
273         private String address;
274         private int port;
275
276         private Builder() {}
277
278         /**
279          * Fill a builder with attribute values from the provided {@code Service} instance. Regular
280          * attribute values will be replaced with those from the given instance. Absent optional
281          * values will not replace present values. Collection elements and entries will be added,
282          * not replaced.
283          * 
284          * @param instance The instance from which to copy values
285          * @return {@code this} builder for use in a chained invocation
286          */
287         public final Builder from(Service instance) {
288             Preconditions.checkNotNull(instance, "instance");
289             id(instance.getId());
290             service(instance.getService());
291             addAllTags(instance.getTags());
292             address(instance.getAddress());
293             port(instance.getPort());
294             return this;
295         }
296
297         /**
298          * Initializes the value for the {@link Service#getId() id} attribute.
299          * 
300          * @param id The value for id
301          * @return {@code this} builder for use in a chained invocation
302          */
303         public final Builder id(String id) {
304             this.id = Preconditions.checkNotNull(id, "id");
305             initBits &= ~INIT_BIT_ID;
306             return this;
307         }
308
309         /**
310          * Initializes the value for the {@link Service#getService() service} attribute.
311          * 
312          * @param service The value for service
313          * @return {@code this} builder for use in a chained invocation
314          */
315         public final Builder service(String service) {
316             this.service = Preconditions.checkNotNull(service, "service");
317             initBits &= ~INIT_BIT_SERVICE;
318             return this;
319         }
320
321         /**
322          * Adds one element to {@link Service#getTags() tags} list.
323          * 
324          * @param element A tags element
325          * @return {@code this} builder for use in a chained invocation
326          */
327         public final Builder addTags(String element) {
328             tagsBuilder.add(element);
329             return this;
330         }
331
332         /**
333          * Adds elements to {@link Service#getTags() tags} list.
334          * 
335          * @param elements An array of tags elements
336          * @return {@code this} builder for use in a chained invocation
337          */
338         public final Builder addTags(String... elements) {
339             tagsBuilder.add(elements);
340             return this;
341         }
342
343         /**
344          * Sets or replaces all elements for {@link Service#getTags() tags} list.
345          * 
346          * @param elements An iterable of tags elements
347          * @return {@code this} builder for use in a chained invocation
348          */
349         public final Builder tags(Iterable<String> elements) {
350             tagsBuilder = ImmutableList.builder();
351             return addAllTags(elements);
352         }
353
354         /**
355          * Adds elements to {@link Service#getTags() tags} list.
356          * 
357          * @param elements An iterable of tags elements
358          * @return {@code this} builder for use in a chained invocation
359          */
360         public final Builder addAllTags(Iterable<String> elements) {
361             tagsBuilder.addAll(elements);
362             return this;
363         }
364
365         /**
366          * Initializes the value for the {@link Service#getAddress() address} attribute.
367          * 
368          * @param address The value for address
369          * @return {@code this} builder for use in a chained invocation
370          */
371         public final Builder address(String address) {
372             this.address = Preconditions.checkNotNull(address, "address");
373             initBits &= ~INIT_BIT_ADDRESS;
374             return this;
375         }
376
377         /**
378          * Initializes the value for the {@link Service#getPort() port} attribute.
379          * 
380          * @param port The value for port
381          * @return {@code this} builder for use in a chained invocation
382          */
383         public final Builder port(int port) {
384             this.port = port;
385             initBits &= ~INIT_BIT_PORT;
386             return this;
387         }
388
389         /**
390          * Builds a new {@link ImmutableService ImmutableService}.
391          * 
392          * @return An immutable instance of Service
393          * @throws java.lang.IllegalStateException if any required attributes are missing
394          */
395         public ImmutableService build() throws IllegalStateException {
396             if (initBits != 0) {
397                 throw new IllegalStateException(formatRequiredAttributesMessage());
398             }
399             return new ImmutableService(id, service, tagsBuilder.build(), address, port);
400         }
401
402         private String formatRequiredAttributesMessage() {
403             List<String> attributes = Lists.newArrayList();
404             if ((initBits & INIT_BIT_ID) != 0)
405                 attributes.add("id");
406             if ((initBits & INIT_BIT_SERVICE) != 0)
407                 attributes.add("service");
408             if ((initBits & INIT_BIT_ADDRESS) != 0)
409                 attributes.add("address");
410             if ((initBits & INIT_BIT_PORT) != 0)
411                 attributes.add("port");
412             return "Cannot build Service, some of required attributes are not set " + attributes;
413         }
414     }
415 }