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