2 * Copyright 2016 2015-2016 ZTE, Inc. and others. All rights reserved.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
16 package org.openo.msb.wrapper.consul.model.catalog;
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;
30 * Immutable implementation of {@link CatalogService}.
32 * Use the builder to create immutable instances:
33 * {@code ImmutableCatalogService.builder()}.
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;
47 private ImmutableCatalogService(
52 String serviceAddress,
54 ImmutableList<String> serviceTags) {
56 this.address = address;
57 this.serviceName = serviceName;
58 this.serviceId = serviceId;
59 this.serviceAddress = serviceAddress;
60 this.servicePort = servicePort;
61 this.serviceTags = serviceTags;
65 * @return The value of the {@code node} attribute
67 @JsonProperty(value = "Node")
69 public String getNode() {
74 * @return The value of the {@code address} attribute
76 @JsonProperty(value = "Address")
78 public String getAddress() {
83 * @return The value of the {@code serviceName} attribute
85 @JsonProperty(value = "ServiceName")
87 public String getServiceName() {
92 * @return The value of the {@code serviceId} attribute
94 @JsonProperty(value = "ServiceID")
96 public String getServiceId() {
101 * @return The value of the {@code serviceAddress} attribute
103 @JsonProperty(value = "ServiceAddress")
105 public String getServiceAddress() {
106 return serviceAddress;
110 * @return The value of the {@code servicePort} attribute
112 @JsonProperty(value = "ServicePort")
114 public int getServicePort() {
119 * @return The value of the {@code serviceTags} attribute
121 @JsonProperty(value = "ServiceTags")
123 public ImmutableList<String> getServiceTags() {
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
133 public final ImmutableCatalogService withNode(String value) {
134 if (this.node.equals(value)) return this;
135 return new ImmutableCatalogService(
136 Preconditions.checkNotNull(value, "node"),
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
151 public final ImmutableCatalogService withAddress(String value) {
152 if (this.address.equals(value)) return this;
153 return new ImmutableCatalogService(
155 Preconditions.checkNotNull(value, "address"),
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
169 public final ImmutableCatalogService withServiceName(String value) {
170 if (this.serviceName.equals(value)) return this;
171 return new ImmutableCatalogService(
174 Preconditions.checkNotNull(value, "serviceName"),
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
187 public final ImmutableCatalogService withServiceId(String value) {
188 if (this.serviceId.equals(value)) return this;
189 return new ImmutableCatalogService(
193 Preconditions.checkNotNull(value, "serviceId"),
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
205 public final ImmutableCatalogService withServiceAddress(String value) {
206 if (this.serviceAddress.equals(value)) return this;
207 return new ImmutableCatalogService(
212 Preconditions.checkNotNull(value, "serviceAddress"),
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
223 public final ImmutableCatalogService withServicePort(int value) {
224 if (this.servicePort == value) return this;
225 return new ImmutableCatalogService(
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
240 public final ImmutableCatalogService withServiceTags(String... elements) {
241 ImmutableList<String> newValue = ImmutableList.copyOf(elements);
242 return new ImmutableCatalogService(
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
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(
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
276 public boolean equals(Object another) {
277 if (this == another) return true;
278 return another instanceof ImmutableCatalogService
279 && equalTo((ImmutableCatalogService) another);
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);
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
297 public int hashCode() {
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();
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
315 public String toString() {
316 return MoreObjects.toStringHelper("CatalogService")
318 .add("address", address)
319 .add("serviceName", serviceName)
320 .add("serviceId", serviceId)
321 .add("serviceAddress", serviceAddress)
322 .add("servicePort", servicePort)
323 .add("serviceTags", serviceTags)
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
333 static final class Json extends CatalogService {
338 String serviceAddress;
340 List<String> serviceTags = ImmutableList.of();
341 @JsonProperty(value = "Node")
342 public void setNode(String node) {
345 @JsonProperty(value = "Address")
346 public void setAddress(String address) {
347 this.address = address;
349 @JsonProperty(value = "ServiceName")
350 public void setServiceName(String serviceName) {
351 this.serviceName = serviceName;
353 @JsonProperty(value = "ServiceID")
354 public void setServiceId(String serviceId) {
355 this.serviceId = serviceId;
357 @JsonProperty(value = "ServiceAddress")
358 public void setServiceAddress(String serviceAddress) {
359 this.serviceAddress = serviceAddress;
361 @JsonProperty(value = "ServicePort")
362 public void setServicePort(int servicePort) {
363 this.servicePort = servicePort;
365 @JsonProperty(value = "ServiceTags")
366 public void setServiceTags(List<String> serviceTags) {
367 this.serviceTags = serviceTags;
370 public String getNode() { throw new UnsupportedOperationException(); }
372 public String getAddress() { throw new UnsupportedOperationException(); }
374 public String getServiceName() { throw new UnsupportedOperationException(); }
376 public String getServiceId() { throw new UnsupportedOperationException(); }
378 public String getServiceAddress() { throw new UnsupportedOperationException(); }
380 public int getServicePort() { throw new UnsupportedOperationException(); }
382 public List<String> getServiceTags() { throw new UnsupportedOperationException(); }
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
392 static ImmutableCatalogService fromJson(Json json) {
393 ImmutableCatalogService.Builder builder = ImmutableCatalogService.builder();
394 if (json.node != null) {
395 builder.node(json.node);
397 if (json.address != null) {
398 builder.address(json.address);
400 if (json.serviceName != null) {
401 builder.serviceName(json.serviceName);
403 if (json.serviceId != null) {
404 builder.serviceId(json.serviceId);
406 if (json.serviceAddress != null) {
407 builder.serviceAddress(json.serviceAddress);
409 if (json.servicePort != null) {
410 builder.servicePort(json.servicePort);
412 if (json.serviceTags != null) {
413 builder.addAllServiceTags(json.serviceTags);
415 return builder.build();
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
425 public static ImmutableCatalogService copyOf(CatalogService instance) {
426 if (instance instanceof ImmutableCatalogService) {
427 return (ImmutableCatalogService) instance;
429 return ImmutableCatalogService.builder()
435 * Creates a builder for {@link ImmutableCatalogService ImmutableCatalogService}.
436 * @return A new ImmutableCatalogService builder
438 public static ImmutableCatalogService.Builder builder() {
439 return new ImmutableCatalogService.Builder();
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>
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;
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();
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
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());
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
494 public final Builder node(String node) {
495 this.node = Preconditions.checkNotNull(node, "node");
496 initBits &= ~INIT_BIT_NODE;
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
505 public final Builder address(String address) {
506 this.address = Preconditions.checkNotNull(address, "address");
507 initBits &= ~INIT_BIT_ADDRESS;
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
516 public final Builder serviceName(String serviceName) {
517 this.serviceName = Preconditions.checkNotNull(serviceName, "serviceName");
518 initBits &= ~INIT_BIT_SERVICE_NAME;
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
527 public final Builder serviceId(String serviceId) {
528 this.serviceId = Preconditions.checkNotNull(serviceId, "serviceId");
529 initBits &= ~INIT_BIT_SERVICE_ID;
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
538 public final Builder serviceAddress(String serviceAddress) {
539 this.serviceAddress = Preconditions.checkNotNull(serviceAddress, "serviceAddress");
540 initBits &= ~INIT_BIT_SERVICE_ADDRESS;
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
549 public final Builder servicePort(int servicePort) {
550 this.servicePort = servicePort;
551 initBits &= ~INIT_BIT_SERVICE_PORT;
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
560 public final Builder addServiceTags(String element) {
561 serviceTagsBuilder.add(element);
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
570 public final Builder addServiceTags(String... elements) {
571 serviceTagsBuilder.add(elements);
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
580 public final Builder serviceTags(Iterable<String> elements) {
581 serviceTagsBuilder = ImmutableList.builder();
582 return addAllServiceTags(elements);
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
590 public final Builder addAllServiceTags(Iterable<String> elements) {
591 serviceTagsBuilder.addAll(elements);
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
600 public ImmutableCatalogService build() throws IllegalStateException {
602 throw new IllegalStateException(formatRequiredAttributesMessage());
604 return new ImmutableCatalogService(
611 serviceTagsBuilder.build());
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;