2 * Copyright (C) 2016 ZTE, Inc. and others. All rights reserved. (ZTE)
\r
4 * Licensed under the Apache License, Version 2.0 (the "License");
\r
5 * you may not use this file except in compliance with the License.
\r
6 * You may obtain a copy of the License at
\r
8 * http://www.apache.org/licenses/LICENSE-2.0
\r
10 * Unless required by applicable law or agreed to in writing, software
\r
11 * distributed under the License is distributed on an "AS IS" BASIS,
\r
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
\r
13 * See the License for the specific language governing permissions and
\r
14 * limitations under the License.
\r
17 package org.openo.msb.wrapper.consul.option;
\r
19 import com.google.common.base.MoreObjects;
\r
20 import com.google.common.base.Optional;
\r
21 import com.google.common.base.Preconditions;
\r
22 import javax.annotation.Generated;
\r
25 * Immutable implementation of {@link CatalogOptions}.
\r
27 * Use the builder to create immutable instances:
\r
28 * {@code ImmutableCatalogOptions.builder()}.
\r
30 @SuppressWarnings("all")
\r
31 @Generated({"Immutables.generator", "CatalogOptions"})
\r
32 public final class ImmutableCatalogOptions extends CatalogOptions {
\r
33 private final Optional<String> datacenter;
\r
34 private final Optional<String> tag;
\r
36 private ImmutableCatalogOptions(
\r
37 Optional<String> datacenter,
\r
38 Optional<String> tag) {
\r
39 this.datacenter = datacenter;
\r
44 * @return The value of the {@code datacenter} attribute
\r
47 public Optional<String> getDatacenter() {
\r
52 * @return The value of the {@code tag} attribute
\r
55 public Optional<String> getTag() {
\r
60 * Copy the current immutable object by setting a <i>present</i> value for the optional {@link CatalogOptions#getDatacenter() datacenter} attribute.
\r
61 * @param value The value for datacenter
\r
62 * @return A modified copy of {@code this} object
\r
64 public final ImmutableCatalogOptions withDatacenter(String value) {
\r
65 Optional<String> newValue = Optional.of(value);
\r
66 return new ImmutableCatalogOptions(newValue, this.tag);
\r
70 * Copy the current immutable object by setting an optional value for the {@link CatalogOptions#getDatacenter() datacenter} attribute.
\r
71 * A shallow reference equality check on the optional value is used to prevent copying of the same value by returning {@code this}.
\r
72 * @param optional A value for datacenter
\r
73 * @return A modified copy of {@code this} object
\r
75 public final ImmutableCatalogOptions withDatacenter(Optional<String> optional) {
\r
76 Optional<String> value = Preconditions.checkNotNull(optional, "datacenter");
\r
77 if (this.datacenter == value) return this;
\r
78 return new ImmutableCatalogOptions(value, this.tag);
\r
82 * Copy the current immutable object by setting a <i>present</i> value for the optional {@link CatalogOptions#getTag() tag} attribute.
\r
83 * @param value The value for tag
\r
84 * @return A modified copy of {@code this} object
\r
86 public final ImmutableCatalogOptions withTag(String value) {
\r
87 Optional<String> newValue = Optional.of(value);
\r
88 return new ImmutableCatalogOptions(this.datacenter, newValue);
\r
92 * Copy the current immutable object by setting an optional value for the {@link CatalogOptions#getTag() tag} attribute.
\r
93 * A shallow reference equality check on the optional value is used to prevent copying of the same value by returning {@code this}.
\r
94 * @param optional A value for tag
\r
95 * @return A modified copy of {@code this} object
\r
97 public final ImmutableCatalogOptions withTag(Optional<String> optional) {
\r
98 Optional<String> value = Preconditions.checkNotNull(optional, "tag");
\r
99 if (this.tag == value) return this;
\r
100 return new ImmutableCatalogOptions(this.datacenter, value);
\r
104 * This instance is equal to all instances of {@code ImmutableCatalogOptions} that have equal attribute values.
\r
105 * @return {@code true} if {@code this} is equal to {@code another} instance
\r
108 public boolean equals(Object another) {
\r
109 if (this == another) return true;
\r
110 return another instanceof ImmutableCatalogOptions
\r
111 && equalTo((ImmutableCatalogOptions) another);
\r
114 private boolean equalTo(ImmutableCatalogOptions another) {
\r
115 return datacenter.equals(another.datacenter)
\r
116 && tag.equals(another.tag);
\r
120 * Computes a hash code from attributes: {@code datacenter}, {@code tag}.
\r
121 * @return hashCode value
\r
124 public int hashCode() {
\r
126 h = h * 17 + datacenter.hashCode();
\r
127 h = h * 17 + tag.hashCode();
\r
132 * Prints the immutable value {@code CatalogOptions...} with all non-generated
\r
133 * and non-auxiliary attribute values.
\r
134 * @return A string representation of the value
\r
137 public String toString() {
\r
138 return MoreObjects.toStringHelper("CatalogOptions")
\r
139 .add("datacenter", datacenter)
\r
145 * Creates an immutable copy of a {@link CatalogOptions} value.
\r
146 * Uses accessors to get values to initialize the new immutable instance.
\r
147 * If an instance is already immutable, it is returned as is.
\r
148 * @param instance The instance to copy
\r
149 * @return A copied immutable CatalogOptions instance
\r
151 public static ImmutableCatalogOptions copyOf(CatalogOptions instance) {
\r
152 if (instance instanceof ImmutableCatalogOptions) {
\r
153 return (ImmutableCatalogOptions) instance;
\r
155 return ImmutableCatalogOptions.builder()
\r
161 * Creates a builder for {@link ImmutableCatalogOptions ImmutableCatalogOptions}.
\r
162 * @return A new ImmutableCatalogOptions builder
\r
164 public static ImmutableCatalogOptions.Builder builder() {
\r
165 return new ImmutableCatalogOptions.Builder();
\r
169 * Builds instances of type {@link ImmutableCatalogOptions ImmutableCatalogOptions}.
\r
170 * Initialize attributes and then invoke the {@link #build()} method to create an
\r
171 * immutable instance.
\r
172 * <p><em>{@code Builder} is not thread-safe and generally should not be stored in a field or collection,
\r
173 * but instead used immediately to create instances.</em>
\r
175 public static final class Builder {
\r
176 private Optional<String> datacenter = Optional.absent();
\r
177 private Optional<String> tag = Optional.absent();
\r
179 private Builder() {
\r
183 * Fill a builder with attribute values from the provided {@code CatalogOptions} instance.
\r
184 * Regular attribute values will be replaced with those from the given instance.
\r
185 * Absent optional values will not replace present values.
\r
186 * @param instance The instance from which to copy values
\r
187 * @return {@code this} builder for use in a chained invocation
\r
189 public final Builder from(CatalogOptions instance) {
\r
190 Preconditions.checkNotNull(instance, "instance");
\r
191 Optional<String> datacenterOptional = instance.getDatacenter();
\r
192 if (datacenterOptional.isPresent()) {
\r
193 datacenter(datacenterOptional);
\r
195 Optional<String> tagOptional = instance.getTag();
\r
196 if (tagOptional.isPresent()) {
\r
203 * Initializes the optional value {@link CatalogOptions#getDatacenter() datacenter} to datacenter.
\r
204 * @param datacenter The value for datacenter
\r
205 * @return {@code this} builder for chained invocation
\r
207 public final Builder datacenter(String datacenter) {
\r
208 this.datacenter = Optional.of(datacenter);
\r
213 * Initializes the optional value {@link CatalogOptions#getDatacenter() datacenter} to datacenter.
\r
214 * @param datacenter The value for datacenter
\r
215 * @return {@code this} builder for use in a chained invocation
\r
217 public final Builder datacenter(Optional<String> datacenter) {
\r
218 this.datacenter = Preconditions.checkNotNull(datacenter, "datacenter");
\r
223 * Initializes the optional value {@link CatalogOptions#getTag() tag} to tag.
\r
224 * @param tag The value for tag
\r
225 * @return {@code this} builder for chained invocation
\r
227 public final Builder tag(String tag) {
\r
228 this.tag = Optional.of(tag);
\r
233 * Initializes the optional value {@link CatalogOptions#getTag() tag} to tag.
\r
234 * @param tag The value for tag
\r
235 * @return {@code this} builder for use in a chained invocation
\r
237 public final Builder tag(Optional<String> tag) {
\r
238 this.tag = Preconditions.checkNotNull(tag, "tag");
\r
243 * Builds a new {@link ImmutableCatalogOptions ImmutableCatalogOptions}.
\r
244 * @return An immutable instance of CatalogOptions
\r
245 * @throws java.lang.IllegalStateException if any required attributes are missing
\r
247 public ImmutableCatalogOptions build() throws IllegalStateException {
\r
248 return new ImmutableCatalogOptions(datacenter, tag);
\r