Initial code import
[msb/apigateway.git] / apiroute / apiroute-service / src / main / java / org / openo / msb / wrapper / consul / model / health / ImmutableService.java
diff --git a/apiroute/apiroute-service/src/main/java/org/openo/msb/wrapper/consul/model/health/ImmutableService.java b/apiroute/apiroute-service/src/main/java/org/openo/msb/wrapper/consul/model/health/ImmutableService.java
new file mode 100644 (file)
index 0000000..70eabf2
--- /dev/null
@@ -0,0 +1,478 @@
+/**\r
+* Copyright (C) 2016 ZTE, Inc. and others. All rights reserved. (ZTE)\r
+*\r
+* Licensed under the Apache License, Version 2.0 (the "License");\r
+* you may not use this file except in compliance with the License.\r
+* You may obtain a copy of the License at\r
+*\r
+* http://www.apache.org/licenses/LICENSE-2.0\r
+*\r
+* Unless required by applicable law or agreed to in writing, software\r
+* distributed under the License is distributed on an "AS IS" BASIS,\r
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+* See the License for the specific language governing permissions and\r
+* limitations under the License.\r
+*/\r
+\r
+package org.openo.msb.wrapper.consul.model.health;\r
+\r
+import com.fasterxml.jackson.annotation.JsonCreator;\r
+import com.fasterxml.jackson.annotation.JsonIgnoreProperties;\r
+import com.fasterxml.jackson.annotation.JsonProperty;\r
+import com.fasterxml.jackson.databind.annotation.JsonDeserialize;\r
+import com.google.common.base.MoreObjects;\r
+import com.google.common.base.Preconditions;\r
+import com.google.common.collect.ImmutableList;\r
+import com.google.common.collect.Lists;\r
+import java.util.List;\r
+import javax.annotation.Generated;\r
+\r
+/**\r
+ * Immutable implementation of {@link Service}.\r
+ * <p>\r
+ * Use the builder to create immutable instances:\r
+ * {@code ImmutableService.builder()}.\r
+ */\r
+@SuppressWarnings("all")\r
+@Generated({"Immutables.generator", "Service"})\r
+@JsonIgnoreProperties(ignoreUnknown = true)\r
+public final class ImmutableService extends Service {\r
+  private final String id;\r
+  private final String service;\r
+  private final ImmutableList<String> tags;\r
+  private final String address;\r
+  private final int port;\r
+\r
+  private ImmutableService(\r
+      String id,\r
+      String service,\r
+      ImmutableList<String> tags,\r
+      String address,\r
+      int port) {\r
+    this.id = id;\r
+    this.service = service;\r
+    this.tags = tags;\r
+    this.address = address;\r
+    this.port = port;\r
+  }\r
+\r
+  /**\r
+   * @return The value of the {@code id} attribute\r
+   */\r
+  @JsonProperty(value = "ID")\r
+  @Override\r
+  public String getId() {\r
+    return id;\r
+  }\r
+\r
+  /**\r
+   * @return The value of the {@code service} attribute\r
+   */\r
+  @JsonProperty(value = "Service")\r
+  @Override\r
+  public String getService() {\r
+    return service;\r
+  }\r
+\r
+  /**\r
+   * @return The value of the {@code tags} attribute\r
+   */\r
+  @JsonProperty(value = "Tags")\r
+  @JsonDeserialize(as = ImmutableList.class, contentAs = String.class)\r
+  @Override\r
+  public ImmutableList<String> getTags() {\r
+    return tags;\r
+  }\r
+\r
+  /**\r
+   * @return The value of the {@code address} attribute\r
+   */\r
+  @JsonProperty(value = "Address")\r
+  @Override\r
+  public String getAddress() {\r
+    return address;\r
+  }\r
+\r
+  /**\r
+   * @return The value of the {@code port} attribute\r
+   */\r
+  @JsonProperty(value = "Port")\r
+  @Override\r
+  public int getPort() {\r
+    return port;\r
+  }\r
+\r
+  /**\r
+   * Copy the current immutable object by setting a value for the {@link Service#getId() id} attribute.\r
+   * An equals check used to prevent copying of the same value by returning {@code this}.\r
+   * @param value A new value for id\r
+   * @return A modified copy of the {@code this} object\r
+   */\r
+  public final ImmutableService withId(String value) {\r
+    if (this.id.equals(value)) return this;\r
+    return new ImmutableService(\r
+        Preconditions.checkNotNull(value, "id"),\r
+        this.service,\r
+        this.tags,\r
+        this.address,\r
+        this.port);\r
+  }\r
+\r
+  /**\r
+   * Copy the current immutable object by setting a value for the {@link Service#getService() service} attribute.\r
+   * An equals check used to prevent copying of the same value by returning {@code this}.\r
+   * @param value A new value for service\r
+   * @return A modified copy of the {@code this} object\r
+   */\r
+  public final ImmutableService withService(String value) {\r
+    if (this.service.equals(value)) return this;\r
+    return new ImmutableService(\r
+        this.id,\r
+        Preconditions.checkNotNull(value, "service"),\r
+        this.tags,\r
+        this.address,\r
+        this.port);\r
+  }\r
+\r
+  /**\r
+   * Copy the current immutable object with elements that replace the content of {@link Service#getTags() tags}.\r
+   * @param elements The elements to set\r
+   * @return A modified copy of {@code this} object\r
+   */\r
+  public final ImmutableService withTags(String... elements) {\r
+    ImmutableList<String> newValue = ImmutableList.copyOf(elements);\r
+    return new ImmutableService(this.id, this.service, newValue, this.address, this.port);\r
+  }\r
+\r
+  /**\r
+   * Copy the current immutable object with elements that replace the content of {@link Service#getTags() tags}.\r
+   * A shallow reference equality check is used to prevent copying of the same value by returning {@code this}.\r
+   * @param elements An iterable of tags elements to set\r
+   * @return A modified copy of {@code this} object\r
+   */\r
+  public final ImmutableService withTags(Iterable<String> elements) {\r
+    if (this.tags == elements) return this;\r
+    ImmutableList<String> newValue = ImmutableList.copyOf(elements);\r
+    return new ImmutableService(this.id, this.service, newValue, this.address, this.port);\r
+  }\r
+\r
+  /**\r
+   * Copy the current immutable object by setting a value for the {@link Service#getAddress() address} attribute.\r
+   * An equals check used to prevent copying of the same value by returning {@code this}.\r
+   * @param value A new value for address\r
+   * @return A modified copy of the {@code this} object\r
+   */\r
+  public final ImmutableService withAddress(String value) {\r
+    if (this.address.equals(value)) return this;\r
+    return new ImmutableService(\r
+        this.id,\r
+        this.service,\r
+        this.tags,\r
+        Preconditions.checkNotNull(value, "address"),\r
+        this.port);\r
+  }\r
+\r
+  /**\r
+   * Copy the current immutable object by setting a value for the {@link Service#getPort() port} attribute.\r
+   * A value equality check is used to prevent copying of the same value by returning {@code this}.\r
+   * @param value A new value for port\r
+   * @return A modified copy of the {@code this} object\r
+   */\r
+  public final ImmutableService withPort(int value) {\r
+    if (this.port == value) return this;\r
+    return new ImmutableService(this.id, this.service, this.tags, this.address, value);\r
+  }\r
+\r
+  /**\r
+   * This instance is equal to all instances of {@code ImmutableService} that have equal attribute values.\r
+   * @return {@code true} if {@code this} is equal to {@code another} instance\r
+   */\r
+  @Override\r
+  public boolean equals(Object another) {\r
+    if (this == another) return true;\r
+    return another instanceof ImmutableService\r
+        && equalTo((ImmutableService) another);\r
+  }\r
+\r
+  private boolean equalTo(ImmutableService another) {\r
+    return id.equals(another.id)\r
+        && service.equals(another.service)\r
+        && tags.equals(another.tags)\r
+        && address.equals(another.address)\r
+        && port == another.port;\r
+  }\r
+\r
+  /**\r
+   * Computes a hash code from attributes: {@code id}, {@code service}, {@code tags}, {@code address}, {@code port}.\r
+   * @return hashCode value\r
+   */\r
+  @Override\r
+  public int hashCode() {\r
+    int h = 31;\r
+    h = h * 17 + id.hashCode();\r
+    h = h * 17 + service.hashCode();\r
+    h = h * 17 + tags.hashCode();\r
+    h = h * 17 + address.hashCode();\r
+    h = h * 17 + port;\r
+    return h;\r
+  }\r
+\r
+  /**\r
+   * Prints the immutable value {@code Service...} with all non-generated\r
+   * and non-auxiliary attribute values.\r
+   * @return A string representation of the value\r
+   */\r
+  @Override\r
+  public String toString() {\r
+    return MoreObjects.toStringHelper("Service")\r
+        .add("id", id)\r
+        .add("service", service)\r
+        .add("tags", tags)\r
+        .add("address", address)\r
+        .add("port", port)\r
+        .toString();\r
+  }\r
+\r
+  /**\r
+   * Utility type used to correctly read immutable object from JSON representation.\r
+   * @deprecated Do not use this type directly, it exists only for the <em>Jackson</em>-binding infrastructure\r
+   */\r
+  @Deprecated\r
+  @JsonDeserialize\r
+  static final class Json extends Service {\r
+    String id;\r
+    String service;\r
+    List<String> tags = ImmutableList.of();\r
+    String address;\r
+    Integer port;\r
+    @JsonProperty(value = "ID")\r
+    public void setId(String id) {\r
+      this.id = id;\r
+    }\r
+    @JsonProperty(value = "Service")\r
+    public void setService(String service) {\r
+      this.service = service;\r
+    }\r
+    @JsonProperty(value = "Tags")\r
+    @JsonDeserialize(as = ImmutableList.class, contentAs = String.class)\r
+    public void setTags(List<String> tags) {\r
+      this.tags = tags;\r
+    }\r
+    @JsonProperty(value = "Address")\r
+    public void setAddress(String address) {\r
+      this.address = address;\r
+    }\r
+    @JsonProperty(value = "Port")\r
+    public void setPort(int port) {\r
+      this.port = port;\r
+    }\r
+    @Override\r
+    public String getId() { throw new UnsupportedOperationException(); }\r
+    @Override\r
+    public String getService() { throw new UnsupportedOperationException(); }\r
+    @Override\r
+    public List<String> getTags() { throw new UnsupportedOperationException(); }\r
+    @Override\r
+    public String getAddress() { throw new UnsupportedOperationException(); }\r
+    @Override\r
+    public int getPort() { throw new UnsupportedOperationException(); }\r
+  }\r
+\r
+  /**\r
+   * @param json A JSON-bindable data structure\r
+   * @return An immutable value type\r
+   * @deprecated Do not use this method directly, it exists only for the <em>Jackson</em>-binding infrastructure\r
+   */\r
+  @Deprecated\r
+  @JsonCreator\r
+  static ImmutableService fromJson(Json json) {\r
+    ImmutableService.Builder builder = ImmutableService.builder();\r
+    if (json.id != null) {\r
+      builder.id(json.id);\r
+    }\r
+    if (json.service != null) {\r
+      builder.service(json.service);\r
+    }\r
+    if (json.tags != null) {\r
+      builder.addAllTags(json.tags);\r
+    }\r
+    if (json.address != null) {\r
+      builder.address(json.address);\r
+    }\r
+    if (json.port != null) {\r
+      builder.port(json.port);\r
+    }\r
+    return builder.build();\r
+  }\r
+\r
+  /**\r
+   * Creates an immutable copy of a {@link Service} value.\r
+   * Uses accessors to get values to initialize the new immutable instance.\r
+   * If an instance is already immutable, it is returned as is.\r
+   * @param instance The instance to copy\r
+   * @return A copied immutable Service instance\r
+   */\r
+  public static ImmutableService copyOf(Service instance) {\r
+    if (instance instanceof ImmutableService) {\r
+      return (ImmutableService) instance;\r
+    }\r
+    return ImmutableService.builder()\r
+        .from(instance)\r
+        .build();\r
+  }\r
+\r
+  /**\r
+   * Creates a builder for {@link ImmutableService ImmutableService}.\r
+   * @return A new ImmutableService builder\r
+   */\r
+  public static ImmutableService.Builder builder() {\r
+    return new ImmutableService.Builder();\r
+  }\r
+\r
+  /**\r
+   * Builds instances of type {@link ImmutableService ImmutableService}.\r
+   * Initialize attributes and then invoke the {@link #build()} method to create an\r
+   * immutable instance.\r
+   * <p><em>{@code Builder} is not thread-safe and generally should not be stored in a field or collection,\r
+   * but instead used immediately to create instances.</em>\r
+   */\r
+  public static final class Builder {\r
+    private static final long INIT_BIT_ID = 0x1L;\r
+    private static final long INIT_BIT_SERVICE = 0x2L;\r
+    private static final long INIT_BIT_ADDRESS = 0x4L;\r
+    private static final long INIT_BIT_PORT = 0x8L;\r
+    private long initBits = 0xf;\r
+\r
+    private String id;\r
+    private String service;\r
+    private ImmutableList.Builder<String> tagsBuilder = ImmutableList.builder();\r
+    private String address;\r
+    private int port;\r
+\r
+    private Builder() {\r
+    }\r
+\r
+    /**\r
+     * Fill a builder with attribute values from the provided {@code Service} instance.\r
+     * Regular attribute values will be replaced with those from the given instance.\r
+     * Absent optional values will not replace present values.\r
+     * Collection elements and entries will be added, not replaced.\r
+     * @param instance The instance from which to copy values\r
+     * @return {@code this} builder for use in a chained invocation\r
+     */\r
+    public final Builder from(Service instance) {\r
+      Preconditions.checkNotNull(instance, "instance");\r
+      id(instance.getId());\r
+      service(instance.getService());\r
+      addAllTags(instance.getTags());\r
+      address(instance.getAddress());\r
+      port(instance.getPort());\r
+      return this;\r
+    }\r
+\r
+    /**\r
+     * Initializes the value for the {@link Service#getId() id} attribute.\r
+     * @param id The value for id \r
+     * @return {@code this} builder for use in a chained invocation\r
+     */\r
+    public final Builder id(String id) {\r
+      this.id = Preconditions.checkNotNull(id, "id");\r
+      initBits &= ~INIT_BIT_ID;\r
+      return this;\r
+    }\r
+\r
+    /**\r
+     * Initializes the value for the {@link Service#getService() service} attribute.\r
+     * @param service The value for service \r
+     * @return {@code this} builder for use in a chained invocation\r
+     */\r
+    public final Builder service(String service) {\r
+      this.service = Preconditions.checkNotNull(service, "service");\r
+      initBits &= ~INIT_BIT_SERVICE;\r
+      return this;\r
+    }\r
+\r
+    /**\r
+     * Adds one element to {@link Service#getTags() tags} list.\r
+     * @param element A tags element\r
+     * @return {@code this} builder for use in a chained invocation\r
+     */\r
+    public final Builder addTags(String element) {\r
+      tagsBuilder.add(element);\r
+      return this;\r
+    }\r
+\r
+    /**\r
+     * Adds elements to {@link Service#getTags() tags} list.\r
+     * @param elements An array of tags elements\r
+     * @return {@code this} builder for use in a chained invocation\r
+     */\r
+    public final Builder addTags(String... elements) {\r
+      tagsBuilder.add(elements);\r
+      return this;\r
+    }\r
+\r
+    /**\r
+     * Sets or replaces all elements for {@link Service#getTags() tags} list.\r
+     * @param elements An iterable of tags elements\r
+     * @return {@code this} builder for use in a chained invocation\r
+     */\r
+    public final Builder tags(Iterable<String> elements) {\r
+      tagsBuilder = ImmutableList.builder();\r
+      return addAllTags(elements);\r
+    }\r
+\r
+    /**\r
+     * Adds elements to {@link Service#getTags() tags} list.\r
+     * @param elements An iterable of tags elements\r
+     * @return {@code this} builder for use in a chained invocation\r
+     */\r
+    public final Builder addAllTags(Iterable<String> elements) {\r
+      tagsBuilder.addAll(elements);\r
+      return this;\r
+    }\r
+\r
+    /**\r
+     * Initializes the value for the {@link Service#getAddress() address} attribute.\r
+     * @param address The value for address \r
+     * @return {@code this} builder for use in a chained invocation\r
+     */\r
+    public final Builder address(String address) {\r
+      this.address = Preconditions.checkNotNull(address, "address");\r
+      initBits &= ~INIT_BIT_ADDRESS;\r
+      return this;\r
+    }\r
+\r
+    /**\r
+     * Initializes the value for the {@link Service#getPort() port} attribute.\r
+     * @param port The value for port \r
+     * @return {@code this} builder for use in a chained invocation\r
+     */\r
+    public final Builder port(int port) {\r
+      this.port = port;\r
+      initBits &= ~INIT_BIT_PORT;\r
+      return this;\r
+    }\r
+\r
+    /**\r
+     * Builds a new {@link ImmutableService ImmutableService}.\r
+     * @return An immutable instance of Service\r
+     * @throws java.lang.IllegalStateException if any required attributes are missing\r
+     */\r
+    public ImmutableService build() throws IllegalStateException {\r
+      if (initBits != 0) {\r
+        throw new IllegalStateException(formatRequiredAttributesMessage());\r
+      }\r
+      return new ImmutableService(id, service, tagsBuilder.build(), address, port);\r
+    }\r
+\r
+    private String formatRequiredAttributesMessage() {\r
+      List<String> attributes = Lists.newArrayList();\r
+      if ((initBits & INIT_BIT_ID) != 0) attributes.add("id");\r
+      if ((initBits & INIT_BIT_SERVICE) != 0) attributes.add("service");\r
+      if ((initBits & INIT_BIT_ADDRESS) != 0) attributes.add("address");\r
+      if ((initBits & INIT_BIT_PORT) != 0) attributes.add("port");\r
+      return "Cannot build Service, some of required attributes are not set " + attributes;\r
+    }\r
+  }\r
+}\r