2 * Copyright 2016-2017 ZTE, Inc. and others.
4 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
5 * in compliance with the License. You may obtain a copy of the License at
7 * http://www.apache.org/licenses/LICENSE-2.0
9 * Unless required by applicable law or agreed to in writing, software distributed under the License
10 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
11 * or implied. See the License for the specific language governing permissions and limitations under
14 package org.onap.msb.sdclient.wrapper.consul.model.health;
16 import java.util.List;
18 import javax.annotation.Generated;
20 import com.fasterxml.jackson.annotation.JsonCreator;
21 import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
22 import com.fasterxml.jackson.annotation.JsonProperty;
23 import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
24 import com.google.common.base.MoreObjects;
25 import com.google.common.base.Preconditions;
26 import com.google.common.collect.Lists;
29 * Immutable implementation of {@link Node}.
31 * Use the builder to create immutable instances: {@code ImmutableNode.builder()}.
33 @SuppressWarnings("all")
34 @Generated({"Immutables.generator", "Node"})
35 @JsonIgnoreProperties(ignoreUnknown = true)
36 public final class ImmutableNode extends Node {
37 private final String node;
38 private final String address;
40 private ImmutableNode(String node, String address) {
42 this.address = address;
46 * @return The value of the {@code node} attribute
48 @JsonProperty(value = "Node")
50 public String getNode() {
55 * @return The value of the {@code address} attribute
57 @JsonProperty(value = "Address")
59 public String getAddress() {
64 * Copy the current immutable object by setting a value for the {@link Node#getNode() node}
65 * attribute. An equals check used to prevent copying of the same value by returning
68 * @param value A new value for node
69 * @return A modified copy of the {@code this} object
71 public final ImmutableNode withNode(String value) {
72 if (this.node.equals(value))
74 return new ImmutableNode(Preconditions.checkNotNull(value, "node"), this.address);
78 * Copy the current immutable object by setting a value for the {@link Node#getAddress()
79 * address} attribute. An equals check used to prevent copying of the same value by returning
82 * @param value A new value for address
83 * @return A modified copy of the {@code this} object
85 public final ImmutableNode withAddress(String value) {
86 if (this.address.equals(value))
88 return new ImmutableNode(this.node, Preconditions.checkNotNull(value, "address"));
92 * This instance is equal to all instances of {@code ImmutableNode} that have equal attribute
95 * @return {@code true} if {@code this} is equal to {@code another} instance
98 public boolean equals(Object another) {
101 return another instanceof ImmutableNode && equalTo((ImmutableNode) another);
104 private boolean equalTo(ImmutableNode another) {
105 return node.equals(another.node) && address.equals(another.address);
109 * Computes a hash code from attributes: {@code node}, {@code address}.
111 * @return hashCode value
114 public int hashCode() {
116 h = h * 17 + node.hashCode();
117 h = h * 17 + address.hashCode();
122 * Prints the immutable value {@code Node...} with all non-generated and non-auxiliary attribute
125 * @return A string representation of the value
128 public String toString() {
129 return MoreObjects.toStringHelper("Node").add("node", node).add("address", address).toString();
133 * Utility type used to correctly read immutable object from JSON representation.
135 * @deprecated Do not use this type directly, it exists only for the <em>Jackson</em>-binding
140 static final class Json extends Node {
144 @JsonProperty(value = "Node")
145 public void setNode(String node) {
149 @JsonProperty(value = "Address")
150 public void setAddress(String address) {
151 this.address = address;
155 public String getNode() {
156 throw new UnsupportedOperationException();
160 public String getAddress() {
161 throw new UnsupportedOperationException();
166 * @param json A JSON-bindable data structure
167 * @return An immutable value type
168 * @deprecated Do not use this method directly, it exists only for the <em>Jackson</em>-binding
173 static ImmutableNode fromJson(Json json) {
174 ImmutableNode.Builder builder = ImmutableNode.builder();
175 if (json.node != null) {
176 builder.node(json.node);
178 if (json.address != null) {
179 builder.address(json.address);
181 return builder.build();
185 * Creates an immutable copy of a {@link Node} value. Uses accessors to get values to initialize
186 * the new immutable instance. If an instance is already immutable, it is returned as is.
188 * @param instance The instance to copy
189 * @return A copied immutable Node instance
191 public static ImmutableNode copyOf(Node instance) {
192 if (instance instanceof ImmutableNode) {
193 return (ImmutableNode) instance;
195 return ImmutableNode.builder().from(instance).build();
199 * Creates a builder for {@link ImmutableNode ImmutableNode}.
201 * @return A new ImmutableNode builder
203 public static ImmutableNode.Builder builder() {
204 return new ImmutableNode.Builder();
208 * Builds instances of type {@link ImmutableNode ImmutableNode}. Initialize attributes and then
209 * invoke the {@link #build()} method to create an immutable instance.
211 * <em>{@code Builder} is not thread-safe and generally should not be stored in a field or
212 * collection, but instead used immediately to create instances.</em>
214 public static final class Builder {
215 private static final long INIT_BIT_NODE = 0x1L;
216 private static final long INIT_BIT_ADDRESS = 0x2L;
217 private long initBits = 0x3;
220 private String address;
225 * Fill a builder with attribute values from the provided {@code Node} instance. Regular
226 * attribute values will be replaced with those from the given instance. Absent optional
227 * values will not replace present values.
229 * @param instance The instance from which to copy values
230 * @return {@code this} builder for use in a chained invocation
232 public final Builder from(Node instance) {
233 Preconditions.checkNotNull(instance, "instance");
234 node(instance.getNode());
235 address(instance.getAddress());
240 * Initializes the value for the {@link Node#getNode() node} attribute.
242 * @param node The value for node
243 * @return {@code this} builder for use in a chained invocation
245 public final Builder node(String node) {
246 this.node = Preconditions.checkNotNull(node, "node");
247 initBits &= ~INIT_BIT_NODE;
252 * Initializes the value for the {@link Node#getAddress() address} attribute.
254 * @param address The value for address
255 * @return {@code this} builder for use in a chained invocation
257 public final Builder address(String address) {
258 this.address = Preconditions.checkNotNull(address, "address");
259 initBits &= ~INIT_BIT_ADDRESS;
264 * Builds a new {@link ImmutableNode ImmutableNode}.
266 * @return An immutable instance of Node
267 * @throws java.lang.IllegalStateException if any required attributes are missing
269 public ImmutableNode build() throws IllegalStateException {
271 throw new IllegalStateException(formatRequiredAttributesMessage());
273 return new ImmutableNode(node, address);
276 private String formatRequiredAttributesMessage() {
277 List<String> attributes = Lists.newArrayList();
278 if ((initBits & INIT_BIT_NODE) != 0)
279 attributes.add("node");
280 if ((initBits & INIT_BIT_ADDRESS) != 0)
281 attributes.add("address");
282 return "Cannot build Node, some of required attributes are not set " + attributes;