Issue-id: OCS-9
[msb/apigateway.git] / msb-core / apiroute / apiroute-service / src / main / java / org / openo / msb / wrapper / consul / model / catalog / ImmutableCatalogService.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.model.catalog;
17
18 import com.fasterxml.jackson.annotation.JsonCreator;
19 import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
20 import com.fasterxml.jackson.annotation.JsonProperty;
21 import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
22 import com.google.common.base.MoreObjects;
23 import com.google.common.base.Preconditions;
24 import com.google.common.collect.ImmutableList;
25 import com.google.common.collect.Lists;
26 import java.util.List;
27 import javax.annotation.Generated;
28
29 /**
30  * Immutable implementation of {@link CatalogService}.
31  * <p>
32  * Use the builder to create immutable instances:
33  * {@code ImmutableCatalogService.builder()}.
34  */
35 @SuppressWarnings("all")
36 @Generated({"Immutables.generator", "CatalogService"})
37 @JsonIgnoreProperties(ignoreUnknown = true)
38 public final class ImmutableCatalogService extends CatalogService {
39   private final String node;
40   private final String address;
41   private final String serviceName;
42   private final String serviceId;
43   private final String serviceAddress;
44   private final int servicePort;
45   private final ImmutableList<String> serviceTags;
46
47   private ImmutableCatalogService(
48       String node,
49       String address,
50       String serviceName,
51       String serviceId,
52       String serviceAddress,
53       int servicePort,
54       ImmutableList<String> serviceTags) {
55     this.node = node;
56     this.address = address;
57     this.serviceName = serviceName;
58     this.serviceId = serviceId;
59     this.serviceAddress = serviceAddress;
60     this.servicePort = servicePort;
61     this.serviceTags = serviceTags;
62   }
63
64   /**
65    * @return The value of the {@code node} attribute
66    */
67   @JsonProperty(value = "Node")
68   @Override
69   public String getNode() {
70     return node;
71   }
72
73   /**
74    * @return The value of the {@code address} attribute
75    */
76   @JsonProperty(value = "Address")
77   @Override
78   public String getAddress() {
79     return address;
80   }
81
82   /**
83    * @return The value of the {@code serviceName} attribute
84    */
85   @JsonProperty(value = "ServiceName")
86   @Override
87   public String getServiceName() {
88     return serviceName;
89   }
90
91   /**
92    * @return The value of the {@code serviceId} attribute
93    */
94   @JsonProperty(value = "ServiceID")
95   @Override
96   public String getServiceId() {
97     return serviceId;
98   }
99
100   /**
101    * @return The value of the {@code serviceAddress} attribute
102    */
103   @JsonProperty(value = "ServiceAddress")
104   @Override
105   public String getServiceAddress() {
106     return serviceAddress;
107   }
108
109   /**
110    * @return The value of the {@code servicePort} attribute
111    */
112   @JsonProperty(value = "ServicePort")
113   @Override
114   public int getServicePort() {
115     return servicePort;
116   }
117
118   /**
119    * @return The value of the {@code serviceTags} attribute
120    */
121   @JsonProperty(value = "ServiceTags")
122   @Override
123   public ImmutableList<String> getServiceTags() {
124     return serviceTags;
125   }
126
127   /**
128    * Copy the current immutable object by setting a value for the {@link CatalogService#getNode() node} attribute.
129    * An equals check used to prevent copying of the same value by returning {@code this}.
130    * @param value A new value for node
131    * @return A modified copy of the {@code this} object
132    */
133   public final ImmutableCatalogService withNode(String value) {
134     if (this.node.equals(value)) return this;
135     return new ImmutableCatalogService(
136         Preconditions.checkNotNull(value, "node"),
137         this.address,
138         this.serviceName,
139         this.serviceId,
140         this.serviceAddress,
141         this.servicePort,
142         this.serviceTags);
143   }
144
145   /**
146    * Copy the current immutable object by setting a value for the {@link CatalogService#getAddress() address} attribute.
147    * An equals check used to prevent copying of the same value by returning {@code this}.
148    * @param value A new value for address
149    * @return A modified copy of the {@code this} object
150    */
151   public final ImmutableCatalogService withAddress(String value) {
152     if (this.address.equals(value)) return this;
153     return new ImmutableCatalogService(
154         this.node,
155         Preconditions.checkNotNull(value, "address"),
156         this.serviceName,
157         this.serviceId,
158         this.serviceAddress,
159         this.servicePort,
160         this.serviceTags);
161   }
162
163   /**
164    * Copy the current immutable object by setting a value for the {@link CatalogService#getServiceName() serviceName} attribute.
165    * An equals check used to prevent copying of the same value by returning {@code this}.
166    * @param value A new value for serviceName
167    * @return A modified copy of the {@code this} object
168    */
169   public final ImmutableCatalogService withServiceName(String value) {
170     if (this.serviceName.equals(value)) return this;
171     return new ImmutableCatalogService(
172         this.node,
173         this.address,
174         Preconditions.checkNotNull(value, "serviceName"),
175         this.serviceId,
176         this.serviceAddress,
177         this.servicePort,
178         this.serviceTags);
179   }
180
181   /**
182    * Copy the current immutable object by setting a value for the {@link CatalogService#getServiceId() serviceId} attribute.
183    * An equals check used to prevent copying of the same value by returning {@code this}.
184    * @param value A new value for serviceId
185    * @return A modified copy of the {@code this} object
186    */
187   public final ImmutableCatalogService withServiceId(String value) {
188     if (this.serviceId.equals(value)) return this;
189     return new ImmutableCatalogService(
190         this.node,
191         this.address,
192         this.serviceName,
193         Preconditions.checkNotNull(value, "serviceId"),
194         this.serviceAddress,
195         this.servicePort,
196         this.serviceTags);
197   }
198
199   /**
200    * Copy the current immutable object by setting a value for the {@link CatalogService#getServiceAddress() serviceAddress} attribute.
201    * An equals check used to prevent copying of the same value by returning {@code this}.
202    * @param value A new value for serviceAddress
203    * @return A modified copy of the {@code this} object
204    */
205   public final ImmutableCatalogService withServiceAddress(String value) {
206     if (this.serviceAddress.equals(value)) return this;
207     return new ImmutableCatalogService(
208         this.node,
209         this.address,
210         this.serviceName,
211         this.serviceId,
212         Preconditions.checkNotNull(value, "serviceAddress"),
213         this.servicePort,
214         this.serviceTags);
215   }
216
217   /**
218    * Copy the current immutable object by setting a value for the {@link CatalogService#getServicePort() servicePort} attribute.
219    * A value equality check is used to prevent copying of the same value by returning {@code this}.
220    * @param value A new value for servicePort
221    * @return A modified copy of the {@code this} object
222    */
223   public final ImmutableCatalogService withServicePort(int value) {
224     if (this.servicePort == value) return this;
225     return new ImmutableCatalogService(
226         this.node,
227         this.address,
228         this.serviceName,
229         this.serviceId,
230         this.serviceAddress,
231         value,
232         this.serviceTags);
233   }
234
235   /**
236    * Copy the current immutable object with elements that replace the content of {@link CatalogService#getServiceTags() serviceTags}.
237    * @param elements The elements to set
238    * @return A modified copy of {@code this} object
239    */
240   public final ImmutableCatalogService withServiceTags(String... elements) {
241     ImmutableList<String> newValue = ImmutableList.copyOf(elements);
242     return new ImmutableCatalogService(
243         this.node,
244         this.address,
245         this.serviceName,
246         this.serviceId,
247         this.serviceAddress,
248         this.servicePort,
249         newValue);
250   }
251
252   /**
253    * Copy the current immutable object with elements that replace the content of {@link CatalogService#getServiceTags() serviceTags}.
254    * A shallow reference equality check is used to prevent copying of the same value by returning {@code this}.
255    * @param elements An iterable of serviceTags elements to set
256    * @return A modified copy of {@code this} object
257    */
258   public final ImmutableCatalogService withServiceTags(Iterable<String> elements) {
259     if (this.serviceTags == elements) return this;
260     ImmutableList<String> newValue = ImmutableList.copyOf(elements);
261     return new ImmutableCatalogService(
262         this.node,
263         this.address,
264         this.serviceName,
265         this.serviceId,
266         this.serviceAddress,
267         this.servicePort,
268         newValue);
269   }
270
271   /**
272    * This instance is equal to all instances of {@code ImmutableCatalogService} that have equal attribute values.
273    * @return {@code true} if {@code this} is equal to {@code another} instance
274    */
275   @Override
276   public boolean equals(Object another) {
277     if (this == another) return true;
278     return another instanceof ImmutableCatalogService
279         && equalTo((ImmutableCatalogService) another);
280   }
281
282   private boolean equalTo(ImmutableCatalogService another) {
283     return node.equals(another.node)
284         && address.equals(another.address)
285         && serviceName.equals(another.serviceName)
286         && serviceId.equals(another.serviceId)
287         && serviceAddress.equals(another.serviceAddress)
288         && servicePort == another.servicePort
289         && serviceTags.equals(another.serviceTags);
290   }
291
292   /**
293    * Computes a hash code from attributes: {@code node}, {@code address}, {@code serviceName}, {@code serviceId}, {@code serviceAddress}, {@code servicePort}, {@code serviceTags}.
294    * @return hashCode value
295    */
296   @Override
297   public int hashCode() {
298     int h = 31;
299     h = h * 17 + node.hashCode();
300     h = h * 17 + address.hashCode();
301     h = h * 17 + serviceName.hashCode();
302     h = h * 17 + serviceId.hashCode();
303     h = h * 17 + serviceAddress.hashCode();
304     h = h * 17 + servicePort;
305     h = h * 17 + serviceTags.hashCode();
306     return h;
307   }
308
309   /**
310    * Prints the immutable value {@code CatalogService...} with all non-generated
311    * and non-auxiliary attribute values.
312    * @return A string representation of the value
313    */
314   @Override
315   public String toString() {
316     return MoreObjects.toStringHelper("CatalogService")
317         .add("node", node)
318         .add("address", address)
319         .add("serviceName", serviceName)
320         .add("serviceId", serviceId)
321         .add("serviceAddress", serviceAddress)
322         .add("servicePort", servicePort)
323         .add("serviceTags", serviceTags)
324         .toString();
325   }
326
327   /**
328    * Utility type used to correctly read immutable object from JSON representation.
329    * @deprecated Do not use this type directly, it exists only for the <em>Jackson</em>-binding infrastructure
330    */
331   @Deprecated
332   @JsonDeserialize
333   static final class Json extends CatalogService {
334     String node;
335     String address;
336     String serviceName;
337     String serviceId;
338     String serviceAddress;
339     Integer servicePort;
340     List<String> serviceTags = ImmutableList.of();
341     @JsonProperty(value = "Node")
342     public void setNode(String node) {
343       this.node = node;
344     }
345     @JsonProperty(value = "Address")
346     public void setAddress(String address) {
347       this.address = address;
348     }
349     @JsonProperty(value = "ServiceName")
350     public void setServiceName(String serviceName) {
351       this.serviceName = serviceName;
352     }
353     @JsonProperty(value = "ServiceID")
354     public void setServiceId(String serviceId) {
355       this.serviceId = serviceId;
356     }
357     @JsonProperty(value = "ServiceAddress")
358     public void setServiceAddress(String serviceAddress) {
359       this.serviceAddress = serviceAddress;
360     }
361     @JsonProperty(value = "ServicePort")
362     public void setServicePort(int servicePort) {
363       this.servicePort = servicePort;
364     }
365     @JsonProperty(value = "ServiceTags")
366     public void setServiceTags(List<String> serviceTags) {
367       this.serviceTags = serviceTags;
368     }
369     @Override
370     public String getNode() { throw new UnsupportedOperationException(); }
371     @Override
372     public String getAddress() { throw new UnsupportedOperationException(); }
373     @Override
374     public String getServiceName() { throw new UnsupportedOperationException(); }
375     @Override
376     public String getServiceId() { throw new UnsupportedOperationException(); }
377     @Override
378     public String getServiceAddress() { throw new UnsupportedOperationException(); }
379     @Override
380     public int getServicePort() { throw new UnsupportedOperationException(); }
381     @Override
382     public List<String> getServiceTags() { throw new UnsupportedOperationException(); }
383   }
384
385   /**
386    * @param json A JSON-bindable data structure
387    * @return An immutable value type
388    * @deprecated Do not use this method directly, it exists only for the <em>Jackson</em>-binding infrastructure
389    */
390   @Deprecated
391   @JsonCreator
392   static ImmutableCatalogService fromJson(Json json) {
393     ImmutableCatalogService.Builder builder = ImmutableCatalogService.builder();
394     if (json.node != null) {
395       builder.node(json.node);
396     }
397     if (json.address != null) {
398       builder.address(json.address);
399     }
400     if (json.serviceName != null) {
401       builder.serviceName(json.serviceName);
402     }
403     if (json.serviceId != null) {
404       builder.serviceId(json.serviceId);
405     }
406     if (json.serviceAddress != null) {
407       builder.serviceAddress(json.serviceAddress);
408     }
409     if (json.servicePort != null) {
410       builder.servicePort(json.servicePort);
411     }
412     if (json.serviceTags != null) {
413       builder.addAllServiceTags(json.serviceTags);
414     }
415     return builder.build();
416   }
417
418   /**
419    * Creates an immutable copy of a {@link CatalogService} value.
420    * Uses accessors to get values to initialize the new immutable instance.
421    * If an instance is already immutable, it is returned as is.
422    * @param instance The instance to copy
423    * @return A copied immutable CatalogService instance
424    */
425   public static ImmutableCatalogService copyOf(CatalogService instance) {
426     if (instance instanceof ImmutableCatalogService) {
427       return (ImmutableCatalogService) instance;
428     }
429     return ImmutableCatalogService.builder()
430         .from(instance)
431         .build();
432   }
433
434   /**
435    * Creates a builder for {@link ImmutableCatalogService ImmutableCatalogService}.
436    * @return A new ImmutableCatalogService builder
437    */
438   public static ImmutableCatalogService.Builder builder() {
439     return new ImmutableCatalogService.Builder();
440   }
441
442   /**
443    * Builds instances of type {@link ImmutableCatalogService ImmutableCatalogService}.
444    * Initialize attributes and then invoke the {@link #build()} method to create an
445    * immutable instance.
446    * <p><em>{@code Builder} is not thread-safe and generally should not be stored in a field or collection,
447    * but instead used immediately to create instances.</em>
448    */
449   public static final class Builder {
450     private static final long INIT_BIT_NODE = 0x1L;
451     private static final long INIT_BIT_ADDRESS = 0x2L;
452     private static final long INIT_BIT_SERVICE_NAME = 0x4L;
453     private static final long INIT_BIT_SERVICE_ID = 0x8L;
454     private static final long INIT_BIT_SERVICE_ADDRESS = 0x10L;
455     private static final long INIT_BIT_SERVICE_PORT = 0x20L;
456     private long initBits = 0x3f;
457
458     private String node;
459     private String address;
460     private String serviceName;
461     private String serviceId;
462     private String serviceAddress;
463     private int servicePort;
464     private ImmutableList.Builder<String> serviceTagsBuilder = ImmutableList.builder();
465
466     private Builder() {
467     }
468
469     /**
470      * Fill a builder with attribute values from the provided {@code CatalogService} instance.
471      * Regular attribute values will be replaced with those from the given instance.
472      * Absent optional values will not replace present values.
473      * Collection elements and entries will be added, not replaced.
474      * @param instance The instance from which to copy values
475      * @return {@code this} builder for use in a chained invocation
476      */
477     public final Builder from(CatalogService instance) {
478       Preconditions.checkNotNull(instance, "instance");
479       node(instance.getNode());
480       address(instance.getAddress());
481       serviceName(instance.getServiceName());
482       serviceId(instance.getServiceId());
483       serviceAddress(instance.getServiceAddress());
484       servicePort(instance.getServicePort());
485       addAllServiceTags(instance.getServiceTags());
486       return this;
487     }
488
489     /**
490      * Initializes the value for the {@link CatalogService#getNode() node} attribute.
491      * @param node The value for node 
492      * @return {@code this} builder for use in a chained invocation
493      */
494     public final Builder node(String node) {
495       this.node = Preconditions.checkNotNull(node, "node");
496       initBits &= ~INIT_BIT_NODE;
497       return this;
498     }
499
500     /**
501      * Initializes the value for the {@link CatalogService#getAddress() address} attribute.
502      * @param address The value for address 
503      * @return {@code this} builder for use in a chained invocation
504      */
505     public final Builder address(String address) {
506       this.address = Preconditions.checkNotNull(address, "address");
507       initBits &= ~INIT_BIT_ADDRESS;
508       return this;
509     }
510
511     /**
512      * Initializes the value for the {@link CatalogService#getServiceName() serviceName} attribute.
513      * @param serviceName The value for serviceName 
514      * @return {@code this} builder for use in a chained invocation
515      */
516     public final Builder serviceName(String serviceName) {
517       this.serviceName = Preconditions.checkNotNull(serviceName, "serviceName");
518       initBits &= ~INIT_BIT_SERVICE_NAME;
519       return this;
520     }
521
522     /**
523      * Initializes the value for the {@link CatalogService#getServiceId() serviceId} attribute.
524      * @param serviceId The value for serviceId 
525      * @return {@code this} builder for use in a chained invocation
526      */
527     public final Builder serviceId(String serviceId) {
528       this.serviceId = Preconditions.checkNotNull(serviceId, "serviceId");
529       initBits &= ~INIT_BIT_SERVICE_ID;
530       return this;
531     }
532
533     /**
534      * Initializes the value for the {@link CatalogService#getServiceAddress() serviceAddress} attribute.
535      * @param serviceAddress The value for serviceAddress 
536      * @return {@code this} builder for use in a chained invocation
537      */
538     public final Builder serviceAddress(String serviceAddress) {
539       this.serviceAddress = Preconditions.checkNotNull(serviceAddress, "serviceAddress");
540       initBits &= ~INIT_BIT_SERVICE_ADDRESS;
541       return this;
542     }
543
544     /**
545      * Initializes the value for the {@link CatalogService#getServicePort() servicePort} attribute.
546      * @param servicePort The value for servicePort 
547      * @return {@code this} builder for use in a chained invocation
548      */
549     public final Builder servicePort(int servicePort) {
550       this.servicePort = servicePort;
551       initBits &= ~INIT_BIT_SERVICE_PORT;
552       return this;
553     }
554
555     /**
556      * Adds one element to {@link CatalogService#getServiceTags() serviceTags} list.
557      * @param element A serviceTags element
558      * @return {@code this} builder for use in a chained invocation
559      */
560     public final Builder addServiceTags(String element) {
561       serviceTagsBuilder.add(element);
562       return this;
563     }
564
565     /**
566      * Adds elements to {@link CatalogService#getServiceTags() serviceTags} list.
567      * @param elements An array of serviceTags elements
568      * @return {@code this} builder for use in a chained invocation
569      */
570     public final Builder addServiceTags(String... elements) {
571       serviceTagsBuilder.add(elements);
572       return this;
573     }
574
575     /**
576      * Sets or replaces all elements for {@link CatalogService#getServiceTags() serviceTags} list.
577      * @param elements An iterable of serviceTags elements
578      * @return {@code this} builder for use in a chained invocation
579      */
580     public final Builder serviceTags(Iterable<String> elements) {
581       serviceTagsBuilder = ImmutableList.builder();
582       return addAllServiceTags(elements);
583     }
584
585     /**
586      * Adds elements to {@link CatalogService#getServiceTags() serviceTags} list.
587      * @param elements An iterable of serviceTags elements
588      * @return {@code this} builder for use in a chained invocation
589      */
590     public final Builder addAllServiceTags(Iterable<String> elements) {
591       serviceTagsBuilder.addAll(elements);
592       return this;
593     }
594
595     /**
596      * Builds a new {@link ImmutableCatalogService ImmutableCatalogService}.
597      * @return An immutable instance of CatalogService
598      * @throws java.lang.IllegalStateException if any required attributes are missing
599      */
600     public ImmutableCatalogService build() throws IllegalStateException {
601       if (initBits != 0) {
602         throw new IllegalStateException(formatRequiredAttributesMessage());
603       }
604       return new ImmutableCatalogService(
605           node,
606           address,
607           serviceName,
608           serviceId,
609           serviceAddress,
610           servicePort,
611           serviceTagsBuilder.build());
612     }
613
614     private String formatRequiredAttributesMessage() {
615       List<String> attributes = Lists.newArrayList();
616       if ((initBits & INIT_BIT_NODE) != 0) attributes.add("node");
617       if ((initBits & INIT_BIT_ADDRESS) != 0) attributes.add("address");
618       if ((initBits & INIT_BIT_SERVICE_NAME) != 0) attributes.add("serviceName");
619       if ((initBits & INIT_BIT_SERVICE_ID) != 0) attributes.add("serviceId");
620       if ((initBits & INIT_BIT_SERVICE_ADDRESS) != 0) attributes.add("serviceAddress");
621       if ((initBits & INIT_BIT_SERVICE_PORT) != 0) attributes.add("servicePort");
622       return "Cannot build CatalogService, some of required attributes are not set " + attributes;
623     }
624   }
625 }