2 * Copyright 2016 2015-2016 ZTE, Inc. and others. All rights reserved.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 package org.openo.msb.wrapper.consul.option;
18 import com.google.common.base.MoreObjects;
19 import com.google.common.base.Optional;
20 import com.google.common.base.Preconditions;
21 import javax.annotation.Generated;
24 * Immutable implementation of {@link CatalogOptions}.
26 * Use the builder to create immutable instances:
27 * {@code ImmutableCatalogOptions.builder()}.
29 @SuppressWarnings("all")
30 @Generated({"Immutables.generator", "CatalogOptions"})
31 public final class ImmutableCatalogOptions extends CatalogOptions {
32 private final Optional<String> datacenter;
33 private final Optional<String> tag;
35 private ImmutableCatalogOptions(
36 Optional<String> datacenter,
37 Optional<String> tag) {
38 this.datacenter = datacenter;
43 * @return The value of the {@code datacenter} attribute
46 public Optional<String> getDatacenter() {
51 * @return The value of the {@code tag} attribute
54 public Optional<String> getTag() {
59 * Copy the current immutable object by setting a <i>present</i> value for the optional {@link CatalogOptions#getDatacenter() datacenter} attribute.
60 * @param value The value for datacenter
61 * @return A modified copy of {@code this} object
63 public final ImmutableCatalogOptions withDatacenter(String value) {
64 Optional<String> newValue = Optional.of(value);
65 return new ImmutableCatalogOptions(newValue, this.tag);
69 * Copy the current immutable object by setting an optional value for the {@link CatalogOptions#getDatacenter() datacenter} attribute.
70 * A shallow reference equality check on the optional value is used to prevent copying of the same value by returning {@code this}.
71 * @param optional A value for datacenter
72 * @return A modified copy of {@code this} object
74 public final ImmutableCatalogOptions withDatacenter(Optional<String> optional) {
75 Optional<String> value = Preconditions.checkNotNull(optional, "datacenter");
76 if (this.datacenter == value) return this;
77 return new ImmutableCatalogOptions(value, this.tag);
81 * Copy the current immutable object by setting a <i>present</i> value for the optional {@link CatalogOptions#getTag() tag} attribute.
82 * @param value The value for tag
83 * @return A modified copy of {@code this} object
85 public final ImmutableCatalogOptions withTag(String value) {
86 Optional<String> newValue = Optional.of(value);
87 return new ImmutableCatalogOptions(this.datacenter, newValue);
91 * Copy the current immutable object by setting an optional value for the {@link CatalogOptions#getTag() tag} attribute.
92 * A shallow reference equality check on the optional value is used to prevent copying of the same value by returning {@code this}.
93 * @param optional A value for tag
94 * @return A modified copy of {@code this} object
96 public final ImmutableCatalogOptions withTag(Optional<String> optional) {
97 Optional<String> value = Preconditions.checkNotNull(optional, "tag");
98 if (this.tag == value) return this;
99 return new ImmutableCatalogOptions(this.datacenter, value);
103 * This instance is equal to all instances of {@code ImmutableCatalogOptions} that have equal attribute values.
104 * @return {@code true} if {@code this} is equal to {@code another} instance
107 public boolean equals(Object another) {
108 if (this == another) return true;
109 return another instanceof ImmutableCatalogOptions
110 && equalTo((ImmutableCatalogOptions) another);
113 private boolean equalTo(ImmutableCatalogOptions another) {
114 return datacenter.equals(another.datacenter)
115 && tag.equals(another.tag);
119 * Computes a hash code from attributes: {@code datacenter}, {@code tag}.
120 * @return hashCode value
123 public int hashCode() {
125 h = h * 17 + datacenter.hashCode();
126 h = h * 17 + tag.hashCode();
131 * Prints the immutable value {@code CatalogOptions...} with all non-generated
132 * and non-auxiliary attribute values.
133 * @return A string representation of the value
136 public String toString() {
137 return MoreObjects.toStringHelper("CatalogOptions")
138 .add("datacenter", datacenter)
144 * Creates an immutable copy of a {@link CatalogOptions} value.
145 * Uses accessors to get values to initialize the new immutable instance.
146 * If an instance is already immutable, it is returned as is.
147 * @param instance The instance to copy
148 * @return A copied immutable CatalogOptions instance
150 public static ImmutableCatalogOptions copyOf(CatalogOptions instance) {
151 if (instance instanceof ImmutableCatalogOptions) {
152 return (ImmutableCatalogOptions) instance;
154 return ImmutableCatalogOptions.builder()
160 * Creates a builder for {@link ImmutableCatalogOptions ImmutableCatalogOptions}.
161 * @return A new ImmutableCatalogOptions builder
163 public static ImmutableCatalogOptions.Builder builder() {
164 return new ImmutableCatalogOptions.Builder();
168 * Builds instances of type {@link ImmutableCatalogOptions ImmutableCatalogOptions}.
169 * Initialize attributes and then invoke the {@link #build()} method to create an
170 * immutable instance.
171 * <p><em>{@code Builder} is not thread-safe and generally should not be stored in a field or collection,
172 * but instead used immediately to create instances.</em>
174 public static final class Builder {
175 private Optional<String> datacenter = Optional.absent();
176 private Optional<String> tag = Optional.absent();
182 * Fill a builder with attribute values from the provided {@code CatalogOptions} instance.
183 * Regular attribute values will be replaced with those from the given instance.
184 * Absent optional values will not replace present values.
185 * @param instance The instance from which to copy values
186 * @return {@code this} builder for use in a chained invocation
188 public final Builder from(CatalogOptions instance) {
189 Preconditions.checkNotNull(instance, "instance");
190 Optional<String> datacenterOptional = instance.getDatacenter();
191 if (datacenterOptional.isPresent()) {
192 datacenter(datacenterOptional);
194 Optional<String> tagOptional = instance.getTag();
195 if (tagOptional.isPresent()) {
202 * Initializes the optional value {@link CatalogOptions#getDatacenter() datacenter} to datacenter.
203 * @param datacenter The value for datacenter
204 * @return {@code this} builder for chained invocation
206 public final Builder datacenter(String datacenter) {
207 this.datacenter = Optional.of(datacenter);
212 * Initializes the optional value {@link CatalogOptions#getDatacenter() datacenter} to datacenter.
213 * @param datacenter The value for datacenter
214 * @return {@code this} builder for use in a chained invocation
216 public final Builder datacenter(Optional<String> datacenter) {
217 this.datacenter = Preconditions.checkNotNull(datacenter, "datacenter");
222 * Initializes the optional value {@link CatalogOptions#getTag() tag} to tag.
223 * @param tag The value for tag
224 * @return {@code this} builder for chained invocation
226 public final Builder tag(String tag) {
227 this.tag = Optional.of(tag);
232 * Initializes the optional value {@link CatalogOptions#getTag() tag} to tag.
233 * @param tag The value for tag
234 * @return {@code this} builder for use in a chained invocation
236 public final Builder tag(Optional<String> tag) {
237 this.tag = Preconditions.checkNotNull(tag, "tag");
242 * Builds a new {@link ImmutableCatalogOptions ImmutableCatalogOptions}.
243 * @return An immutable instance of CatalogOptions
244 * @throws java.lang.IllegalStateException if any required attributes are missing
246 public ImmutableCatalogOptions build() throws IllegalStateException {
247 return new ImmutableCatalogOptions(datacenter, tag);