2  * Copyright 2016 2015-2016 ZTE, Inc. and others. All rights reserved.
 
   4  * Licensed under the Apache License, Version 2.0 (the "License");
 
   5  * you may not use this file except in compliance with the License.
 
   6  * You may obtain a copy of the License at
 
   8  *     http://www.apache.org/licenses/LICENSE-2.0
 
  10  * Unless required by applicable law or agreed to in writing, software
 
  11  * distributed under the License is distributed on an "AS IS" BASIS,
 
  12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 
  13  * See the License for the specific language governing permissions and
 
  14  * limitations under the License.
 
  16 package org.openo.msb.wrapper.consul.model.health;
 
  18 import com.fasterxml.jackson.annotation.JsonCreator;
 
  19 import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
 
  20 import com.fasterxml.jackson.annotation.JsonProperty;
 
  21 import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
 
  22 import com.google.common.base.MoreObjects;
 
  23 import com.google.common.base.Preconditions;
 
  24 import com.google.common.collect.ImmutableList;
 
  25 import com.google.common.collect.Lists;
 
  26 import java.util.List;
 
  27 import javax.annotation.Generated;
 
  30  * Immutable implementation of {@link Service}.
 
  32  * Use the builder to create immutable instances:
 
  33  * {@code ImmutableService.builder()}.
 
  35 @SuppressWarnings("all")
 
  36 @Generated({"Immutables.generator", "Service"})
 
  37 @JsonIgnoreProperties(ignoreUnknown = true)
 
  38 public final class ImmutableService extends Service {
 
  39   private final String id;
 
  40   private final String service;
 
  41   private final ImmutableList<String> tags;
 
  42   private final String address;
 
  43   private final int port;
 
  45   private ImmutableService(
 
  48       ImmutableList<String> tags,
 
  52     this.service = service;
 
  54     this.address = address;
 
  59    * @return The value of the {@code id} attribute
 
  61   @JsonProperty(value = "ID")
 
  63   public String getId() {
 
  68    * @return The value of the {@code service} attribute
 
  70   @JsonProperty(value = "Service")
 
  72   public String getService() {
 
  77    * @return The value of the {@code tags} attribute
 
  79   @JsonProperty(value = "Tags")
 
  80   @JsonDeserialize(as = ImmutableList.class, contentAs = String.class)
 
  82   public ImmutableList<String> getTags() {
 
  87    * @return The value of the {@code address} attribute
 
  89   @JsonProperty(value = "Address")
 
  91   public String getAddress() {
 
  96    * @return The value of the {@code port} attribute
 
  98   @JsonProperty(value = "Port")
 
 100   public int getPort() {
 
 105    * Copy the current immutable object by setting a value for the {@link Service#getId() id} attribute.
 
 106    * An equals check used to prevent copying of the same value by returning {@code this}.
 
 107    * @param value A new value for id
 
 108    * @return A modified copy of the {@code this} object
 
 110   public final ImmutableService withId(String value) {
 
 111     if (this.id.equals(value)) return this;
 
 112     return new ImmutableService(
 
 113         Preconditions.checkNotNull(value, "id"),
 
 121    * Copy the current immutable object by setting a value for the {@link Service#getService() service} attribute.
 
 122    * An equals check used to prevent copying of the same value by returning {@code this}.
 
 123    * @param value A new value for service
 
 124    * @return A modified copy of the {@code this} object
 
 126   public final ImmutableService withService(String value) {
 
 127     if (this.service.equals(value)) return this;
 
 128     return new ImmutableService(
 
 130         Preconditions.checkNotNull(value, "service"),
 
 137    * Copy the current immutable object with elements that replace the content of {@link Service#getTags() tags}.
 
 138    * @param elements The elements to set
 
 139    * @return A modified copy of {@code this} object
 
 141   public final ImmutableService withTags(String... elements) {
 
 142     ImmutableList<String> newValue = ImmutableList.copyOf(elements);
 
 143     return new ImmutableService(this.id, this.service, newValue, this.address, this.port);
 
 147    * Copy the current immutable object with elements that replace the content of {@link Service#getTags() tags}.
 
 148    * A shallow reference equality check is used to prevent copying of the same value by returning {@code this}.
 
 149    * @param elements An iterable of tags elements to set
 
 150    * @return A modified copy of {@code this} object
 
 152   public final ImmutableService withTags(Iterable<String> elements) {
 
 153     if (this.tags == elements) return this;
 
 154     ImmutableList<String> newValue = ImmutableList.copyOf(elements);
 
 155     return new ImmutableService(this.id, this.service, newValue, this.address, this.port);
 
 159    * Copy the current immutable object by setting a value for the {@link Service#getAddress() address} attribute.
 
 160    * An equals check used to prevent copying of the same value by returning {@code this}.
 
 161    * @param value A new value for address
 
 162    * @return A modified copy of the {@code this} object
 
 164   public final ImmutableService withAddress(String value) {
 
 165     if (this.address.equals(value)) return this;
 
 166     return new ImmutableService(
 
 170         Preconditions.checkNotNull(value, "address"),
 
 175    * Copy the current immutable object by setting a value for the {@link Service#getPort() port} attribute.
 
 176    * A value equality check is used to prevent copying of the same value by returning {@code this}.
 
 177    * @param value A new value for port
 
 178    * @return A modified copy of the {@code this} object
 
 180   public final ImmutableService withPort(int value) {
 
 181     if (this.port == value) return this;
 
 182     return new ImmutableService(this.id, this.service, this.tags, this.address, value);
 
 186    * This instance is equal to all instances of {@code ImmutableService} that have equal attribute values.
 
 187    * @return {@code true} if {@code this} is equal to {@code another} instance
 
 190   public boolean equals(Object another) {
 
 191     if (this == another) return true;
 
 192     return another instanceof ImmutableService
 
 193         && equalTo((ImmutableService) another);
 
 196   private boolean equalTo(ImmutableService another) {
 
 197     return id.equals(another.id)
 
 198         && service.equals(another.service)
 
 199         && tags.equals(another.tags)
 
 200         && address.equals(another.address)
 
 201         && port == another.port;
 
 205    * Computes a hash code from attributes: {@code id}, {@code service}, {@code tags}, {@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
 
 221    * and non-auxiliary attribute values.
 
 222    * @return A string representation of the value
 
 225   public String toString() {
 
 226     return MoreObjects.toStringHelper("Service")
 
 228         .add("service", service)
 
 230         .add("address", address)
 
 236    * Utility type used to correctly read immutable object from JSON representation.
 
 237    * @deprecated Do not use this type directly, it exists only for the <em>Jackson</em>-binding infrastructure
 
 241   static final class Json extends Service {
 
 244     List<String> tags = ImmutableList.of();
 
 247     @JsonProperty(value = "ID")
 
 248     public void setId(String id) {
 
 251     @JsonProperty(value = "Service")
 
 252     public void setService(String service) {
 
 253       this.service = service;
 
 255     @JsonProperty(value = "Tags")
 
 256     @JsonDeserialize(as = ImmutableList.class, contentAs = String.class)
 
 257     public void setTags(List<String> tags) {
 
 260     @JsonProperty(value = "Address")
 
 261     public void setAddress(String address) {
 
 262       this.address = address;
 
 264     @JsonProperty(value = "Port")
 
 265     public void setPort(int port) {
 
 269     public String getId() { throw new UnsupportedOperationException(); }
 
 271     public String getService() { throw new UnsupportedOperationException(); }
 
 273     public List<String> getTags() { throw new UnsupportedOperationException(); }
 
 275     public String getAddress() { throw new UnsupportedOperationException(); }
 
 277     public int getPort() { throw new UnsupportedOperationException(); }
 
 281    * @param json A JSON-bindable data structure
 
 282    * @return An immutable value type
 
 283    * @deprecated Do not use this method directly, it exists only for the <em>Jackson</em>-binding infrastructure
 
 287   static ImmutableService fromJson(Json json) {
 
 288     ImmutableService.Builder builder = ImmutableService.builder();
 
 289     if (json.id != null) {
 
 292     if (json.service != null) {
 
 293       builder.service(json.service);
 
 295     if (json.tags != null) {
 
 296       builder.addAllTags(json.tags);
 
 298     if (json.address != null) {
 
 299       builder.address(json.address);
 
 301     if (json.port != null) {
 
 302       builder.port(json.port);
 
 304     return builder.build();
 
 308    * Creates an immutable copy of a {@link Service} value.
 
 309    * Uses accessors to get values to initialize the new immutable instance.
 
 310    * If an instance is already immutable, it is returned as is.
 
 311    * @param instance The instance to copy
 
 312    * @return A copied immutable Service instance
 
 314   public static ImmutableService copyOf(Service instance) {
 
 315     if (instance instanceof ImmutableService) {
 
 316       return (ImmutableService) instance;
 
 318     return ImmutableService.builder()
 
 324    * Creates a builder for {@link ImmutableService ImmutableService}.
 
 325    * @return A new ImmutableService builder
 
 327   public static ImmutableService.Builder builder() {
 
 328     return new ImmutableService.Builder();
 
 332    * Builds instances of type {@link ImmutableService ImmutableService}.
 
 333    * Initialize attributes and then invoke the {@link #build()} method to create an
 
 334    * immutable instance.
 
 335    * <p><em>{@code Builder} is not thread-safe and generally should not be stored in a field or collection,
 
 336    * but instead used immediately to create instances.</em>
 
 338   public static final class Builder {
 
 339     private static final long INIT_BIT_ID = 0x1L;
 
 340     private static final long INIT_BIT_SERVICE = 0x2L;
 
 341     private static final long INIT_BIT_ADDRESS = 0x4L;
 
 342     private static final long INIT_BIT_PORT = 0x8L;
 
 343     private long initBits = 0xf;
 
 346     private String service;
 
 347     private ImmutableList.Builder<String> tagsBuilder = ImmutableList.builder();
 
 348     private String address;
 
 355      * Fill a builder with attribute values from the provided {@code Service} instance.
 
 356      * Regular attribute values will be replaced with those from the given instance.
 
 357      * Absent optional values will not replace present values.
 
 358      * Collection elements and entries will be added, not replaced.
 
 359      * @param instance The instance from which to copy values
 
 360      * @return {@code this} builder for use in a chained invocation
 
 362     public final Builder from(Service instance) {
 
 363       Preconditions.checkNotNull(instance, "instance");
 
 364       id(instance.getId());
 
 365       service(instance.getService());
 
 366       addAllTags(instance.getTags());
 
 367       address(instance.getAddress());
 
 368       port(instance.getPort());
 
 373      * Initializes the value for the {@link Service#getId() id} attribute.
 
 374      * @param id The value for id 
 
 375      * @return {@code this} builder for use in a chained invocation
 
 377     public final Builder id(String id) {
 
 378       this.id = Preconditions.checkNotNull(id, "id");
 
 379       initBits &= ~INIT_BIT_ID;
 
 384      * Initializes the value for the {@link Service#getService() service} attribute.
 
 385      * @param service The value for service 
 
 386      * @return {@code this} builder for use in a chained invocation
 
 388     public final Builder service(String service) {
 
 389       this.service = Preconditions.checkNotNull(service, "service");
 
 390       initBits &= ~INIT_BIT_SERVICE;
 
 395      * Adds one element to {@link Service#getTags() tags} list.
 
 396      * @param element A tags element
 
 397      * @return {@code this} builder for use in a chained invocation
 
 399     public final Builder addTags(String element) {
 
 400       tagsBuilder.add(element);
 
 405      * Adds elements to {@link Service#getTags() tags} list.
 
 406      * @param elements An array of tags elements
 
 407      * @return {@code this} builder for use in a chained invocation
 
 409     public final Builder addTags(String... elements) {
 
 410       tagsBuilder.add(elements);
 
 415      * Sets or replaces all elements for {@link Service#getTags() tags} list.
 
 416      * @param elements An iterable of tags elements
 
 417      * @return {@code this} builder for use in a chained invocation
 
 419     public final Builder tags(Iterable<String> elements) {
 
 420       tagsBuilder = ImmutableList.builder();
 
 421       return addAllTags(elements);
 
 425      * Adds elements to {@link Service#getTags() tags} list.
 
 426      * @param elements An iterable of tags elements
 
 427      * @return {@code this} builder for use in a chained invocation
 
 429     public final Builder addAllTags(Iterable<String> elements) {
 
 430       tagsBuilder.addAll(elements);
 
 435      * Initializes the value for the {@link Service#getAddress() address} attribute.
 
 436      * @param address The value for address 
 
 437      * @return {@code this} builder for use in a chained invocation
 
 439     public final Builder address(String address) {
 
 440       this.address = Preconditions.checkNotNull(address, "address");
 
 441       initBits &= ~INIT_BIT_ADDRESS;
 
 446      * Initializes the value for the {@link Service#getPort() port} attribute.
 
 447      * @param port The value for port 
 
 448      * @return {@code this} builder for use in a chained invocation
 
 450     public final Builder port(int port) {
 
 452       initBits &= ~INIT_BIT_PORT;
 
 457      * Builds a new {@link ImmutableService ImmutableService}.
 
 458      * @return An immutable instance of Service
 
 459      * @throws java.lang.IllegalStateException if any required attributes are missing
 
 461     public ImmutableService build() throws IllegalStateException {
 
 463         throw new IllegalStateException(formatRequiredAttributesMessage());
 
 465       return new ImmutableService(id, service, tagsBuilder.build(), address, port);
 
 468     private String formatRequiredAttributesMessage() {
 
 469       List<String> attributes = Lists.newArrayList();
 
 470       if ((initBits & INIT_BIT_ID) != 0) attributes.add("id");
 
 471       if ((initBits & INIT_BIT_SERVICE) != 0) attributes.add("service");
 
 472       if ((initBits & INIT_BIT_ADDRESS) != 0) attributes.add("address");
 
 473       if ((initBits & INIT_BIT_PORT) != 0) attributes.add("port");
 
 474       return "Cannot build Service, some of required attributes are not set " + attributes;