Fix java check style issue
[msb/discovery.git] / sdclient / discovery-service / src / main / java / org / onap / msb / sdclient / wrapper / consul / option / ImmutableCatalogOptions.java
1 /**
2  * Copyright 2016-2017 ZTE, Inc. and others.
3  *
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
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
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
12  * the License.
13  */
14 package org.onap.msb.sdclient.wrapper.consul.option;
15
16 import javax.annotation.Generated;
17
18 import com.google.common.base.MoreObjects;
19 import com.google.common.base.Optional;
20 import com.google.common.base.Preconditions;
21
22 /**
23  * Immutable implementation of {@link CatalogOptions}.
24  * <p>
25  * Use the builder to create immutable instances: {@code ImmutableCatalogOptions.builder()}.
26  */
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;
32
33     private ImmutableCatalogOptions(Optional<String> datacenter, Optional<String> tag) {
34         this.datacenter = datacenter;
35         this.tag = tag;
36     }
37
38     /**
39      * @return The value of the {@code datacenter} attribute
40      */
41     @Override
42     public Optional<String> getDatacenter() {
43         return datacenter;
44     }
45
46     /**
47      * @return The value of the {@code tag} attribute
48      */
49     @Override
50     public Optional<String> getTag() {
51         return tag;
52     }
53
54     /**
55      * Copy the current immutable object by setting a <i>present</i> value for the optional
56      * {@link CatalogOptions#getDatacenter() datacenter} attribute.
57      * 
58      * @param value The value for datacenter
59      * @return A modified copy of {@code this} object
60      */
61     public final ImmutableCatalogOptions withDatacenter(String value) {
62         Optional<String> newValue = Optional.of(value);
63         return new ImmutableCatalogOptions(newValue, this.tag);
64     }
65
66     /**
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
70      * {@code this}.
71      * 
72      * @param optional A value for datacenter
73      * @return A modified copy of {@code this} object
74      */
75     public final ImmutableCatalogOptions withDatacenter(Optional<String> optional) {
76         Optional<String> value = Preconditions.checkNotNull(optional, "datacenter");
77         if (this.datacenter == value)
78             return this;
79         return new ImmutableCatalogOptions(value, this.tag);
80     }
81
82     /**
83      * Copy the current immutable object by setting a <i>present</i> value for the optional
84      * {@link CatalogOptions#getTag() tag} attribute.
85      * 
86      * @param value The value for tag
87      * @return A modified copy of {@code this} object
88      */
89     public final ImmutableCatalogOptions withTag(String value) {
90         Optional<String> newValue = Optional.of(value);
91         return new ImmutableCatalogOptions(this.datacenter, newValue);
92     }
93
94     /**
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}.
98      * 
99      * @param optional A value for tag
100      * @return A modified copy of {@code this} object
101      */
102     public final ImmutableCatalogOptions withTag(Optional<String> optional) {
103         Optional<String> value = Preconditions.checkNotNull(optional, "tag");
104         if (this.tag == value)
105             return this;
106         return new ImmutableCatalogOptions(this.datacenter, value);
107     }
108
109     /**
110      * This instance is equal to all instances of {@code ImmutableCatalogOptions} that have equal
111      * attribute values.
112      * 
113      * @return {@code true} if {@code this} is equal to {@code another} instance
114      */
115     @Override
116     public boolean equals(Object another) {
117         if (this == another)
118             return true;
119         return another instanceof ImmutableCatalogOptions && equalTo((ImmutableCatalogOptions) another);
120     }
121
122     private boolean equalTo(ImmutableCatalogOptions another) {
123         return datacenter.equals(another.datacenter) && tag.equals(another.tag);
124     }
125
126     /**
127      * Computes a hash code from attributes: {@code datacenter}, {@code tag}.
128      * 
129      * @return hashCode value
130      */
131     @Override
132     public int hashCode() {
133         int h = 31;
134         h = h * 17 + datacenter.hashCode();
135         h = h * 17 + tag.hashCode();
136         return h;
137     }
138
139     /**
140      * Prints the immutable value {@code CatalogOptions...} with all non-generated and non-auxiliary
141      * attribute values.
142      * 
143      * @return A string representation of the value
144      */
145     @Override
146     public String toString() {
147         return MoreObjects.toStringHelper("CatalogOptions").add("datacenter", datacenter).add("tag", tag).toString();
148     }
149
150     /**
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
153      * is.
154      * 
155      * @param instance The instance to copy
156      * @return A copied immutable CatalogOptions instance
157      */
158     public static ImmutableCatalogOptions copyOf(CatalogOptions instance) {
159         if (instance instanceof ImmutableCatalogOptions) {
160             return (ImmutableCatalogOptions) instance;
161         }
162         return ImmutableCatalogOptions.builder().from(instance).build();
163     }
164
165     /**
166      * Creates a builder for {@link ImmutableCatalogOptions ImmutableCatalogOptions}.
167      * 
168      * @return A new ImmutableCatalogOptions builder
169      */
170     public static ImmutableCatalogOptions.Builder builder() {
171         return new ImmutableCatalogOptions.Builder();
172     }
173
174     /**
175      * Builds instances of type {@link ImmutableCatalogOptions ImmutableCatalogOptions}. Initialize
176      * attributes and then invoke the {@link #build()} method to create an immutable instance.
177      * <p>
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>
180      */
181     public static final class Builder {
182         private Optional<String> datacenter = Optional.absent();
183         private Optional<String> tag = Optional.absent();
184
185         private Builder() {}
186
187         /**
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.
191          * 
192          * @param instance The instance from which to copy values
193          * @return {@code this} builder for use in a chained invocation
194          */
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);
200             }
201             Optional<String> tagOptional = instance.getTag();
202             if (tagOptional.isPresent()) {
203                 tag(tagOptional);
204             }
205             return this;
206         }
207
208         /**
209          * Initializes the optional value {@link CatalogOptions#getDatacenter() datacenter} to
210          * datacenter.
211          * 
212          * @param datacenter The value for datacenter
213          * @return {@code this} builder for chained invocation
214          */
215         public final Builder datacenter(String datacenter) {
216             this.datacenter = Optional.of(datacenter);
217             return this;
218         }
219
220         /**
221          * Initializes the optional value {@link CatalogOptions#getDatacenter() datacenter} to
222          * datacenter.
223          * 
224          * @param datacenter The value for datacenter
225          * @return {@code this} builder for use in a chained invocation
226          */
227         public final Builder datacenter(Optional<String> datacenter) {
228             this.datacenter = Preconditions.checkNotNull(datacenter, "datacenter");
229             return this;
230         }
231
232         /**
233          * Initializes the optional value {@link CatalogOptions#getTag() tag} to tag.
234          * 
235          * @param tag The value for tag
236          * @return {@code this} builder for chained invocation
237          */
238         public final Builder tag(String tag) {
239             this.tag = Optional.of(tag);
240             return this;
241         }
242
243         /**
244          * Initializes the optional value {@link CatalogOptions#getTag() tag} to tag.
245          * 
246          * @param tag The value for tag
247          * @return {@code this} builder for use in a chained invocation
248          */
249         public final Builder tag(Optional<String> tag) {
250             this.tag = Preconditions.checkNotNull(tag, "tag");
251             return this;
252         }
253
254         /**
255          * Builds a new {@link ImmutableCatalogOptions ImmutableCatalogOptions}.
256          * 
257          * @return An immutable instance of CatalogOptions
258          * @throws java.lang.IllegalStateException if any required attributes are missing
259          */
260         public ImmutableCatalogOptions build() throws IllegalStateException {
261             return new ImmutableCatalogOptions(datacenter, tag);
262         }
263     }
264 }