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();
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
237 * @param instance The instance to copy
238 * @return A copied immutable Service instance
240 public static ImmutableService copyOf(Service instance) {
241 if (instance instanceof ImmutableService) {
242 return (ImmutableService) instance;
244 return ImmutableService.builder().from(instance).build();
248 * Creates a builder for {@link ImmutableService ImmutableService}.
250 * @return A new ImmutableService builder
252 public static ImmutableService.Builder builder() {
253 return new ImmutableService.Builder();
257 * Builds instances of type {@link ImmutableService ImmutableService}. Initialize attributes and
258 * then invoke the {@link #build()} method to create an immutable instance.
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>
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;
271 private String service;
272 private ImmutableList.Builder<String> tagsBuilder = ImmutableList.builder();
273 private String address;
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,
284 * @param instance The instance from which to copy values
285 * @return {@code this} builder for use in a chained invocation
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());
298 * Initializes the value for the {@link Service#getId() id} attribute.
300 * @param id The value for id
301 * @return {@code this} builder for use in a chained invocation
303 public final Builder id(String id) {
304 this.id = Preconditions.checkNotNull(id, "id");
305 initBits &= ~INIT_BIT_ID;
310 * Initializes the value for the {@link Service#getService() service} attribute.
312 * @param service The value for service
313 * @return {@code this} builder for use in a chained invocation
315 public final Builder service(String service) {
316 this.service = Preconditions.checkNotNull(service, "service");
317 initBits &= ~INIT_BIT_SERVICE;
322 * Adds one element to {@link Service#getTags() tags} list.
324 * @param element A tags element
325 * @return {@code this} builder for use in a chained invocation
327 public final Builder addTags(String element) {
328 tagsBuilder.add(element);
333 * Adds elements to {@link Service#getTags() tags} list.
335 * @param elements An array of tags elements
336 * @return {@code this} builder for use in a chained invocation
338 public final Builder addTags(String... elements) {
339 tagsBuilder.add(elements);
344 * Sets or replaces all elements for {@link Service#getTags() tags} list.
346 * @param elements An iterable of tags elements
347 * @return {@code this} builder for use in a chained invocation
349 public final Builder tags(Iterable<String> elements) {
350 tagsBuilder = ImmutableList.builder();
351 return addAllTags(elements);
355 * Adds elements to {@link Service#getTags() tags} list.
357 * @param elements An iterable of tags elements
358 * @return {@code this} builder for use in a chained invocation
360 public final Builder addAllTags(Iterable<String> elements) {
361 tagsBuilder.addAll(elements);
366 * Initializes the value for the {@link Service#getAddress() address} attribute.
368 * @param address The value for address
369 * @return {@code this} builder for use in a chained invocation
371 public final Builder address(String address) {
372 this.address = Preconditions.checkNotNull(address, "address");
373 initBits &= ~INIT_BIT_ADDRESS;
378 * Initializes the value for the {@link Service#getPort() port} attribute.
380 * @param port The value for port
381 * @return {@code this} builder for use in a chained invocation
383 public final Builder port(int port) {
385 initBits &= ~INIT_BIT_PORT;
390 * Builds a new {@link ImmutableService ImmutableService}.
392 * @return An immutable instance of Service
393 * @throws java.lang.IllegalStateException if any required attributes are missing
395 public ImmutableService build() throws IllegalStateException {
397 throw new IllegalStateException(formatRequiredAttributesMessage());
399 return new ImmutableService(id, service, tagsBuilder.build(), address, port);
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;