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.health;
\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.Lists;
\r
26 import java.util.List;
\r
27 import javax.annotation.Generated;
\r
30 * Immutable implementation of {@link Node}.
\r
32 * Use the builder to create immutable instances:
\r
33 * {@code ImmutableNode.builder()}.
\r
35 @SuppressWarnings("all")
\r
36 @Generated({"Immutables.generator", "Node"})
\r
37 @JsonIgnoreProperties(ignoreUnknown = true)
\r
38 public final class ImmutableNode extends Node {
\r
39 private final String node;
\r
40 private final String address;
\r
42 private ImmutableNode(String node, String address) {
\r
44 this.address = address;
\r
48 * @return The value of the {@code node} attribute
\r
50 @JsonProperty(value = "Node")
\r
52 public String getNode() {
\r
57 * @return The value of the {@code address} attribute
\r
59 @JsonProperty(value = "Address")
\r
61 public String getAddress() {
\r
66 * Copy the current immutable object by setting a value for the {@link Node#getNode() node} attribute.
\r
67 * An equals check used to prevent copying of the same value by returning {@code this}.
\r
68 * @param value A new value for node
\r
69 * @return A modified copy of the {@code this} object
\r
71 public final ImmutableNode withNode(String value) {
\r
72 if (this.node.equals(value)) return this;
\r
73 return new ImmutableNode(Preconditions.checkNotNull(value, "node"), this.address);
\r
77 * Copy the current immutable object by setting a value for the {@link Node#getAddress() address} attribute.
\r
78 * An equals check used to prevent copying of the same value by returning {@code this}.
\r
79 * @param value A new value for address
\r
80 * @return A modified copy of the {@code this} object
\r
82 public final ImmutableNode withAddress(String value) {
\r
83 if (this.address.equals(value)) return this;
\r
84 return new ImmutableNode(this.node, Preconditions.checkNotNull(value, "address"));
\r
88 * This instance is equal to all instances of {@code ImmutableNode} that have equal attribute values.
\r
89 * @return {@code true} if {@code this} is equal to {@code another} instance
\r
92 public boolean equals(Object another) {
\r
93 if (this == another) return true;
\r
94 return another instanceof ImmutableNode
\r
95 && equalTo((ImmutableNode) another);
\r
98 private boolean equalTo(ImmutableNode another) {
\r
99 return node.equals(another.node)
\r
100 && address.equals(another.address);
\r
104 * Computes a hash code from attributes: {@code node}, {@code address}.
\r
105 * @return hashCode value
\r
108 public int hashCode() {
\r
110 h = h * 17 + node.hashCode();
\r
111 h = h * 17 + address.hashCode();
\r
116 * Prints the immutable value {@code Node...} with all non-generated
\r
117 * and non-auxiliary attribute values.
\r
118 * @return A string representation of the value
\r
121 public String toString() {
\r
122 return MoreObjects.toStringHelper("Node")
\r
124 .add("address", address)
\r
129 * Utility type used to correctly read immutable object from JSON representation.
\r
130 * @deprecated Do not use this type directly, it exists only for the <em>Jackson</em>-binding infrastructure
\r
134 static final class Json extends Node {
\r
137 @JsonProperty(value = "Node")
\r
138 public void setNode(String node) {
\r
141 @JsonProperty(value = "Address")
\r
142 public void setAddress(String address) {
\r
143 this.address = address;
\r
146 public String getNode() { throw new UnsupportedOperationException(); }
\r
148 public String getAddress() { throw new UnsupportedOperationException(); }
\r
152 * @param json A JSON-bindable data structure
\r
153 * @return An immutable value type
\r
154 * @deprecated Do not use this method directly, it exists only for the <em>Jackson</em>-binding infrastructure
\r
158 static ImmutableNode fromJson(Json json) {
\r
159 ImmutableNode.Builder builder = ImmutableNode.builder();
\r
160 if (json.node != null) {
\r
161 builder.node(json.node);
\r
163 if (json.address != null) {
\r
164 builder.address(json.address);
\r
166 return builder.build();
\r
170 * Creates an immutable copy of a {@link Node} value.
\r
171 * Uses accessors to get values to initialize the new immutable instance.
\r
172 * If an instance is already immutable, it is returned as is.
\r
173 * @param instance The instance to copy
\r
174 * @return A copied immutable Node instance
\r
176 public static ImmutableNode copyOf(Node instance) {
\r
177 if (instance instanceof ImmutableNode) {
\r
178 return (ImmutableNode) instance;
\r
180 return ImmutableNode.builder()
\r
186 * Creates a builder for {@link ImmutableNode ImmutableNode}.
\r
187 * @return A new ImmutableNode builder
\r
189 public static ImmutableNode.Builder builder() {
\r
190 return new ImmutableNode.Builder();
\r
194 * Builds instances of type {@link ImmutableNode ImmutableNode}.
\r
195 * Initialize attributes and then invoke the {@link #build()} method to create an
\r
196 * immutable instance.
\r
197 * <p><em>{@code Builder} is not thread-safe and generally should not be stored in a field or collection,
\r
198 * but instead used immediately to create instances.</em>
\r
200 public static final class Builder {
\r
201 private static final long INIT_BIT_NODE = 0x1L;
\r
202 private static final long INIT_BIT_ADDRESS = 0x2L;
\r
203 private long initBits = 0x3;
\r
205 private String node;
\r
206 private String address;
\r
208 private Builder() {
\r
212 * Fill a builder with attribute values from the provided {@code Node} instance.
\r
213 * Regular attribute values will be replaced with those from the given instance.
\r
214 * Absent optional values will not replace present values.
\r
215 * @param instance The instance from which to copy values
\r
216 * @return {@code this} builder for use in a chained invocation
\r
218 public final Builder from(Node instance) {
\r
219 Preconditions.checkNotNull(instance, "instance");
\r
220 node(instance.getNode());
\r
221 address(instance.getAddress());
\r
226 * Initializes the value for the {@link Node#getNode() node} attribute.
\r
227 * @param node The value for node
\r
228 * @return {@code this} builder for use in a chained invocation
\r
230 public final Builder node(String node) {
\r
231 this.node = Preconditions.checkNotNull(node, "node");
\r
232 initBits &= ~INIT_BIT_NODE;
\r
237 * Initializes the value for the {@link Node#getAddress() address} attribute.
\r
238 * @param address The value for address
\r
239 * @return {@code this} builder for use in a chained invocation
\r
241 public final Builder address(String address) {
\r
242 this.address = Preconditions.checkNotNull(address, "address");
\r
243 initBits &= ~INIT_BIT_ADDRESS;
\r
248 * Builds a new {@link ImmutableNode ImmutableNode}.
\r
249 * @return An immutable instance of Node
\r
250 * @throws java.lang.IllegalStateException if any required attributes are missing
\r
252 public ImmutableNode build() throws IllegalStateException {
\r
253 if (initBits != 0) {
\r
254 throw new IllegalStateException(formatRequiredAttributesMessage());
\r
256 return new ImmutableNode(node, address);
\r
259 private String formatRequiredAttributesMessage() {
\r
260 List<String> attributes = Lists.newArrayList();
\r
261 if ((initBits & INIT_BIT_NODE) != 0) attributes.add("node");
\r
262 if ((initBits & INIT_BIT_ADDRESS) != 0) attributes.add("address");
\r
263 return "Cannot build Node, some of required attributes are not set " + attributes;
\r