2 * Copyright 2016-2017 ZTE, Inc. and others.
4 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
5 * in compliance with the License. You may obtain a copy of the License at
7 * http://www.apache.org/licenses/LICENSE-2.0
9 * Unless required by applicable law or agreed to in writing, software distributed under the License
10 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
11 * or implied. See the License for the specific language governing permissions and limitations under
14 package org.onap.msb.sdclient.wrapper.consul.option;
16 import javax.annotation.Generated;
18 import com.google.common.base.MoreObjects;
19 import com.google.common.base.Optional;
20 import com.google.common.base.Preconditions;
23 * Immutable implementation of {@link CatalogOptions}.
25 * Use the builder to create immutable instances: {@code ImmutableCatalogOptions.builder()}.
27 @SuppressWarnings("all")
28 @Generated({"Immutables.generator", "CatalogOptions"})
29 public final class ImmutableCatalogOptions extends CatalogOptions {
30 private final Optional<String> datacenter;
31 private final Optional<String> tag;
33 private ImmutableCatalogOptions(Optional<String> datacenter, Optional<String> tag) {
34 this.datacenter = datacenter;
39 * @return The value of the {@code datacenter} attribute
42 public Optional<String> getDatacenter() {
47 * @return The value of the {@code tag} attribute
50 public Optional<String> getTag() {
55 * Copy the current immutable object by setting a <i>present</i> value for the optional
56 * {@link CatalogOptions#getDatacenter() datacenter} attribute.
58 * @param value The value for datacenter
59 * @return A modified copy of {@code this} object
61 public final ImmutableCatalogOptions withDatacenter(String value) {
62 Optional<String> newValue = Optional.of(value);
63 return new ImmutableCatalogOptions(newValue, this.tag);
67 * Copy the current immutable object by setting an optional value for the
68 * {@link CatalogOptions#getDatacenter() datacenter} attribute. A shallow reference equality
69 * check on the optional value is used to prevent copying of the same value by returning
72 * @param optional A value for datacenter
73 * @return A modified copy of {@code this} object
75 public final ImmutableCatalogOptions withDatacenter(Optional<String> optional) {
76 Optional<String> value = Preconditions.checkNotNull(optional, "datacenter");
77 if (this.datacenter == value)
79 return new ImmutableCatalogOptions(value, this.tag);
83 * Copy the current immutable object by setting a <i>present</i> value for the optional
84 * {@link CatalogOptions#getTag() tag} attribute.
86 * @param value The value for tag
87 * @return A modified copy of {@code this} object
89 public final ImmutableCatalogOptions withTag(String value) {
90 Optional<String> newValue = Optional.of(value);
91 return new ImmutableCatalogOptions(this.datacenter, newValue);
95 * Copy the current immutable object by setting an optional value for the
96 * {@link CatalogOptions#getTag() tag} attribute. A shallow reference equality check on the
97 * optional value is used to prevent copying of the same value by returning {@code this}.
99 * @param optional A value for tag
100 * @return A modified copy of {@code this} object
102 public final ImmutableCatalogOptions withTag(Optional<String> optional) {
103 Optional<String> value = Preconditions.checkNotNull(optional, "tag");
104 if (this.tag == value)
106 return new ImmutableCatalogOptions(this.datacenter, value);
110 * This instance is equal to all instances of {@code ImmutableCatalogOptions} that have equal
113 * @return {@code true} if {@code this} is equal to {@code another} instance
116 public boolean equals(Object another) {
119 return another instanceof ImmutableCatalogOptions && equalTo((ImmutableCatalogOptions) another);
122 private boolean equalTo(ImmutableCatalogOptions another) {
123 return datacenter.equals(another.datacenter) && tag.equals(another.tag);
127 * Computes a hash code from attributes: {@code datacenter}, {@code tag}.
129 * @return hashCode value
132 public int hashCode() {
134 h = h * 17 + datacenter.hashCode();
135 h = h * 17 + tag.hashCode();
140 * Prints the immutable value {@code CatalogOptions...} with all non-generated and non-auxiliary
143 * @return A string representation of the value
146 public String toString() {
147 return MoreObjects.toStringHelper("CatalogOptions").add("datacenter", datacenter).add("tag", tag).toString();
151 * Creates an immutable copy of a {@link CatalogOptions} value. Uses accessors to get values to
152 * initialize the new immutable instance. If an instance is already immutable, it is returned as
155 * @param instance The instance to copy
156 * @return A copied immutable CatalogOptions instance
158 public static ImmutableCatalogOptions copyOf(CatalogOptions instance) {
159 if (instance instanceof ImmutableCatalogOptions) {
160 return (ImmutableCatalogOptions) instance;
162 return ImmutableCatalogOptions.builder().from(instance).build();
166 * Creates a builder for {@link ImmutableCatalogOptions ImmutableCatalogOptions}.
168 * @return A new ImmutableCatalogOptions builder
170 public static ImmutableCatalogOptions.Builder builder() {
171 return new ImmutableCatalogOptions.Builder();
175 * Builds instances of type {@link ImmutableCatalogOptions ImmutableCatalogOptions}. Initialize
176 * attributes and then invoke the {@link #build()} method to create an immutable instance.
178 * <em>{@code Builder} is not thread-safe and generally should not be stored in a field or
179 * collection, but instead used immediately to create instances.</em>
181 public static final class Builder {
182 private Optional<String> datacenter = Optional.absent();
183 private Optional<String> tag = Optional.absent();
188 * Fill a builder with attribute values from the provided {@code CatalogOptions} instance.
189 * Regular attribute values will be replaced with those from the given instance. Absent
190 * optional values will not replace present values.
192 * @param instance The instance from which to copy values
193 * @return {@code this} builder for use in a chained invocation
195 public final Builder from(CatalogOptions instance) {
196 Preconditions.checkNotNull(instance, "instance");
197 Optional<String> datacenterOptional = instance.getDatacenter();
198 if (datacenterOptional.isPresent()) {
199 datacenter(datacenterOptional);
201 Optional<String> tagOptional = instance.getTag();
202 if (tagOptional.isPresent()) {
209 * Initializes the optional value {@link CatalogOptions#getDatacenter() datacenter} to
212 * @param datacenter The value for datacenter
213 * @return {@code this} builder for chained invocation
215 public final Builder datacenter(String datacenter) {
216 this.datacenter = Optional.of(datacenter);
221 * Initializes the optional value {@link CatalogOptions#getDatacenter() datacenter} to
224 * @param datacenter The value for datacenter
225 * @return {@code this} builder for use in a chained invocation
227 public final Builder datacenter(Optional<String> datacenter) {
228 this.datacenter = Preconditions.checkNotNull(datacenter, "datacenter");
233 * Initializes the optional value {@link CatalogOptions#getTag() tag} to tag.
235 * @param tag The value for tag
236 * @return {@code this} builder for chained invocation
238 public final Builder tag(String tag) {
239 this.tag = Optional.of(tag);
244 * Initializes the optional value {@link CatalogOptions#getTag() tag} to tag.
246 * @param tag The value for tag
247 * @return {@code this} builder for use in a chained invocation
249 public final Builder tag(Optional<String> tag) {
250 this.tag = Preconditions.checkNotNull(tag, "tag");
255 * Builds a new {@link ImmutableCatalogOptions ImmutableCatalogOptions}.
257 * @return An immutable instance of CatalogOptions
258 * @throws java.lang.IllegalStateException if any required attributes are missing
260 public ImmutableCatalogOptions build() throws IllegalStateException {
261 return new ImmutableCatalogOptions(datacenter, tag);