Initial code import
[msb/apigateway.git] / apiroute / apiroute-service / src / main / java / org / openo / msb / wrapper / consul / model / health / ImmutableNode.java
diff --git a/apiroute/apiroute-service/src/main/java/org/openo/msb/wrapper/consul/model/health/ImmutableNode.java b/apiroute/apiroute-service/src/main/java/org/openo/msb/wrapper/consul/model/health/ImmutableNode.java
new file mode 100644 (file)
index 0000000..8499ac3
--- /dev/null
@@ -0,0 +1,266 @@
+/**\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.Lists;\r
+import java.util.List;\r
+import javax.annotation.Generated;\r
+\r
+/**\r
+ * Immutable implementation of {@link Node}.\r
+ * <p>\r
+ * Use the builder to create immutable instances:\r
+ * {@code ImmutableNode.builder()}.\r
+ */\r
+@SuppressWarnings("all")\r
+@Generated({"Immutables.generator", "Node"})\r
+@JsonIgnoreProperties(ignoreUnknown = true)\r
+public final class ImmutableNode extends Node {\r
+  private final String node;\r
+  private final String address;\r
+\r
+  private ImmutableNode(String node, String address) {\r
+    this.node = node;\r
+    this.address = address;\r
+  }\r
+\r
+  /**\r
+   * @return The value of the {@code node} attribute\r
+   */\r
+  @JsonProperty(value = "Node")\r
+  @Override\r
+  public String getNode() {\r
+    return node;\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
+   * Copy the current immutable object by setting a value for the {@link Node#getNode() node} attribute.\r
+   * An equals check used to prevent copying of the same value by returning {@code this}.\r
+   * @param value A new value for node\r
+   * @return A modified copy of the {@code this} object\r
+   */\r
+  public final ImmutableNode withNode(String value) {\r
+    if (this.node.equals(value)) return this;\r
+    return new ImmutableNode(Preconditions.checkNotNull(value, "node"), this.address);\r
+  }\r
+\r
+  /**\r
+   * Copy the current immutable object by setting a value for the {@link Node#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 ImmutableNode withAddress(String value) {\r
+    if (this.address.equals(value)) return this;\r
+    return new ImmutableNode(this.node, Preconditions.checkNotNull(value, "address"));\r
+  }\r
+\r
+  /**\r
+   * This instance is equal to all instances of {@code ImmutableNode} 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 ImmutableNode\r
+        && equalTo((ImmutableNode) another);\r
+  }\r
+\r
+  private boolean equalTo(ImmutableNode another) {\r
+    return node.equals(another.node)\r
+        && address.equals(another.address);\r
+  }\r
+\r
+  /**\r
+   * Computes a hash code from attributes: {@code node}, {@code address}.\r
+   * @return hashCode value\r
+   */\r
+  @Override\r
+  public int hashCode() {\r
+    int h = 31;\r
+    h = h * 17 + node.hashCode();\r
+    h = h * 17 + address.hashCode();\r
+    return h;\r
+  }\r
+\r
+  /**\r
+   * Prints the immutable value {@code Node...} 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("Node")\r
+        .add("node", node)\r
+        .add("address", address)\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 Node {\r
+    String node;\r
+    String address;\r
+    @JsonProperty(value = "Node")\r
+    public void setNode(String node) {\r
+      this.node = node;\r
+    }\r
+    @JsonProperty(value = "Address")\r
+    public void setAddress(String address) {\r
+      this.address = address;\r
+    }\r
+    @Override\r
+    public String getNode() { throw new UnsupportedOperationException(); }\r
+    @Override\r
+    public String getAddress() { 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 ImmutableNode fromJson(Json json) {\r
+    ImmutableNode.Builder builder = ImmutableNode.builder();\r
+    if (json.node != null) {\r
+      builder.node(json.node);\r
+    }\r
+    if (json.address != null) {\r
+      builder.address(json.address);\r
+    }\r
+    return builder.build();\r
+  }\r
+\r
+  /**\r
+   * Creates an immutable copy of a {@link Node} 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 Node instance\r
+   */\r
+  public static ImmutableNode copyOf(Node instance) {\r
+    if (instance instanceof ImmutableNode) {\r
+      return (ImmutableNode) instance;\r
+    }\r
+    return ImmutableNode.builder()\r
+        .from(instance)\r
+        .build();\r
+  }\r
+\r
+  /**\r
+   * Creates a builder for {@link ImmutableNode ImmutableNode}.\r
+   * @return A new ImmutableNode builder\r
+   */\r
+  public static ImmutableNode.Builder builder() {\r
+    return new ImmutableNode.Builder();\r
+  }\r
+\r
+  /**\r
+   * Builds instances of type {@link ImmutableNode ImmutableNode}.\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_NODE = 0x1L;\r
+    private static final long INIT_BIT_ADDRESS = 0x2L;\r
+    private long initBits = 0x3;\r
+\r
+    private String node;\r
+    private String address;\r
+\r
+    private Builder() {\r
+    }\r
+\r
+    /**\r
+     * Fill a builder with attribute values from the provided {@code Node} instance.\r
+     * Regular attribute values will be replaced with those from the given instance.\r
+     * Absent optional values will not replace present values.\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(Node instance) {\r
+      Preconditions.checkNotNull(instance, "instance");\r
+      node(instance.getNode());\r
+      address(instance.getAddress());\r
+      return this;\r
+    }\r
+\r
+    /**\r
+     * Initializes the value for the {@link Node#getNode() node} attribute.\r
+     * @param node The value for node \r
+     * @return {@code this} builder for use in a chained invocation\r
+     */\r
+    public final Builder node(String node) {\r
+      this.node = Preconditions.checkNotNull(node, "node");\r
+      initBits &= ~INIT_BIT_NODE;\r
+      return this;\r
+    }\r
+\r
+    /**\r
+     * Initializes the value for the {@link Node#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
+     * Builds a new {@link ImmutableNode ImmutableNode}.\r
+     * @return An immutable instance of Node\r
+     * @throws java.lang.IllegalStateException if any required attributes are missing\r
+     */\r
+    public ImmutableNode build() throws IllegalStateException {\r
+      if (initBits != 0) {\r
+        throw new IllegalStateException(formatRequiredAttributesMessage());\r
+      }\r
+      return new ImmutableNode(node, address);\r
+    }\r
+\r
+    private String formatRequiredAttributesMessage() {\r
+      List<String> attributes = Lists.newArrayList();\r
+      if ((initBits & INIT_BIT_NODE) != 0) attributes.add("node");\r
+      if ((initBits & INIT_BIT_ADDRESS) != 0) attributes.add("address");\r
+      return "Cannot build Node, some of required attributes are not set " + attributes;\r
+    }\r
+  }\r
+}\r