Initial code import
[msb/apigateway.git] / apiroute / apiroute-service / src / main / java / org / openo / msb / wrapper / consul / model / catalog / ImmutableCatalogNode.java
diff --git a/apiroute/apiroute-service/src/main/java/org/openo/msb/wrapper/consul/model/catalog/ImmutableCatalogNode.java b/apiroute/apiroute-service/src/main/java/org/openo/msb/wrapper/consul/model/catalog/ImmutableCatalogNode.java
new file mode 100644 (file)
index 0000000..f504168
--- /dev/null
@@ -0,0 +1,306 @@
+/**\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.catalog;\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.ImmutableMap;\r
+import com.google.common.collect.Lists;\r
+\r
+import java.util.List;\r
+import java.util.Map;\r
+\r
+import javax.annotation.Generated;\r
+\r
+import org.openo.msb.wrapper.consul.model.health.Node;\r
+import org.openo.msb.wrapper.consul.model.health.Service;\r
+\r
+/**\r
+ * Immutable implementation of {@link CatalogNode}.\r
+ * <p>\r
+ * Use the builder to create immutable instances:\r
+ * {@code ImmutableCatalogNode.builder()}.\r
+ */\r
+@SuppressWarnings("all")\r
+@Generated({"Immutables.generator", "CatalogNode"})\r
+@JsonIgnoreProperties(ignoreUnknown = true)\r
+public final class ImmutableCatalogNode extends CatalogNode {\r
+  private final Node node;\r
+  private final ImmutableMap<String, Service> services;\r
+\r
+  private ImmutableCatalogNode(\r
+      Node node,\r
+      ImmutableMap<String, Service> services) {\r
+    this.node = node;\r
+    this.services = services;\r
+  }\r
+\r
+  /**\r
+   * @return The value of the {@code node} attribute\r
+   */\r
+  @JsonProperty(value = "Node")\r
+  @Override\r
+  public Node getNode() {\r
+    return node;\r
+  }\r
+\r
+  /**\r
+   * @return The value of the {@code services} attribute\r
+   */\r
+  @JsonProperty(value = "Services")\r
+  @Override\r
+  public ImmutableMap<String, Service> getServices() {\r
+    return services;\r
+  }\r
+\r
+  /**\r
+   * Copy the current immutable object by setting a value for the {@link CatalogNode#getNode() node} attribute.\r
+   * A shallow reference equality check is 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 ImmutableCatalogNode withNode(Node value) {\r
+    if (this.node == value) return this;\r
+    return new ImmutableCatalogNode(Preconditions.checkNotNull(value, "node"), this.services);\r
+  }\r
+\r
+  /**\r
+   * Copy the current immutable object by replacing the {@link CatalogNode#getServices() services} map with the specified map.\r
+   * Nulls are not permitted as keys or values.\r
+   * A shallow reference equality check is used to prevent copying of the same value by returning {@code this}.\r
+   * @param entries The entries to be added to the services map\r
+   * @return A modified copy of {@code this} object\r
+   */\r
+  public final ImmutableCatalogNode withServices(Map<String, ? extends Service> entries) {\r
+    if (this.services == entries) return this;\r
+    ImmutableMap<String, Service> value = ImmutableMap.copyOf(entries);\r
+    return new ImmutableCatalogNode(this.node, value);\r
+  }\r
+\r
+  /**\r
+   * This instance is equal to all instances of {@code ImmutableCatalogNode} 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 ImmutableCatalogNode\r
+        && equalTo((ImmutableCatalogNode) another);\r
+  }\r
+\r
+  private boolean equalTo(ImmutableCatalogNode another) {\r
+    return node.equals(another.node)\r
+        && services.equals(another.services);\r
+  }\r
+\r
+  /**\r
+   * Computes a hash code from attributes: {@code node}, {@code services}.\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 + services.hashCode();\r
+    return h;\r
+  }\r
+\r
+  /**\r
+   * Prints the immutable value {@code CatalogNode...} 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("CatalogNode")\r
+        .add("node", node)\r
+        .add("services", services)\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 CatalogNode {\r
+    Node node;\r
+    Map<String, Service> services;\r
+    @JsonProperty(value = "Node")\r
+    public void setNode(Node node) {\r
+      this.node = node;\r
+    }\r
+    @JsonProperty(value = "Services")\r
+    public void setServices(Map<String, Service> services) {\r
+      this.services = services;\r
+    }\r
+    @Override\r
+    public Node getNode() { throw new UnsupportedOperationException(); }\r
+    @Override\r
+    public Map<String, Service> getServices() { 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 ImmutableCatalogNode fromJson(Json json) {\r
+    ImmutableCatalogNode.Builder builder = ImmutableCatalogNode.builder();\r
+    if (json.node != null) {\r
+      builder.node(json.node);\r
+    }\r
+    if (json.services != null) {\r
+      builder.putAllServices(json.services);\r
+    }\r
+    return builder.build();\r
+  }\r
+\r
+  /**\r
+   * Creates an immutable copy of a {@link CatalogNode} 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 CatalogNode instance\r
+   */\r
+  public static ImmutableCatalogNode copyOf(CatalogNode instance) {\r
+    if (instance instanceof ImmutableCatalogNode) {\r
+      return (ImmutableCatalogNode) instance;\r
+    }\r
+    return ImmutableCatalogNode.builder()\r
+        .from(instance)\r
+        .build();\r
+  }\r
+\r
+  /**\r
+   * Creates a builder for {@link ImmutableCatalogNode ImmutableCatalogNode}.\r
+   * @return A new ImmutableCatalogNode builder\r
+   */\r
+  public static ImmutableCatalogNode.Builder builder() {\r
+    return new ImmutableCatalogNode.Builder();\r
+  }\r
+\r
+  /**\r
+   * Builds instances of type {@link ImmutableCatalogNode ImmutableCatalogNode}.\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 long initBits = 0x1;\r
+\r
+    private Node node;\r
+    private ImmutableMap.Builder<String, Service> servicesBuilder = ImmutableMap.builder();\r
+\r
+    private Builder() {\r
+    }\r
+\r
+    /**\r
+     * Fill a builder with attribute values from the provided {@code CatalogNode} 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(CatalogNode instance) {\r
+      Preconditions.checkNotNull(instance, "instance");\r
+      node(instance.getNode());\r
+      putAllServices(instance.getServices());\r
+      return this;\r
+    }\r
+\r
+    /**\r
+     * Initializes the value for the {@link CatalogNode#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(Node node) {\r
+      this.node = Preconditions.checkNotNull(node, "node");\r
+      initBits &= ~INIT_BIT_NODE;\r
+      return this;\r
+    }\r
+\r
+    /**\r
+     * Put one entry to the {@link CatalogNode#getServices() services} map.\r
+     * @param key The key in the services map\r
+     * @param value The associated value in the services map\r
+     * @return {@code this} builder for use in a chained invocation\r
+     */\r
+    public final Builder putServices(String key, Service value) {\r
+      servicesBuilder.put(key, value);\r
+      return this;\r
+    }\r
+\r
+    /**\r
+     * Put one entry to the {@link CatalogNode#getServices() services} map. Nulls are not permitted\r
+     * @param entry The key and value entry\r
+     * @return {@code this} builder for use in a chained invocation\r
+     */\r
+    public final Builder putServices(Map.Entry<String, ? extends Service> entry) {\r
+      servicesBuilder.put(entry);\r
+      return this;\r
+    }\r
+\r
+    /**\r
+     * Sets or replaces all mappings from the specified map as entries for the {@link CatalogNode#getServices() services} map. Nulls are not permitted\r
+     * @param entries The entries that will be added to the services map\r
+     * @return {@code this} builder for use in a chained invocation\r
+     */\r
+    public final Builder services(Map<String, ? extends Service> entries) {\r
+      servicesBuilder = ImmutableMap.builder();\r
+      return putAllServices(entries);\r
+    }\r
+\r
+    /**\r
+     * Put all mappings from the specified map as entries to {@link CatalogNode#getServices() services} map. Nulls are not permitted\r
+     * @param entries The entries that will be added to the services map\r
+     * @return {@code this} builder for use in a chained invocation\r
+     */\r
+    public final Builder putAllServices(Map<String, ? extends Service> entries) {\r
+      servicesBuilder.putAll(entries);\r
+      return this;\r
+    }\r
+\r
+    /**\r
+     * Builds a new {@link ImmutableCatalogNode ImmutableCatalogNode}.\r
+     * @return An immutable instance of CatalogNode\r
+     * @throws java.lang.IllegalStateException if any required attributes are missing\r
+     */\r
+    public ImmutableCatalogNode build() throws IllegalStateException {\r
+      if (initBits != 0) {\r
+        throw new IllegalStateException(formatRequiredAttributesMessage());\r
+      }\r
+      return new ImmutableCatalogNode(node, servicesBuilder.build());\r
+    }\r
+\r
+    private String formatRequiredAttributesMessage() {\r
+      List<String> attributes = Lists.newArrayList();\r
+      if ((initBits & INIT_BIT_NODE) != 0) attributes.add("node");\r
+      return "Cannot build CatalogNode, some of required attributes are not set " + attributes;\r
+    }\r
+  }\r
+}\r