Issue-id: OCS-9
[msb/apigateway.git] / msb-core / apiroute / apiroute-service / src / main / java / org / openo / msb / wrapper / consul / option / ImmutableCatalogOptions.java
1 /**
2  * Copyright 2016 2015-2016 ZTE, Inc. and others. All rights reserved.
3  *
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
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16 package org.openo.msb.wrapper.consul.option;
17
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;
22
23 /**
24  * Immutable implementation of {@link CatalogOptions}.
25  * <p>
26  * Use the builder to create immutable instances:
27  * {@code ImmutableCatalogOptions.builder()}.
28  */
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;
34
35   private ImmutableCatalogOptions(
36       Optional<String> datacenter,
37       Optional<String> tag) {
38     this.datacenter = datacenter;
39     this.tag = tag;
40   }
41
42   /**
43    * @return The value of the {@code datacenter} attribute
44    */
45   @Override
46   public Optional<String> getDatacenter() {
47     return datacenter;
48   }
49
50   /**
51    * @return The value of the {@code tag} attribute
52    */
53   @Override
54   public Optional<String> getTag() {
55     return tag;
56   }
57
58   /**
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
62    */
63   public final ImmutableCatalogOptions withDatacenter(String value) {
64     Optional<String> newValue = Optional.of(value);
65     return new ImmutableCatalogOptions(newValue, this.tag);
66   }
67
68   /**
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
73    */
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);
78   }
79
80   /**
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
84    */
85   public final ImmutableCatalogOptions withTag(String value) {
86     Optional<String> newValue = Optional.of(value);
87     return new ImmutableCatalogOptions(this.datacenter, newValue);
88   }
89
90   /**
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
95    */
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);
100   }
101
102   /**
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
105    */
106   @Override
107   public boolean equals(Object another) {
108     if (this == another) return true;
109     return another instanceof ImmutableCatalogOptions
110         && equalTo((ImmutableCatalogOptions) another);
111   }
112
113   private boolean equalTo(ImmutableCatalogOptions another) {
114     return datacenter.equals(another.datacenter)
115         && tag.equals(another.tag);
116   }
117
118   /**
119    * Computes a hash code from attributes: {@code datacenter}, {@code tag}.
120    * @return hashCode value
121    */
122   @Override
123   public int hashCode() {
124     int h = 31;
125     h = h * 17 + datacenter.hashCode();
126     h = h * 17 + tag.hashCode();
127     return h;
128   }
129
130   /**
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
134    */
135   @Override
136   public String toString() {
137     return MoreObjects.toStringHelper("CatalogOptions")
138         .add("datacenter", datacenter)
139         .add("tag", tag)
140         .toString();
141   }
142
143   /**
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
149    */
150   public static ImmutableCatalogOptions copyOf(CatalogOptions instance) {
151     if (instance instanceof ImmutableCatalogOptions) {
152       return (ImmutableCatalogOptions) instance;
153     }
154     return ImmutableCatalogOptions.builder()
155         .from(instance)
156         .build();
157   }
158
159   /**
160    * Creates a builder for {@link ImmutableCatalogOptions ImmutableCatalogOptions}.
161    * @return A new ImmutableCatalogOptions builder
162    */
163   public static ImmutableCatalogOptions.Builder builder() {
164     return new ImmutableCatalogOptions.Builder();
165   }
166
167   /**
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>
173    */
174   public static final class Builder {
175     private Optional<String> datacenter = Optional.absent();
176     private Optional<String> tag = Optional.absent();
177
178     private Builder() {
179     }
180
181     /**
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
187      */
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);
193       }
194       Optional<String> tagOptional = instance.getTag();
195       if (tagOptional.isPresent()) {
196         tag(tagOptional);
197       }
198       return this;
199     }
200
201     /**
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
205      */
206     public final Builder datacenter(String datacenter) {
207       this.datacenter = Optional.of(datacenter);
208       return this;
209     }
210
211     /**
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
215      */
216     public final Builder datacenter(Optional<String> datacenter) {
217       this.datacenter = Preconditions.checkNotNull(datacenter, "datacenter");
218       return this;
219     }
220
221     /**
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
225      */
226     public final Builder tag(String tag) {
227       this.tag = Optional.of(tag);
228       return this;
229     }
230
231     /**
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
235      */
236     public final Builder tag(Optional<String> tag) {
237       this.tag = Preconditions.checkNotNull(tag, "tag");
238       return this;
239     }
240
241     /**
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
245      */
246     public ImmutableCatalogOptions build() throws IllegalStateException {
247       return new ImmutableCatalogOptions(datacenter, tag);
248     }
249   }
250 }