2 * Copyright 2016-2017 ZTE, Inc. and others.
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
7 * http://www.apache.org/licenses/LICENSE-2.0
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
14 package org.onap.msb.sdclient.wrapper.consul.model.health;
16 import java.util.List;
18 import javax.annotation.Generated;
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;
30 * Immutable implementation of {@link Service}.
32 * Use the builder to create immutable instances: {@code ImmutableService.builder()}.
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;
44 private ImmutableService(String id, String service, ImmutableList<String> tags, String address, int port) {
46 this.service = service;
48 this.address = address;
53 * @return The value of the {@code id} attribute
55 @JsonProperty(value = "ID")
57 public String getId() {
62 * @return The value of the {@code service} attribute
64 @JsonProperty(value = "Service")
66 public String getService() {
71 * @return The value of the {@code tags} attribute
73 @JsonProperty(value = "Tags")
74 @JsonDeserialize(as = ImmutableList.class, contentAs = String.class)
76 public ImmutableList<String> getTags() {
81 * @return The value of the {@code address} attribute
83 @JsonProperty(value = "Address")
85 public String getAddress() {
90 * @return The value of the {@code port} attribute
92 @JsonProperty(value = "Port")
94 public int getPort() {
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
103 * @param value A new value for id
104 * @return A modified copy of the {@code this} object
106 public final ImmutableService withId(String value) {
107 if (this.id.equals(value))
109 return new ImmutableService(Preconditions.checkNotNull(value, "id"), this.service, this.tags, this.address,
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
118 * @param value A new value for service
119 * @return A modified copy of the {@code this} object
121 public final ImmutableService withService(String value) {
122 if (this.service.equals(value))
124 return new ImmutableService(this.id, Preconditions.checkNotNull(value, "service"), this.tags, this.address,
129 * Copy the current immutable object with elements that replace the content of
130 * {@link Service#getTags() tags}.
132 * @param elements The elements to set
133 * @return A modified copy of {@code this} object
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);
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}.
145 * @param elements An iterable of tags elements to set
146 * @return A modified copy of {@code this} object
148 public final ImmutableService withTags(Iterable<String> elements) {
149 if (this.tags == elements)
151 ImmutableList<String> newValue = ImmutableList.copyOf(elements);
152 return new ImmutableService(this.id, this.service, newValue, this.address, this.port);
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
160 * @param value A new value for address
161 * @return A modified copy of the {@code this} object
163 public final ImmutableService withAddress(String value) {
164 if (this.address.equals(value))
166 return new ImmutableService(this.id, this.service, this.tags, Preconditions.checkNotNull(value, "address"),
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
175 * @param value A new value for port
176 * @return A modified copy of the {@code this} object
178 public final ImmutableService withPort(int value) {
179 if (this.port == value)
181 return new ImmutableService(this.id, this.service, this.tags, this.address, value);
185 * This instance is equal to all instances of {@code ImmutableService} that have equal attribute
188 * @return {@code true} if {@code this} is equal to {@code another} instance
191 public boolean equals(Object another) {
194 return another instanceof ImmutableService && equalTo((ImmutableService) another);
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;
203 * Computes a hash code from attributes: {@code id}, {@code service}, {@code tags},
204 * {@code address}, {@code port}.
206 * @return hashCode value
209 public int hashCode() {
211 h = h * 17 + id.hashCode();
212 h = h * 17 + service.hashCode();
213 h = h * 17 + tags.hashCode();
214 h = h * 17 + address.hashCode();
220 * Prints the immutable value {@code Service...} with all non-generated and non-auxiliary
223 * @return A string representation of the value
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();
232 * Utility type used to correctly read immutable object from JSON representation.
234 * @deprecated Do not use this type directly, it exists only for the <em>Jackson</em>-binding
239 static final class Json extends Service {
242 List<String> tags = ImmutableList.of();
246 @JsonProperty(value = "ID")
247 public void setId(String id) {
251 @JsonProperty(value = "Service")
252 public void setService(String service) {
253 this.service = service;
256 @JsonProperty(value = "Tags")
257 @JsonDeserialize(as = ImmutableList.class, contentAs = String.class)
258 public void setTags(List<String> tags) {
262 @JsonProperty(value = "Address")
263 public void setAddress(String address) {
264 this.address = address;
267 @JsonProperty(value = "Port")
268 public void setPort(int port) {
273 public String getId() {
274 throw new UnsupportedOperationException();
278 public String getService() {
279 throw new UnsupportedOperationException();
283 public List<String> getTags() {
284 throw new UnsupportedOperationException();
288 public String getAddress() {
289 throw new UnsupportedOperationException();
293 public int getPort() {
294 throw new UnsupportedOperationException();
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
306 static ImmutableService fromJson(Json json) {
307 ImmutableService.Builder builder = ImmutableService.builder();
308 if (json.id != null) {
311 if (json.service != null) {
312 builder.service(json.service);
314 if (json.tags != null) {
315 builder.addAllTags(json.tags);
317 if (json.address != null) {
318 builder.address(json.address);
320 if (json.port != null) {
321 builder.port(json.port);
323 return builder.build();
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
331 * @param instance The instance to copy
332 * @return A copied immutable Service instance
334 public static ImmutableService copyOf(Service instance) {
335 if (instance instanceof ImmutableService) {
336 return (ImmutableService) instance;
338 return ImmutableService.builder().from(instance).build();
342 * Creates a builder for {@link ImmutableService ImmutableService}.
344 * @return A new ImmutableService builder
346 public static ImmutableService.Builder builder() {
347 return new ImmutableService.Builder();
351 * Builds instances of type {@link ImmutableService ImmutableService}. Initialize attributes and
352 * then invoke the {@link #build()} method to create an immutable instance.
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>
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;
365 private String service;
366 private ImmutableList.Builder<String> tagsBuilder = ImmutableList.builder();
367 private String address;
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,
378 * @param instance The instance from which to copy values
379 * @return {@code this} builder for use in a chained invocation
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());
392 * Initializes the value for the {@link Service#getId() id} attribute.
394 * @param id The value for id
395 * @return {@code this} builder for use in a chained invocation
397 public final Builder id(String id) {
398 this.id = Preconditions.checkNotNull(id, "id");
399 initBits &= ~INIT_BIT_ID;
404 * Initializes the value for the {@link Service#getService() service} attribute.
406 * @param service The value for service
407 * @return {@code this} builder for use in a chained invocation
409 public final Builder service(String service) {
410 this.service = Preconditions.checkNotNull(service, "service");
411 initBits &= ~INIT_BIT_SERVICE;
416 * Adds one element to {@link Service#getTags() tags} list.
418 * @param element A tags element
419 * @return {@code this} builder for use in a chained invocation
421 public final Builder addTags(String element) {
422 tagsBuilder.add(element);
427 * Adds elements to {@link Service#getTags() tags} list.
429 * @param elements An array of tags elements
430 * @return {@code this} builder for use in a chained invocation
432 public final Builder addTags(String... elements) {
433 tagsBuilder.add(elements);
438 * Sets or replaces all elements for {@link Service#getTags() tags} list.
440 * @param elements An iterable of tags elements
441 * @return {@code this} builder for use in a chained invocation
443 public final Builder tags(Iterable<String> elements) {
444 tagsBuilder = ImmutableList.builder();
445 return addAllTags(elements);
449 * Adds elements to {@link Service#getTags() tags} list.
451 * @param elements An iterable of tags elements
452 * @return {@code this} builder for use in a chained invocation
454 public final Builder addAllTags(Iterable<String> elements) {
455 tagsBuilder.addAll(elements);
460 * Initializes the value for the {@link Service#getAddress() address} attribute.
462 * @param address The value for address
463 * @return {@code this} builder for use in a chained invocation
465 public final Builder address(String address) {
466 this.address = Preconditions.checkNotNull(address, "address");
467 initBits &= ~INIT_BIT_ADDRESS;
472 * Initializes the value for the {@link Service#getPort() port} attribute.
474 * @param port The value for port
475 * @return {@code this} builder for use in a chained invocation
477 public final Builder port(int port) {
479 initBits &= ~INIT_BIT_PORT;
484 * Builds a new {@link ImmutableService ImmutableService}.
486 * @return An immutable instance of Service
487 * @throws java.lang.IllegalStateException if any required attributes are missing
489 public ImmutableService build() throws IllegalStateException {
491 throw new IllegalStateException(formatRequiredAttributesMessage());
493 return new ImmutableService(id, service, tagsBuilder.build(), address, port);
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;