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.health;
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.Lists;
25 import java.util.List;
26 import javax.annotation.Generated;
29 * Immutable implementation of {@link Node}.
31 * Use the builder to create immutable instances:
32 * {@code ImmutableNode.builder()}.
34 @SuppressWarnings("all")
35 @Generated({"Immutables.generator", "Node"})
36 @JsonIgnoreProperties(ignoreUnknown = true)
37 public final class ImmutableNode extends Node {
38 private final String node;
39 private final String address;
41 private ImmutableNode(String node, String address) {
43 this.address = address;
47 * @return The value of the {@code node} attribute
49 @JsonProperty(value = "Node")
51 public String getNode() {
56 * @return The value of the {@code address} attribute
58 @JsonProperty(value = "Address")
60 public String getAddress() {
65 * Copy the current immutable object by setting a value for the {@link Node#getNode() node} attribute.
66 * An equals check used to prevent copying of the same value by returning {@code this}.
67 * @param value A new value for node
68 * @return A modified copy of the {@code this} object
70 public final ImmutableNode withNode(String value) {
71 if (this.node.equals(value)) return this;
72 return new ImmutableNode(Preconditions.checkNotNull(value, "node"), this.address);
76 * Copy the current immutable object by setting a value for the {@link Node#getAddress() address} attribute.
77 * An equals check used to prevent copying of the same value by returning {@code this}.
78 * @param value A new value for address
79 * @return A modified copy of the {@code this} object
81 public final ImmutableNode withAddress(String value) {
82 if (this.address.equals(value)) return this;
83 return new ImmutableNode(this.node, Preconditions.checkNotNull(value, "address"));
87 * This instance is equal to all instances of {@code ImmutableNode} that have equal attribute values.
88 * @return {@code true} if {@code this} is equal to {@code another} instance
91 public boolean equals(Object another) {
92 if (this == another) return true;
93 return another instanceof ImmutableNode
94 && equalTo((ImmutableNode) another);
97 private boolean equalTo(ImmutableNode another) {
98 return node.equals(another.node)
99 && address.equals(another.address);
103 * Computes a hash code from attributes: {@code node}, {@code address}.
104 * @return hashCode value
107 public int hashCode() {
109 h = h * 17 + node.hashCode();
110 h = h * 17 + address.hashCode();
115 * Prints the immutable value {@code Node...} with all non-generated
116 * and non-auxiliary attribute values.
117 * @return A string representation of the value
120 public String toString() {
121 return MoreObjects.toStringHelper("Node")
123 .add("address", address)
128 * Utility type used to correctly read immutable object from JSON representation.
129 * @deprecated Do not use this type directly, it exists only for the <em>Jackson</em>-binding infrastructure
133 static final class Json extends Node {
136 @JsonProperty(value = "Node")
137 public void setNode(String node) {
140 @JsonProperty(value = "Address")
141 public void setAddress(String address) {
142 this.address = address;
145 public String getNode() { throw new UnsupportedOperationException(); }
147 public String getAddress() { throw new UnsupportedOperationException(); }
151 * @param json A JSON-bindable data structure
152 * @return An immutable value type
153 * @deprecated Do not use this method directly, it exists only for the <em>Jackson</em>-binding infrastructure
157 static ImmutableNode fromJson(Json json) {
158 ImmutableNode.Builder builder = ImmutableNode.builder();
159 if (json.node != null) {
160 builder.node(json.node);
162 if (json.address != null) {
163 builder.address(json.address);
165 return builder.build();
169 * Creates an immutable copy of a {@link Node} value.
170 * Uses accessors to get values to initialize the new immutable instance.
171 * If an instance is already immutable, it is returned as is.
172 * @param instance The instance to copy
173 * @return A copied immutable Node instance
175 public static ImmutableNode copyOf(Node instance) {
176 if (instance instanceof ImmutableNode) {
177 return (ImmutableNode) instance;
179 return ImmutableNode.builder()
185 * Creates a builder for {@link ImmutableNode ImmutableNode}.
186 * @return A new ImmutableNode builder
188 public static ImmutableNode.Builder builder() {
189 return new ImmutableNode.Builder();
193 * Builds instances of type {@link ImmutableNode ImmutableNode}.
194 * Initialize attributes and then invoke the {@link #build()} method to create an
195 * immutable instance.
196 * <p><em>{@code Builder} is not thread-safe and generally should not be stored in a field or collection,
197 * but instead used immediately to create instances.</em>
199 public static final class Builder {
200 private static final long INIT_BIT_NODE = 0x1L;
201 private static final long INIT_BIT_ADDRESS = 0x2L;
202 private long initBits = 0x3;
205 private String address;
211 * Fill a builder with attribute values from the provided {@code Node} instance.
212 * Regular attribute values will be replaced with those from the given instance.
213 * Absent optional values will not replace present values.
214 * @param instance The instance from which to copy values
215 * @return {@code this} builder for use in a chained invocation
217 public final Builder from(Node instance) {
218 Preconditions.checkNotNull(instance, "instance");
219 node(instance.getNode());
220 address(instance.getAddress());
225 * Initializes the value for the {@link Node#getNode() node} attribute.
226 * @param node The value for node
227 * @return {@code this} builder for use in a chained invocation
229 public final Builder node(String node) {
230 this.node = Preconditions.checkNotNull(node, "node");
231 initBits &= ~INIT_BIT_NODE;
236 * Initializes the value for the {@link Node#getAddress() address} attribute.
237 * @param address The value for address
238 * @return {@code this} builder for use in a chained invocation
240 public final Builder address(String address) {
241 this.address = Preconditions.checkNotNull(address, "address");
242 initBits &= ~INIT_BIT_ADDRESS;
247 * Builds a new {@link ImmutableNode ImmutableNode}.
248 * @return An immutable instance of Node
249 * @throws java.lang.IllegalStateException if any required attributes are missing
251 public ImmutableNode build() throws IllegalStateException {
253 throw new IllegalStateException(formatRequiredAttributesMessage());
255 return new ImmutableNode(node, address);
258 private String formatRequiredAttributesMessage() {
259 List<String> attributes = Lists.newArrayList();
260 if ((initBits & INIT_BIT_NODE) != 0) attributes.add("node");
261 if ((initBits & INIT_BIT_ADDRESS) != 0) attributes.add("address");
262 return "Cannot build Node, some of required attributes are not set " + attributes;