2 * Copyright (C) 2016 ZTE, Inc. and others. All rights reserved. (ZTE)
\r
4 * Licensed under the Apache License, Version 2.0 (the "License");
\r
5 * you may not use this file except in compliance with the License.
\r
6 * You may obtain a copy of the License at
\r
8 * http://www.apache.org/licenses/LICENSE-2.0
\r
10 * Unless required by applicable law or agreed to in writing, software
\r
11 * distributed under the License is distributed on an "AS IS" BASIS,
\r
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
\r
13 * See the License for the specific language governing permissions and
\r
14 * limitations under the License.
\r
17 package org.openo.msb.wrapper.consul.model.health;
\r
19 import com.fasterxml.jackson.annotation.JsonCreator;
\r
20 import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
\r
21 import com.fasterxml.jackson.annotation.JsonProperty;
\r
22 import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
\r
23 import com.google.common.base.MoreObjects;
\r
24 import com.google.common.base.Preconditions;
\r
25 import com.google.common.collect.ImmutableList;
\r
26 import com.google.common.collect.Lists;
\r
27 import java.util.List;
\r
28 import javax.annotation.Generated;
\r
31 * Immutable implementation of {@link Service}.
\r
33 * Use the builder to create immutable instances:
\r
34 * {@code ImmutableService.builder()}.
\r
36 @SuppressWarnings("all")
\r
37 @Generated({"Immutables.generator", "Service"})
\r
38 @JsonIgnoreProperties(ignoreUnknown = true)
\r
39 public final class ImmutableService extends Service {
\r
40 private final String id;
\r
41 private final String service;
\r
42 private final ImmutableList<String> tags;
\r
43 private final String address;
\r
44 private final int port;
\r
46 private ImmutableService(
\r
49 ImmutableList<String> tags,
\r
53 this.service = service;
\r
55 this.address = address;
\r
60 * @return The value of the {@code id} attribute
\r
62 @JsonProperty(value = "ID")
\r
64 public String getId() {
\r
69 * @return The value of the {@code service} attribute
\r
71 @JsonProperty(value = "Service")
\r
73 public String getService() {
\r
78 * @return The value of the {@code tags} attribute
\r
80 @JsonProperty(value = "Tags")
\r
81 @JsonDeserialize(as = ImmutableList.class, contentAs = String.class)
\r
83 public ImmutableList<String> getTags() {
\r
88 * @return The value of the {@code address} attribute
\r
90 @JsonProperty(value = "Address")
\r
92 public String getAddress() {
\r
97 * @return The value of the {@code port} attribute
\r
99 @JsonProperty(value = "Port")
\r
101 public int getPort() {
\r
106 * Copy the current immutable object by setting a value for the {@link Service#getId() id} attribute.
\r
107 * An equals check used to prevent copying of the same value by returning {@code this}.
\r
108 * @param value A new value for id
\r
109 * @return A modified copy of the {@code this} object
\r
111 public final ImmutableService withId(String value) {
\r
112 if (this.id.equals(value)) return this;
\r
113 return new ImmutableService(
\r
114 Preconditions.checkNotNull(value, "id"),
\r
122 * Copy the current immutable object by setting a value for the {@link Service#getService() service} attribute.
\r
123 * An equals check used to prevent copying of the same value by returning {@code this}.
\r
124 * @param value A new value for service
\r
125 * @return A modified copy of the {@code this} object
\r
127 public final ImmutableService withService(String value) {
\r
128 if (this.service.equals(value)) return this;
\r
129 return new ImmutableService(
\r
131 Preconditions.checkNotNull(value, "service"),
\r
138 * Copy the current immutable object with elements that replace the content of {@link Service#getTags() tags}.
\r
139 * @param elements The elements to set
\r
140 * @return A modified copy of {@code this} object
\r
142 public final ImmutableService withTags(String... elements) {
\r
143 ImmutableList<String> newValue = ImmutableList.copyOf(elements);
\r
144 return new ImmutableService(this.id, this.service, newValue, this.address, this.port);
\r
148 * Copy the current immutable object with elements that replace the content of {@link Service#getTags() tags}.
\r
149 * A shallow reference equality check is used to prevent copying of the same value by returning {@code this}.
\r
150 * @param elements An iterable of tags elements to set
\r
151 * @return A modified copy of {@code this} object
\r
153 public final ImmutableService withTags(Iterable<String> elements) {
\r
154 if (this.tags == elements) return this;
\r
155 ImmutableList<String> newValue = ImmutableList.copyOf(elements);
\r
156 return new ImmutableService(this.id, this.service, newValue, this.address, this.port);
\r
160 * Copy the current immutable object by setting a value for the {@link Service#getAddress() address} attribute.
\r
161 * An equals check used to prevent copying of the same value by returning {@code this}.
\r
162 * @param value A new value for address
\r
163 * @return A modified copy of the {@code this} object
\r
165 public final ImmutableService withAddress(String value) {
\r
166 if (this.address.equals(value)) return this;
\r
167 return new ImmutableService(
\r
171 Preconditions.checkNotNull(value, "address"),
\r
176 * Copy the current immutable object by setting a value for the {@link Service#getPort() port} attribute.
\r
177 * A value equality check is used to prevent copying of the same value by returning {@code this}.
\r
178 * @param value A new value for port
\r
179 * @return A modified copy of the {@code this} object
\r
181 public final ImmutableService withPort(int value) {
\r
182 if (this.port == value) return this;
\r
183 return new ImmutableService(this.id, this.service, this.tags, this.address, value);
\r
187 * This instance is equal to all instances of {@code ImmutableService} that have equal attribute values.
\r
188 * @return {@code true} if {@code this} is equal to {@code another} instance
\r
191 public boolean equals(Object another) {
\r
192 if (this == another) return true;
\r
193 return another instanceof ImmutableService
\r
194 && equalTo((ImmutableService) another);
\r
197 private boolean equalTo(ImmutableService another) {
\r
198 return id.equals(another.id)
\r
199 && service.equals(another.service)
\r
200 && tags.equals(another.tags)
\r
201 && address.equals(another.address)
\r
202 && port == another.port;
\r
206 * Computes a hash code from attributes: {@code id}, {@code service}, {@code tags}, {@code address}, {@code port}.
\r
207 * @return hashCode value
\r
210 public int hashCode() {
\r
212 h = h * 17 + id.hashCode();
\r
213 h = h * 17 + service.hashCode();
\r
214 h = h * 17 + tags.hashCode();
\r
215 h = h * 17 + address.hashCode();
\r
221 * Prints the immutable value {@code Service...} with all non-generated
\r
222 * and non-auxiliary attribute values.
\r
223 * @return A string representation of the value
\r
226 public String toString() {
\r
227 return MoreObjects.toStringHelper("Service")
\r
229 .add("service", service)
\r
231 .add("address", address)
\r
237 * Utility type used to correctly read immutable object from JSON representation.
\r
238 * @deprecated Do not use this type directly, it exists only for the <em>Jackson</em>-binding infrastructure
\r
242 static final class Json extends Service {
\r
245 List<String> tags = ImmutableList.of();
\r
248 @JsonProperty(value = "ID")
\r
249 public void setId(String id) {
\r
252 @JsonProperty(value = "Service")
\r
253 public void setService(String service) {
\r
254 this.service = service;
\r
256 @JsonProperty(value = "Tags")
\r
257 @JsonDeserialize(as = ImmutableList.class, contentAs = String.class)
\r
258 public void setTags(List<String> tags) {
\r
261 @JsonProperty(value = "Address")
\r
262 public void setAddress(String address) {
\r
263 this.address = address;
\r
265 @JsonProperty(value = "Port")
\r
266 public void setPort(int port) {
\r
270 public String getId() { throw new UnsupportedOperationException(); }
\r
272 public String getService() { throw new UnsupportedOperationException(); }
\r
274 public List<String> getTags() { throw new UnsupportedOperationException(); }
\r
276 public String getAddress() { throw new UnsupportedOperationException(); }
\r
278 public int getPort() { throw new UnsupportedOperationException(); }
\r
282 * @param json A JSON-bindable data structure
\r
283 * @return An immutable value type
\r
284 * @deprecated Do not use this method directly, it exists only for the <em>Jackson</em>-binding infrastructure
\r
288 static ImmutableService fromJson(Json json) {
\r
289 ImmutableService.Builder builder = ImmutableService.builder();
\r
290 if (json.id != null) {
\r
291 builder.id(json.id);
\r
293 if (json.service != null) {
\r
294 builder.service(json.service);
\r
296 if (json.tags != null) {
\r
297 builder.addAllTags(json.tags);
\r
299 if (json.address != null) {
\r
300 builder.address(json.address);
\r
302 if (json.port != null) {
\r
303 builder.port(json.port);
\r
305 return builder.build();
\r
309 * Creates an immutable copy of a {@link Service} value.
\r
310 * Uses accessors to get values to initialize the new immutable instance.
\r
311 * If an instance is already immutable, it is returned as is.
\r
312 * @param instance The instance to copy
\r
313 * @return A copied immutable Service instance
\r
315 public static ImmutableService copyOf(Service instance) {
\r
316 if (instance instanceof ImmutableService) {
\r
317 return (ImmutableService) instance;
\r
319 return ImmutableService.builder()
\r
325 * Creates a builder for {@link ImmutableService ImmutableService}.
\r
326 * @return A new ImmutableService builder
\r
328 public static ImmutableService.Builder builder() {
\r
329 return new ImmutableService.Builder();
\r
333 * Builds instances of type {@link ImmutableService ImmutableService}.
\r
334 * Initialize attributes and then invoke the {@link #build()} method to create an
\r
335 * immutable instance.
\r
336 * <p><em>{@code Builder} is not thread-safe and generally should not be stored in a field or collection,
\r
337 * but instead used immediately to create instances.</em>
\r
339 public static final class Builder {
\r
340 private static final long INIT_BIT_ID = 0x1L;
\r
341 private static final long INIT_BIT_SERVICE = 0x2L;
\r
342 private static final long INIT_BIT_ADDRESS = 0x4L;
\r
343 private static final long INIT_BIT_PORT = 0x8L;
\r
344 private long initBits = 0xf;
\r
347 private String service;
\r
348 private ImmutableList.Builder<String> tagsBuilder = ImmutableList.builder();
\r
349 private String address;
\r
352 private Builder() {
\r
356 * Fill a builder with attribute values from the provided {@code Service} instance.
\r
357 * Regular attribute values will be replaced with those from the given instance.
\r
358 * Absent optional values will not replace present values.
\r
359 * Collection elements and entries will be added, not replaced.
\r
360 * @param instance The instance from which to copy values
\r
361 * @return {@code this} builder for use in a chained invocation
\r
363 public final Builder from(Service instance) {
\r
364 Preconditions.checkNotNull(instance, "instance");
\r
365 id(instance.getId());
\r
366 service(instance.getService());
\r
367 addAllTags(instance.getTags());
\r
368 address(instance.getAddress());
\r
369 port(instance.getPort());
\r
374 * Initializes the value for the {@link Service#getId() id} attribute.
\r
375 * @param id The value for id
\r
376 * @return {@code this} builder for use in a chained invocation
\r
378 public final Builder id(String id) {
\r
379 this.id = Preconditions.checkNotNull(id, "id");
\r
380 initBits &= ~INIT_BIT_ID;
\r
385 * Initializes the value for the {@link Service#getService() service} attribute.
\r
386 * @param service The value for service
\r
387 * @return {@code this} builder for use in a chained invocation
\r
389 public final Builder service(String service) {
\r
390 this.service = Preconditions.checkNotNull(service, "service");
\r
391 initBits &= ~INIT_BIT_SERVICE;
\r
396 * Adds one element to {@link Service#getTags() tags} list.
\r
397 * @param element A tags element
\r
398 * @return {@code this} builder for use in a chained invocation
\r
400 public final Builder addTags(String element) {
\r
401 tagsBuilder.add(element);
\r
406 * Adds elements to {@link Service#getTags() tags} list.
\r
407 * @param elements An array of tags elements
\r
408 * @return {@code this} builder for use in a chained invocation
\r
410 public final Builder addTags(String... elements) {
\r
411 tagsBuilder.add(elements);
\r
416 * Sets or replaces all elements for {@link Service#getTags() tags} list.
\r
417 * @param elements An iterable of tags elements
\r
418 * @return {@code this} builder for use in a chained invocation
\r
420 public final Builder tags(Iterable<String> elements) {
\r
421 tagsBuilder = ImmutableList.builder();
\r
422 return addAllTags(elements);
\r
426 * Adds elements to {@link Service#getTags() tags} list.
\r
427 * @param elements An iterable of tags elements
\r
428 * @return {@code this} builder for use in a chained invocation
\r
430 public final Builder addAllTags(Iterable<String> elements) {
\r
431 tagsBuilder.addAll(elements);
\r
436 * Initializes the value for the {@link Service#getAddress() address} attribute.
\r
437 * @param address The value for address
\r
438 * @return {@code this} builder for use in a chained invocation
\r
440 public final Builder address(String address) {
\r
441 this.address = Preconditions.checkNotNull(address, "address");
\r
442 initBits &= ~INIT_BIT_ADDRESS;
\r
447 * Initializes the value for the {@link Service#getPort() port} attribute.
\r
448 * @param port The value for port
\r
449 * @return {@code this} builder for use in a chained invocation
\r
451 public final Builder port(int port) {
\r
453 initBits &= ~INIT_BIT_PORT;
\r
458 * Builds a new {@link ImmutableService ImmutableService}.
\r
459 * @return An immutable instance of Service
\r
460 * @throws java.lang.IllegalStateException if any required attributes are missing
\r
462 public ImmutableService build() throws IllegalStateException {
\r
463 if (initBits != 0) {
\r
464 throw new IllegalStateException(formatRequiredAttributesMessage());
\r
466 return new ImmutableService(id, service, tagsBuilder.build(), address, port);
\r
469 private String formatRequiredAttributesMessage() {
\r
470 List<String> attributes = Lists.newArrayList();
\r
471 if ((initBits & INIT_BIT_ID) != 0) attributes.add("id");
\r
472 if ((initBits & INIT_BIT_SERVICE) != 0) attributes.add("service");
\r
473 if ((initBits & INIT_BIT_ADDRESS) != 0) attributes.add("address");
\r
474 if ((initBits & INIT_BIT_PORT) != 0) attributes.add("port");
\r
475 return "Cannot build Service, some of required attributes are not set " + attributes;
\r