2 * Copyright (C) 2016 ZTE, Inc. and others. All rights reserved. (ZTE)
\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
8 * http://www.apache.org/licenses/LICENSE-2.0
\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
17 package org.openo.msb.wrapper.consul.model.catalog;
\r
19 import com.fasterxml.jackson.annotation.JsonCreator;
\r
20 import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
\r
21 import com.fasterxml.jackson.annotation.JsonProperty;
\r
22 import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
\r
23 import com.google.common.base.MoreObjects;
\r
24 import com.google.common.base.Preconditions;
\r
25 import com.google.common.collect.ImmutableList;
\r
26 import com.google.common.collect.Lists;
\r
27 import java.util.List;
\r
28 import javax.annotation.Generated;
\r
31 * Immutable implementation of {@link CatalogService}.
\r
33 * Use the builder to create immutable instances:
\r
34 * {@code ImmutableCatalogService.builder()}.
\r
36 @SuppressWarnings("all")
\r
37 @Generated({"Immutables.generator", "CatalogService"})
\r
38 @JsonIgnoreProperties(ignoreUnknown = true)
\r
39 public final class ImmutableCatalogService extends CatalogService {
\r
40 private final String node;
\r
41 private final String address;
\r
42 private final String serviceName;
\r
43 private final String serviceId;
\r
44 private final String serviceAddress;
\r
45 private final int servicePort;
\r
46 private final ImmutableList<String> serviceTags;
\r
48 private ImmutableCatalogService(
\r
53 String serviceAddress,
\r
55 ImmutableList<String> serviceTags) {
\r
57 this.address = address;
\r
58 this.serviceName = serviceName;
\r
59 this.serviceId = serviceId;
\r
60 this.serviceAddress = serviceAddress;
\r
61 this.servicePort = servicePort;
\r
62 this.serviceTags = serviceTags;
\r
66 * @return The value of the {@code node} attribute
\r
68 @JsonProperty(value = "Node")
\r
70 public String getNode() {
\r
75 * @return The value of the {@code address} attribute
\r
77 @JsonProperty(value = "Address")
\r
79 public String getAddress() {
\r
84 * @return The value of the {@code serviceName} attribute
\r
86 @JsonProperty(value = "ServiceName")
\r
88 public String getServiceName() {
\r
93 * @return The value of the {@code serviceId} attribute
\r
95 @JsonProperty(value = "ServiceID")
\r
97 public String getServiceId() {
\r
102 * @return The value of the {@code serviceAddress} attribute
\r
104 @JsonProperty(value = "ServiceAddress")
\r
106 public String getServiceAddress() {
\r
107 return serviceAddress;
\r
111 * @return The value of the {@code servicePort} attribute
\r
113 @JsonProperty(value = "ServicePort")
\r
115 public int getServicePort() {
\r
116 return servicePort;
\r
120 * @return The value of the {@code serviceTags} attribute
\r
122 @JsonProperty(value = "ServiceTags")
\r
124 public ImmutableList<String> getServiceTags() {
\r
125 return serviceTags;
\r
129 * Copy the current immutable object by setting a value for the {@link CatalogService#getNode() node} attribute.
\r
130 * An equals check used to prevent copying of the same value by returning {@code this}.
\r
131 * @param value A new value for node
\r
132 * @return A modified copy of the {@code this} object
\r
134 public final ImmutableCatalogService withNode(String value) {
\r
135 if (this.node.equals(value)) return this;
\r
136 return new ImmutableCatalogService(
\r
137 Preconditions.checkNotNull(value, "node"),
\r
141 this.serviceAddress,
\r
147 * Copy the current immutable object by setting a value for the {@link CatalogService#getAddress() address} attribute.
\r
148 * An equals check used to prevent copying of the same value by returning {@code this}.
\r
149 * @param value A new value for address
\r
150 * @return A modified copy of the {@code this} object
\r
152 public final ImmutableCatalogService withAddress(String value) {
\r
153 if (this.address.equals(value)) return this;
\r
154 return new ImmutableCatalogService(
\r
156 Preconditions.checkNotNull(value, "address"),
\r
159 this.serviceAddress,
\r
165 * Copy the current immutable object by setting a value for the {@link CatalogService#getServiceName() serviceName} attribute.
\r
166 * An equals check used to prevent copying of the same value by returning {@code this}.
\r
167 * @param value A new value for serviceName
\r
168 * @return A modified copy of the {@code this} object
\r
170 public final ImmutableCatalogService withServiceName(String value) {
\r
171 if (this.serviceName.equals(value)) return this;
\r
172 return new ImmutableCatalogService(
\r
175 Preconditions.checkNotNull(value, "serviceName"),
\r
177 this.serviceAddress,
\r
183 * Copy the current immutable object by setting a value for the {@link CatalogService#getServiceId() serviceId} attribute.
\r
184 * An equals check used to prevent copying of the same value by returning {@code this}.
\r
185 * @param value A new value for serviceId
\r
186 * @return A modified copy of the {@code this} object
\r
188 public final ImmutableCatalogService withServiceId(String value) {
\r
189 if (this.serviceId.equals(value)) return this;
\r
190 return new ImmutableCatalogService(
\r
194 Preconditions.checkNotNull(value, "serviceId"),
\r
195 this.serviceAddress,
\r
201 * Copy the current immutable object by setting a value for the {@link CatalogService#getServiceAddress() serviceAddress} attribute.
\r
202 * An equals check used to prevent copying of the same value by returning {@code this}.
\r
203 * @param value A new value for serviceAddress
\r
204 * @return A modified copy of the {@code this} object
\r
206 public final ImmutableCatalogService withServiceAddress(String value) {
\r
207 if (this.serviceAddress.equals(value)) return this;
\r
208 return new ImmutableCatalogService(
\r
213 Preconditions.checkNotNull(value, "serviceAddress"),
\r
219 * Copy the current immutable object by setting a value for the {@link CatalogService#getServicePort() servicePort} attribute.
\r
220 * A value equality check is used to prevent copying of the same value by returning {@code this}.
\r
221 * @param value A new value for servicePort
\r
222 * @return A modified copy of the {@code this} object
\r
224 public final ImmutableCatalogService withServicePort(int value) {
\r
225 if (this.servicePort == value) return this;
\r
226 return new ImmutableCatalogService(
\r
231 this.serviceAddress,
\r
237 * Copy the current immutable object with elements that replace the content of {@link CatalogService#getServiceTags() serviceTags}.
\r
238 * @param elements The elements to set
\r
239 * @return A modified copy of {@code this} object
\r
241 public final ImmutableCatalogService withServiceTags(String... elements) {
\r
242 ImmutableList<String> newValue = ImmutableList.copyOf(elements);
\r
243 return new ImmutableCatalogService(
\r
248 this.serviceAddress,
\r
254 * Copy the current immutable object with elements that replace the content of {@link CatalogService#getServiceTags() serviceTags}.
\r
255 * A shallow reference equality check is used to prevent copying of the same value by returning {@code this}.
\r
256 * @param elements An iterable of serviceTags elements to set
\r
257 * @return A modified copy of {@code this} object
\r
259 public final ImmutableCatalogService withServiceTags(Iterable<String> elements) {
\r
260 if (this.serviceTags == elements) return this;
\r
261 ImmutableList<String> newValue = ImmutableList.copyOf(elements);
\r
262 return new ImmutableCatalogService(
\r
267 this.serviceAddress,
\r
273 * This instance is equal to all instances of {@code ImmutableCatalogService} that have equal attribute values.
\r
274 * @return {@code true} if {@code this} is equal to {@code another} instance
\r
277 public boolean equals(Object another) {
\r
278 if (this == another) return true;
\r
279 return another instanceof ImmutableCatalogService
\r
280 && equalTo((ImmutableCatalogService) another);
\r
283 private boolean equalTo(ImmutableCatalogService another) {
\r
284 return node.equals(another.node)
\r
285 && address.equals(another.address)
\r
286 && serviceName.equals(another.serviceName)
\r
287 && serviceId.equals(another.serviceId)
\r
288 && serviceAddress.equals(another.serviceAddress)
\r
289 && servicePort == another.servicePort
\r
290 && serviceTags.equals(another.serviceTags);
\r
294 * Computes a hash code from attributes: {@code node}, {@code address}, {@code serviceName}, {@code serviceId}, {@code serviceAddress}, {@code servicePort}, {@code serviceTags}.
\r
295 * @return hashCode value
\r
298 public int hashCode() {
\r
300 h = h * 17 + node.hashCode();
\r
301 h = h * 17 + address.hashCode();
\r
302 h = h * 17 + serviceName.hashCode();
\r
303 h = h * 17 + serviceId.hashCode();
\r
304 h = h * 17 + serviceAddress.hashCode();
\r
305 h = h * 17 + servicePort;
\r
306 h = h * 17 + serviceTags.hashCode();
\r
311 * Prints the immutable value {@code CatalogService...} with all non-generated
\r
312 * and non-auxiliary attribute values.
\r
313 * @return A string representation of the value
\r
316 public String toString() {
\r
317 return MoreObjects.toStringHelper("CatalogService")
\r
319 .add("address", address)
\r
320 .add("serviceName", serviceName)
\r
321 .add("serviceId", serviceId)
\r
322 .add("serviceAddress", serviceAddress)
\r
323 .add("servicePort", servicePort)
\r
324 .add("serviceTags", serviceTags)
\r
329 * Utility type used to correctly read immutable object from JSON representation.
\r
330 * @deprecated Do not use this type directly, it exists only for the <em>Jackson</em>-binding infrastructure
\r
334 static final class Json extends CatalogService {
\r
337 String serviceName;
\r
339 String serviceAddress;
\r
340 Integer servicePort;
\r
341 List<String> serviceTags = ImmutableList.of();
\r
342 @JsonProperty(value = "Node")
\r
343 public void setNode(String node) {
\r
346 @JsonProperty(value = "Address")
\r
347 public void setAddress(String address) {
\r
348 this.address = address;
\r
350 @JsonProperty(value = "ServiceName")
\r
351 public void setServiceName(String serviceName) {
\r
352 this.serviceName = serviceName;
\r
354 @JsonProperty(value = "ServiceID")
\r
355 public void setServiceId(String serviceId) {
\r
356 this.serviceId = serviceId;
\r
358 @JsonProperty(value = "ServiceAddress")
\r
359 public void setServiceAddress(String serviceAddress) {
\r
360 this.serviceAddress = serviceAddress;
\r
362 @JsonProperty(value = "ServicePort")
\r
363 public void setServicePort(int servicePort) {
\r
364 this.servicePort = servicePort;
\r
366 @JsonProperty(value = "ServiceTags")
\r
367 public void setServiceTags(List<String> serviceTags) {
\r
368 this.serviceTags = serviceTags;
\r
371 public String getNode() { throw new UnsupportedOperationException(); }
\r
373 public String getAddress() { throw new UnsupportedOperationException(); }
\r
375 public String getServiceName() { throw new UnsupportedOperationException(); }
\r
377 public String getServiceId() { throw new UnsupportedOperationException(); }
\r
379 public String getServiceAddress() { throw new UnsupportedOperationException(); }
\r
381 public int getServicePort() { throw new UnsupportedOperationException(); }
\r
383 public List<String> getServiceTags() { throw new UnsupportedOperationException(); }
\r
387 * @param json A JSON-bindable data structure
\r
388 * @return An immutable value type
\r
389 * @deprecated Do not use this method directly, it exists only for the <em>Jackson</em>-binding infrastructure
\r
393 static ImmutableCatalogService fromJson(Json json) {
\r
394 ImmutableCatalogService.Builder builder = ImmutableCatalogService.builder();
\r
395 if (json.node != null) {
\r
396 builder.node(json.node);
\r
398 if (json.address != null) {
\r
399 builder.address(json.address);
\r
401 if (json.serviceName != null) {
\r
402 builder.serviceName(json.serviceName);
\r
404 if (json.serviceId != null) {
\r
405 builder.serviceId(json.serviceId);
\r
407 if (json.serviceAddress != null) {
\r
408 builder.serviceAddress(json.serviceAddress);
\r
410 if (json.servicePort != null) {
\r
411 builder.servicePort(json.servicePort);
\r
413 if (json.serviceTags != null) {
\r
414 builder.addAllServiceTags(json.serviceTags);
\r
416 return builder.build();
\r
420 * Creates an immutable copy of a {@link CatalogService} value.
\r
421 * Uses accessors to get values to initialize the new immutable instance.
\r
422 * If an instance is already immutable, it is returned as is.
\r
423 * @param instance The instance to copy
\r
424 * @return A copied immutable CatalogService instance
\r
426 public static ImmutableCatalogService copyOf(CatalogService instance) {
\r
427 if (instance instanceof ImmutableCatalogService) {
\r
428 return (ImmutableCatalogService) instance;
\r
430 return ImmutableCatalogService.builder()
\r
436 * Creates a builder for {@link ImmutableCatalogService ImmutableCatalogService}.
\r
437 * @return A new ImmutableCatalogService builder
\r
439 public static ImmutableCatalogService.Builder builder() {
\r
440 return new ImmutableCatalogService.Builder();
\r
444 * Builds instances of type {@link ImmutableCatalogService ImmutableCatalogService}.
\r
445 * Initialize attributes and then invoke the {@link #build()} method to create an
\r
446 * immutable instance.
\r
447 * <p><em>{@code Builder} is not thread-safe and generally should not be stored in a field or collection,
\r
448 * but instead used immediately to create instances.</em>
\r
450 public static final class Builder {
\r
451 private static final long INIT_BIT_NODE = 0x1L;
\r
452 private static final long INIT_BIT_ADDRESS = 0x2L;
\r
453 private static final long INIT_BIT_SERVICE_NAME = 0x4L;
\r
454 private static final long INIT_BIT_SERVICE_ID = 0x8L;
\r
455 private static final long INIT_BIT_SERVICE_ADDRESS = 0x10L;
\r
456 private static final long INIT_BIT_SERVICE_PORT = 0x20L;
\r
457 private long initBits = 0x3f;
\r
459 private String node;
\r
460 private String address;
\r
461 private String serviceName;
\r
462 private String serviceId;
\r
463 private String serviceAddress;
\r
464 private int servicePort;
\r
465 private ImmutableList.Builder<String> serviceTagsBuilder = ImmutableList.builder();
\r
467 private Builder() {
\r
471 * Fill a builder with attribute values from the provided {@code CatalogService} instance.
\r
472 * Regular attribute values will be replaced with those from the given instance.
\r
473 * Absent optional values will not replace present values.
\r
474 * Collection elements and entries will be added, not replaced.
\r
475 * @param instance The instance from which to copy values
\r
476 * @return {@code this} builder for use in a chained invocation
\r
478 public final Builder from(CatalogService instance) {
\r
479 Preconditions.checkNotNull(instance, "instance");
\r
480 node(instance.getNode());
\r
481 address(instance.getAddress());
\r
482 serviceName(instance.getServiceName());
\r
483 serviceId(instance.getServiceId());
\r
484 serviceAddress(instance.getServiceAddress());
\r
485 servicePort(instance.getServicePort());
\r
486 addAllServiceTags(instance.getServiceTags());
\r
491 * Initializes the value for the {@link CatalogService#getNode() node} attribute.
\r
492 * @param node The value for node
\r
493 * @return {@code this} builder for use in a chained invocation
\r
495 public final Builder node(String node) {
\r
496 this.node = Preconditions.checkNotNull(node, "node");
\r
497 initBits &= ~INIT_BIT_NODE;
\r
502 * Initializes the value for the {@link CatalogService#getAddress() address} attribute.
\r
503 * @param address The value for address
\r
504 * @return {@code this} builder for use in a chained invocation
\r
506 public final Builder address(String address) {
\r
507 this.address = Preconditions.checkNotNull(address, "address");
\r
508 initBits &= ~INIT_BIT_ADDRESS;
\r
513 * Initializes the value for the {@link CatalogService#getServiceName() serviceName} attribute.
\r
514 * @param serviceName The value for serviceName
\r
515 * @return {@code this} builder for use in a chained invocation
\r
517 public final Builder serviceName(String serviceName) {
\r
518 this.serviceName = Preconditions.checkNotNull(serviceName, "serviceName");
\r
519 initBits &= ~INIT_BIT_SERVICE_NAME;
\r
524 * Initializes the value for the {@link CatalogService#getServiceId() serviceId} attribute.
\r
525 * @param serviceId The value for serviceId
\r
526 * @return {@code this} builder for use in a chained invocation
\r
528 public final Builder serviceId(String serviceId) {
\r
529 this.serviceId = Preconditions.checkNotNull(serviceId, "serviceId");
\r
530 initBits &= ~INIT_BIT_SERVICE_ID;
\r
535 * Initializes the value for the {@link CatalogService#getServiceAddress() serviceAddress} attribute.
\r
536 * @param serviceAddress The value for serviceAddress
\r
537 * @return {@code this} builder for use in a chained invocation
\r
539 public final Builder serviceAddress(String serviceAddress) {
\r
540 this.serviceAddress = Preconditions.checkNotNull(serviceAddress, "serviceAddress");
\r
541 initBits &= ~INIT_BIT_SERVICE_ADDRESS;
\r
546 * Initializes the value for the {@link CatalogService#getServicePort() servicePort} attribute.
\r
547 * @param servicePort The value for servicePort
\r
548 * @return {@code this} builder for use in a chained invocation
\r
550 public final Builder servicePort(int servicePort) {
\r
551 this.servicePort = servicePort;
\r
552 initBits &= ~INIT_BIT_SERVICE_PORT;
\r
557 * Adds one element to {@link CatalogService#getServiceTags() serviceTags} list.
\r
558 * @param element A serviceTags element
\r
559 * @return {@code this} builder for use in a chained invocation
\r
561 public final Builder addServiceTags(String element) {
\r
562 serviceTagsBuilder.add(element);
\r
567 * Adds elements to {@link CatalogService#getServiceTags() serviceTags} list.
\r
568 * @param elements An array of serviceTags elements
\r
569 * @return {@code this} builder for use in a chained invocation
\r
571 public final Builder addServiceTags(String... elements) {
\r
572 serviceTagsBuilder.add(elements);
\r
577 * Sets or replaces all elements for {@link CatalogService#getServiceTags() serviceTags} list.
\r
578 * @param elements An iterable of serviceTags elements
\r
579 * @return {@code this} builder for use in a chained invocation
\r
581 public final Builder serviceTags(Iterable<String> elements) {
\r
582 serviceTagsBuilder = ImmutableList.builder();
\r
583 return addAllServiceTags(elements);
\r
587 * Adds elements to {@link CatalogService#getServiceTags() serviceTags} list.
\r
588 * @param elements An iterable of serviceTags elements
\r
589 * @return {@code this} builder for use in a chained invocation
\r
591 public final Builder addAllServiceTags(Iterable<String> elements) {
\r
592 serviceTagsBuilder.addAll(elements);
\r
597 * Builds a new {@link ImmutableCatalogService ImmutableCatalogService}.
\r
598 * @return An immutable instance of CatalogService
\r
599 * @throws java.lang.IllegalStateException if any required attributes are missing
\r
601 public ImmutableCatalogService build() throws IllegalStateException {
\r
602 if (initBits != 0) {
\r
603 throw new IllegalStateException(formatRequiredAttributesMessage());
\r
605 return new ImmutableCatalogService(
\r
612 serviceTagsBuilder.build());
\r
615 private String formatRequiredAttributesMessage() {
\r
616 List<String> attributes = Lists.newArrayList();
\r
617 if ((initBits & INIT_BIT_NODE) != 0) attributes.add("node");
\r
618 if ((initBits & INIT_BIT_ADDRESS) != 0) attributes.add("address");
\r
619 if ((initBits & INIT_BIT_SERVICE_NAME) != 0) attributes.add("serviceName");
\r
620 if ((initBits & INIT_BIT_SERVICE_ID) != 0) attributes.add("serviceId");
\r
621 if ((initBits & INIT_BIT_SERVICE_ADDRESS) != 0) attributes.add("serviceAddress");
\r
622 if ((initBits & INIT_BIT_SERVICE_PORT) != 0) attributes.add("servicePort");
\r
623 return "Cannot build CatalogService, some of required attributes are not set " + attributes;
\r