Initial code import
[msb/apigateway.git] / apiroute / apiroute-service / src / main / java / org / openo / msb / wrapper / consul / option / ImmutableQueryOptions.java
diff --git a/apiroute/apiroute-service/src/main/java/org/openo/msb/wrapper/consul/option/ImmutableQueryOptions.java b/apiroute/apiroute-service/src/main/java/org/openo/msb/wrapper/consul/option/ImmutableQueryOptions.java
new file mode 100644 (file)
index 0000000..87a0f8a
--- /dev/null
@@ -0,0 +1,531 @@
+/**\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.option;\r
+\r
+import com.google.common.base.MoreObjects;\r
+import com.google.common.base.Optional;\r
+import com.google.common.base.Preconditions;\r
+import com.google.common.collect.Lists;\r
+import com.google.common.primitives.Booleans;\r
+import java.math.BigInteger;\r
+import java.util.ArrayList;\r
+import javax.annotation.Generated;\r
+\r
+/**\r
+ * Immutable implementation of {@link QueryOptions}.\r
+ * <p>\r
+ * Use the builder to create immutable instances:\r
+ * {@code ImmutableQueryOptions.builder()}.\r
+ */\r
+@SuppressWarnings("all")\r
+@Generated({"Immutables.generator", "QueryOptions"})\r
+public final class ImmutableQueryOptions extends QueryOptions {\r
+  private final Optional<String> wait;\r
+  private final Optional<String> token;\r
+  private final Optional<BigInteger> index;\r
+  private final Optional<String> near;\r
+  private final ConsistencyMode consistencyMode;\r
+  private final boolean isBlocking;\r
+  private final boolean hasToken;\r
+\r
+  private ImmutableQueryOptions(ImmutableQueryOptions.Builder builder) {\r
+    this.wait = builder.wait;\r
+    this.token = builder.token;\r
+    this.index = builder.index;\r
+    this.near = builder.near;\r
+    if (builder.consistencyMode != null) {\r
+      initShim.consistencyMode(builder.consistencyMode);\r
+    }\r
+    this.consistencyMode = initShim.getConsistencyMode();\r
+    this.isBlocking = initShim.isBlocking();\r
+    this.hasToken = initShim.hasToken();\r
+    this.initShim = null;\r
+  }\r
+\r
+  private ImmutableQueryOptions(\r
+      Optional<String> wait,\r
+      Optional<String> token,\r
+      Optional<BigInteger> index,\r
+      Optional<String> near,\r
+      ConsistencyMode consistencyMode) {\r
+    this.wait = wait;\r
+    this.token = token;\r
+    this.index = index;\r
+    this.near = near;\r
+    this.consistencyMode = consistencyMode;\r
+    initShim.consistencyMode(consistencyMode);\r
+    this.isBlocking = initShim.isBlocking();\r
+    this.hasToken = initShim.hasToken();\r
+    this.initShim = null;\r
+  }\r
+\r
+  private static final int STAGE_INITIALIZING = -1;\r
+  private static final int STAGE_UNINITIALIZED = 0;\r
+  private static final int STAGE_INITIALIZED = 1;\r
+  private volatile InitShim initShim = new InitShim();\r
+\r
+  private final class InitShim {\r
+    private ConsistencyMode consistencyMode;\r
+    private byte consistencyModeStage;\r
+\r
+    ConsistencyMode getConsistencyMode() {\r
+      if (consistencyModeStage == STAGE_INITIALIZING) throw new IllegalStateException(formatInitCycleMessage());\r
+      if (consistencyModeStage == STAGE_UNINITIALIZED) {\r
+        consistencyModeStage = STAGE_INITIALIZING;\r
+        this.consistencyMode = Preconditions.checkNotNull(ImmutableQueryOptions.super.getConsistencyMode(), "consistencyMode");\r
+        consistencyModeStage = STAGE_INITIALIZED;\r
+      }\r
+      return consistencyMode;\r
+    }\r
+\r
+    ConsistencyMode consistencyMode(ConsistencyMode value) {\r
+      this.consistencyMode = value;\r
+      consistencyModeStage = STAGE_INITIALIZED;\r
+      return value;\r
+    }\r
+    private boolean isBlocking;\r
+    private byte isBlockingStage;\r
+\r
+    boolean isBlocking() {\r
+      if (isBlockingStage == STAGE_INITIALIZING) throw new IllegalStateException(formatInitCycleMessage());\r
+      if (isBlockingStage == STAGE_UNINITIALIZED) {\r
+        isBlockingStage = STAGE_INITIALIZING;\r
+        this.isBlocking = ImmutableQueryOptions.super.isBlocking();\r
+        isBlockingStage = STAGE_INITIALIZED;\r
+      }\r
+      return isBlocking;\r
+    }\r
+    private boolean hasToken;\r
+    private byte hasTokenStage;\r
+\r
+    boolean hasToken() {\r
+      if (hasTokenStage == STAGE_INITIALIZING) throw new IllegalStateException(formatInitCycleMessage());\r
+      if (hasTokenStage == STAGE_UNINITIALIZED) {\r
+        hasTokenStage = STAGE_INITIALIZING;\r
+        this.hasToken = ImmutableQueryOptions.super.hasToken();\r
+        hasTokenStage = STAGE_INITIALIZED;\r
+      }\r
+      return hasToken;\r
+    }\r
+\r
+    private String formatInitCycleMessage() {\r
+      ArrayList<String> attributes = Lists.newArrayList();\r
+      if (consistencyModeStage == STAGE_INITIALIZING) attributes.add("consistencyMode");\r
+      if (isBlockingStage == STAGE_INITIALIZING) attributes.add("isBlocking");\r
+      if (hasTokenStage == STAGE_INITIALIZING) attributes.add("hasToken");\r
+      return "Cannot build QueryOptions, attribute initializers form cycle" + attributes;\r
+    }\r
+  }\r
+\r
+  /**\r
+   * @return The value of the {@code wait} attribute\r
+   */\r
+  @Override\r
+  public Optional<String> getWait() {\r
+    return wait;\r
+  }\r
+\r
+  /**\r
+   * @return The value of the {@code token} attribute\r
+   */\r
+  @Override\r
+  public Optional<String> getToken() {\r
+    return token;\r
+  }\r
+\r
+  /**\r
+   * @return The value of the {@code index} attribute\r
+   */\r
+  @Override\r
+  public Optional<BigInteger> getIndex() {\r
+    return index;\r
+  }\r
+\r
+  /**\r
+   * @return The value of the {@code near} attribute\r
+   */\r
+  @Override\r
+  public Optional<String> getNear() {\r
+    return near;\r
+  }\r
+\r
+  /**\r
+   * @return The value of the {@code consistencyMode} attribute\r
+   */\r
+  @Override\r
+  public ConsistencyMode getConsistencyMode() {\r
+    return initShim != null\r
+        ? initShim.getConsistencyMode()\r
+        : consistencyMode;\r
+  }\r
+\r
+  /**\r
+   * @return The computed-at-construction value of the {@code isBlocking} attribute\r
+   */\r
+  @Override\r
+  public boolean isBlocking() {\r
+    return initShim != null\r
+        ? initShim.isBlocking()\r
+        : isBlocking;\r
+  }\r
+\r
+  /**\r
+   * @return The computed-at-construction value of the {@code hasToken} attribute\r
+   */\r
+  @Override\r
+  public boolean hasToken() {\r
+    return initShim != null\r
+        ? initShim.hasToken()\r
+        : hasToken;\r
+  }\r
+\r
+  /**\r
+   * Copy the current immutable object by setting a <i>present</i> value for the optional {@link QueryOptions#getWait() wait} attribute.\r
+   * @param value The value for wait\r
+   * @return A modified copy of {@code this} object\r
+   */\r
+  public final ImmutableQueryOptions withWait(String value) {\r
+    Optional<String> newValue = Optional.of(value);\r
+    return validate(new ImmutableQueryOptions(newValue, this.token, this.index, this.near, this.consistencyMode));\r
+  }\r
+\r
+  /**\r
+   * Copy the current immutable object by setting an optional value for the {@link QueryOptions#getWait() wait} attribute.\r
+   * A shallow reference equality check on the optional value is used to prevent copying of the same value by returning {@code this}.\r
+   * @param optional A value for wait\r
+   * @return A modified copy of {@code this} object\r
+   */\r
+  public final ImmutableQueryOptions withWait(Optional<String> optional) {\r
+    Optional<String> value = Preconditions.checkNotNull(optional, "wait");\r
+    if (this.wait == value) return this;\r
+    return validate(new ImmutableQueryOptions(value, this.token, this.index, this.near, this.consistencyMode));\r
+  }\r
+\r
+  /**\r
+   * Copy the current immutable object by setting a <i>present</i> value for the optional {@link QueryOptions#getToken() token} attribute.\r
+   * @param value The value for token\r
+   * @return A modified copy of {@code this} object\r
+   */\r
+  public final ImmutableQueryOptions withToken(String value) {\r
+    Optional<String> newValue = Optional.of(value);\r
+    return validate(new ImmutableQueryOptions(this.wait, newValue, this.index, this.near, this.consistencyMode));\r
+  }\r
+\r
+  /**\r
+   * Copy the current immutable object by setting an optional value for the {@link QueryOptions#getToken() token} attribute.\r
+   * A shallow reference equality check on the optional value is used to prevent copying of the same value by returning {@code this}.\r
+   * @param optional A value for token\r
+   * @return A modified copy of {@code this} object\r
+   */\r
+  public final ImmutableQueryOptions withToken(Optional<String> optional) {\r
+    Optional<String> value = Preconditions.checkNotNull(optional, "token");\r
+    if (this.token == value) return this;\r
+    return validate(new ImmutableQueryOptions(this.wait, value, this.index, this.near, this.consistencyMode));\r
+  }\r
+\r
+  /**\r
+   * Copy the current immutable object by setting a <i>present</i> value for the optional {@link QueryOptions#getIndex() index} attribute.\r
+   * @param value The value for index\r
+   * @return A modified copy of {@code this} object\r
+   */\r
+  public final ImmutableQueryOptions withIndex(BigInteger value) {\r
+    Optional<BigInteger> newValue = Optional.of(value);\r
+    return validate(new ImmutableQueryOptions(this.wait, this.token, newValue, this.near, this.consistencyMode));\r
+  }\r
+\r
+  /**\r
+   * Copy the current immutable object by setting an optional value for the {@link QueryOptions#getIndex() index} attribute.\r
+   * A shallow reference equality check on the optional value is used to prevent copying of the same value by returning {@code this}.\r
+   * @param optional A value for index\r
+   * @return A modified copy of {@code this} object\r
+   */\r
+  public final ImmutableQueryOptions withIndex(Optional<BigInteger> optional) {\r
+    Optional<BigInteger> value = Preconditions.checkNotNull(optional, "index");\r
+    if (this.index == value) return this;\r
+    return validate(new ImmutableQueryOptions(this.wait, this.token, value, this.near, this.consistencyMode));\r
+  }\r
+\r
+  /**\r
+   * Copy the current immutable object by setting a <i>present</i> value for the optional {@link QueryOptions#getNear() near} attribute.\r
+   * @param value The value for near\r
+   * @return A modified copy of {@code this} object\r
+   */\r
+  public final ImmutableQueryOptions withNear(String value) {\r
+    Optional<String> newValue = Optional.of(value);\r
+    return validate(new ImmutableQueryOptions(this.wait, this.token, this.index, newValue, this.consistencyMode));\r
+  }\r
+\r
+  /**\r
+   * Copy the current immutable object by setting an optional value for the {@link QueryOptions#getNear() near} attribute.\r
+   * A shallow reference equality check on the optional value is used to prevent copying of the same value by returning {@code this}.\r
+   * @param optional A value for near\r
+   * @return A modified copy of {@code this} object\r
+   */\r
+  public final ImmutableQueryOptions withNear(Optional<String> optional) {\r
+    Optional<String> value = Preconditions.checkNotNull(optional, "near");\r
+    if (this.near == value) return this;\r
+    return validate(new ImmutableQueryOptions(this.wait, this.token, this.index, value, this.consistencyMode));\r
+  }\r
+\r
+  /**\r
+   * Copy the current immutable object by setting a value for the {@link QueryOptions#getConsistencyMode() consistencyMode} 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 consistencyMode\r
+   * @return A modified copy of the {@code this} object\r
+   */\r
+  public final ImmutableQueryOptions withConsistencyMode(ConsistencyMode value) {\r
+    if (this.consistencyMode == value) return this;\r
+    return validate(new ImmutableQueryOptions(\r
+        this.wait,\r
+        this.token,\r
+        this.index,\r
+        this.near,\r
+        Preconditions.checkNotNull(value, "consistencyMode")));\r
+  }\r
+\r
+  /**\r
+   * This instance is equal to all instances of {@code ImmutableQueryOptions} 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 ImmutableQueryOptions\r
+        && equalTo((ImmutableQueryOptions) another);\r
+  }\r
+\r
+  private boolean equalTo(ImmutableQueryOptions another) {\r
+    return wait.equals(another.wait)\r
+        && token.equals(another.token)\r
+        && index.equals(another.index)\r
+        && near.equals(another.near)\r
+        && consistencyMode.equals(another.consistencyMode)\r
+        && isBlocking == another.isBlocking\r
+        && hasToken == another.hasToken;\r
+  }\r
+\r
+  /**\r
+   * Computes a hash code from attributes: {@code wait}, {@code token}, {@code index}, {@code near}, {@code consistencyMode}, {@code isBlocking}, {@code hasToken}.\r
+   * @return hashCode value\r
+   */\r
+  @Override\r
+  public int hashCode() {\r
+    int h = 31;\r
+    h = h * 17 + wait.hashCode();\r
+    h = h * 17 + token.hashCode();\r
+    h = h * 17 + index.hashCode();\r
+    h = h * 17 + near.hashCode();\r
+    h = h * 17 + consistencyMode.hashCode();\r
+    h = h * 17 + Booleans.hashCode(isBlocking);\r
+    h = h * 17 + Booleans.hashCode(hasToken);\r
+    return h;\r
+  }\r
+\r
+  /**\r
+   * Prints the immutable value {@code QueryOptions...} 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("QueryOptions")\r
+        .add("wait", wait)\r
+        .add("token", token)\r
+        .add("index", index)\r
+        .add("near", near)\r
+        .add("consistencyMode", consistencyMode)\r
+        .add("isBlocking", isBlocking)\r
+        .add("hasToken", hasToken)\r
+        .toString();\r
+  }\r
+\r
+  private static ImmutableQueryOptions validate(ImmutableQueryOptions instance) {\r
+    instance.validate();\r
+    return instance;\r
+  }\r
+\r
+  /**\r
+   * Creates an immutable copy of a {@link QueryOptions} 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 QueryOptions instance\r
+   */\r
+  public static ImmutableQueryOptions copyOf(QueryOptions instance) {\r
+    if (instance instanceof ImmutableQueryOptions) {\r
+      return (ImmutableQueryOptions) instance;\r
+    }\r
+    return ImmutableQueryOptions.builder()\r
+        .from(instance)\r
+        .build();\r
+  }\r
+\r
+  /**\r
+   * Creates a builder for {@link ImmutableQueryOptions ImmutableQueryOptions}.\r
+   * @return A new ImmutableQueryOptions builder\r
+   */\r
+  public static ImmutableQueryOptions.Builder builder() {\r
+    return new ImmutableQueryOptions.Builder();\r
+  }\r
+\r
+  /**\r
+   * Builds instances of type {@link ImmutableQueryOptions ImmutableQueryOptions}.\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 Optional<String> wait = Optional.absent();\r
+    private Optional<String> token = Optional.absent();\r
+    private Optional<BigInteger> index = Optional.absent();\r
+    private Optional<String> near = Optional.absent();\r
+    private ConsistencyMode consistencyMode;\r
+\r
+    private Builder() {\r
+    }\r
+\r
+    /**\r
+     * Fill a builder with attribute values from the provided {@code QueryOptions} 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(QueryOptions instance) {\r
+      Preconditions.checkNotNull(instance, "instance");\r
+      Optional<String> waitOptional = instance.getWait();\r
+      if (waitOptional.isPresent()) {\r
+        wait(waitOptional);\r
+      }\r
+      Optional<String> tokenOptional = instance.getToken();\r
+      if (tokenOptional.isPresent()) {\r
+        token(tokenOptional);\r
+      }\r
+      Optional<BigInteger> indexOptional = instance.getIndex();\r
+      if (indexOptional.isPresent()) {\r
+        index(indexOptional);\r
+      }\r
+      Optional<String> nearOptional = instance.getNear();\r
+      if (nearOptional.isPresent()) {\r
+        near(nearOptional);\r
+      }\r
+      consistencyMode(instance.getConsistencyMode());\r
+      return this;\r
+    }\r
+\r
+    /**\r
+     * Initializes the optional value {@link QueryOptions#getWait() wait} to wait.\r
+     * @param wait The value for wait\r
+     * @return {@code this} builder for chained invocation\r
+     */\r
+    public final Builder wait(String wait) {\r
+      this.wait = Optional.of(wait);\r
+      return this;\r
+    }\r
+\r
+    /**\r
+     * Initializes the optional value {@link QueryOptions#getWait() wait} to wait.\r
+     * @param wait The value for wait\r
+     * @return {@code this} builder for use in a chained invocation\r
+     */\r
+    public final Builder wait(Optional<String> wait) {\r
+      this.wait = Preconditions.checkNotNull(wait, "wait");\r
+      return this;\r
+    }\r
+\r
+    /**\r
+     * Initializes the optional value {@link QueryOptions#getToken() token} to token.\r
+     * @param token The value for token\r
+     * @return {@code this} builder for chained invocation\r
+     */\r
+    public final Builder token(String token) {\r
+      this.token = Optional.of(token);\r
+      return this;\r
+    }\r
+\r
+    /**\r
+     * Initializes the optional value {@link QueryOptions#getToken() token} to token.\r
+     * @param token The value for token\r
+     * @return {@code this} builder for use in a chained invocation\r
+     */\r
+    public final Builder token(Optional<String> token) {\r
+      this.token = Preconditions.checkNotNull(token, "token");\r
+      return this;\r
+    }\r
+\r
+    /**\r
+     * Initializes the optional value {@link QueryOptions#getIndex() index} to index.\r
+     * @param index The value for index\r
+     * @return {@code this} builder for chained invocation\r
+     */\r
+    public final Builder index(BigInteger index) {\r
+      this.index = Optional.of(index);\r
+      return this;\r
+    }\r
+\r
+    /**\r
+     * Initializes the optional value {@link QueryOptions#getIndex() index} to index.\r
+     * @param index The value for index\r
+     * @return {@code this} builder for use in a chained invocation\r
+     */\r
+    public final Builder index(Optional<BigInteger> index) {\r
+      this.index = Preconditions.checkNotNull(index, "index");\r
+      return this;\r
+    }\r
+\r
+    /**\r
+     * Initializes the optional value {@link QueryOptions#getNear() near} to near.\r
+     * @param near The value for near\r
+     * @return {@code this} builder for chained invocation\r
+     */\r
+    public final Builder near(String near) {\r
+      this.near = Optional.of(near);\r
+      return this;\r
+    }\r
+\r
+    /**\r
+     * Initializes the optional value {@link QueryOptions#getNear() near} to near.\r
+     * @param near The value for near\r
+     * @return {@code this} builder for use in a chained invocation\r
+     */\r
+    public final Builder near(Optional<String> near) {\r
+      this.near = Preconditions.checkNotNull(near, "near");\r
+      return this;\r
+    }\r
+\r
+    /**\r
+     * Initializes the value for the {@link QueryOptions#getConsistencyMode() consistencyMode} attribute.\r
+     * <p><em>If not set, this attribute will have a default value as returned by the initializer of {@link QueryOptions#getConsistencyMode() consistencyMode}.</em>\r
+     * @param consistencyMode The value for consistencyMode \r
+     * @return {@code this} builder for use in a chained invocation\r
+     */\r
+    public final Builder consistencyMode(ConsistencyMode consistencyMode) {\r
+      this.consistencyMode = Preconditions.checkNotNull(consistencyMode, "consistencyMode");\r
+      return this;\r
+    }\r
+\r
+    /**\r
+     * Builds a new {@link ImmutableQueryOptions ImmutableQueryOptions}.\r
+     * @return An immutable instance of QueryOptions\r
+     * @throws java.lang.IllegalStateException if any required attributes are missing\r
+     */\r
+    public ImmutableQueryOptions build() throws IllegalStateException {\r
+      return ImmutableQueryOptions.validate(new ImmutableQueryOptions(this));\r
+    }\r
+  }\r
+}\r