All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.kiwiproject.consul.model.health.ImmutableServiceHealth Maven / Gradle / Ivy

package org.kiwiproject.consul.model.health;

import com.fasterxml.jackson.annotation.JsonAutoDetect;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.google.common.base.MoreObjects;
import com.google.common.collect.ImmutableList;
import com.google.errorprone.annotations.CanIgnoreReturnValue;
import com.google.errorprone.annotations.Var;
import jakarta.annotation.Nullable;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import org.immutables.value.Generated;

/**
 * Immutable implementation of {@link ServiceHealth}.
 * 

* Use the builder to create immutable instances: * {@code ImmutableServiceHealth.builder()}. */ @Generated(from = "ServiceHealth", generator = "Immutables") @SuppressWarnings({"all"}) @javax.annotation.processing.Generated("org.immutables.processor.ProxyProcessor") @JsonIgnoreProperties(ignoreUnknown = true) public final class ImmutableServiceHealth extends ServiceHealth { private final Node node; private final Service service; private final ImmutableList checks; private ImmutableServiceHealth( Node node, Service service, ImmutableList checks) { this.node = node; this.service = service; this.checks = checks; } /** * @return The value of the {@code node} attribute */ @JsonProperty("Node") @Override public Node getNode() { return node; } /** * @return The value of the {@code service} attribute */ @JsonProperty("Service") @Override public Service getService() { return service; } /** * @return The value of the {@code checks} attribute */ @JsonProperty("Checks") @JsonDeserialize(as = ImmutableList.class, contentAs = HealthCheck.class) @Override public ImmutableList getChecks() { return checks; } /** * Copy the current immutable object by setting a value for the {@link ServiceHealth#getNode() node} attribute. * A shallow reference equality check is used to prevent copying of the same value by returning {@code this}. * @param value A new value for node * @return A modified copy of the {@code this} object */ public final ImmutableServiceHealth withNode(Node value) { if (this.node == value) return this; Node newValue = Objects.requireNonNull(value, "node"); return new ImmutableServiceHealth(newValue, this.service, this.checks); } /** * Copy the current immutable object by setting a value for the {@link ServiceHealth#getService() service} attribute. * A shallow reference equality check is used to prevent copying of the same value by returning {@code this}. * @param value A new value for service * @return A modified copy of the {@code this} object */ public final ImmutableServiceHealth withService(Service value) { if (this.service == value) return this; Service newValue = Objects.requireNonNull(value, "service"); return new ImmutableServiceHealth(this.node, newValue, this.checks); } /** * Copy the current immutable object with elements that replace the content of {@link ServiceHealth#getChecks() checks}. * @param elements The elements to set * @return A modified copy of {@code this} object */ public final ImmutableServiceHealth withChecks(HealthCheck... elements) { ImmutableList newValue = ImmutableList.copyOf(elements); return new ImmutableServiceHealth(this.node, this.service, newValue); } /** * Copy the current immutable object with elements that replace the content of {@link ServiceHealth#getChecks() checks}. * A shallow reference equality check is used to prevent copying of the same value by returning {@code this}. * @param elements An iterable of checks elements to set * @return A modified copy of {@code this} object */ public final ImmutableServiceHealth withChecks(Iterable elements) { if (this.checks == elements) return this; ImmutableList newValue = ImmutableList.copyOf(elements); return new ImmutableServiceHealth(this.node, this.service, newValue); } /** * This instance is equal to all instances of {@code ImmutableServiceHealth} that have equal attribute values. * @return {@code true} if {@code this} is equal to {@code another} instance */ @Override public boolean equals(@Nullable Object another) { if (this == another) return true; return another instanceof ImmutableServiceHealth && equalTo(0, (ImmutableServiceHealth) another); } private boolean equalTo(int synthetic, ImmutableServiceHealth another) { return node.equals(another.node) && service.equals(another.service) && checks.equals(another.checks); } /** * Computes a hash code from attributes: {@code node}, {@code service}, {@code checks}. * @return hashCode value */ @Override public int hashCode() { @Var int h = 5381; h += (h << 5) + node.hashCode(); h += (h << 5) + service.hashCode(); h += (h << 5) + checks.hashCode(); return h; } /** * Prints the immutable value {@code ServiceHealth} with attribute values. * @return A string representation of the value */ @Override public String toString() { return MoreObjects.toStringHelper("ServiceHealth") .omitNullValues() .add("node", node) .add("service", service) .add("checks", checks) .toString(); } /** * Utility type used to correctly read immutable object from JSON representation. * @deprecated Do not use this type directly, it exists only for the Jackson-binding infrastructure */ @Generated(from = "ServiceHealth", generator = "Immutables") @Deprecated @SuppressWarnings("Immutable") @JsonDeserialize @JsonAutoDetect(fieldVisibility = JsonAutoDetect.Visibility.NONE) static final class Json extends ServiceHealth { @Nullable Node node; @Nullable Service service; @Nullable List checks = ImmutableList.of(); @JsonProperty("Node") public void setNode(Node node) { this.node = node; } @JsonProperty("Service") public void setService(Service service) { this.service = service; } @JsonProperty("Checks") @JsonDeserialize(as = ImmutableList.class, contentAs = HealthCheck.class) public void setChecks(List checks) { this.checks = checks; } @Override public Node getNode() { throw new UnsupportedOperationException(); } @Override public Service getService() { throw new UnsupportedOperationException(); } @Override public List getChecks() { throw new UnsupportedOperationException(); } } /** * @param json A JSON-bindable data structure * @return An immutable value type * @deprecated Do not use this method directly, it exists only for the Jackson-binding infrastructure */ @Deprecated @JsonCreator(mode = JsonCreator.Mode.DELEGATING) static ImmutableServiceHealth fromJson(Json json) { ImmutableServiceHealth.Builder builder = ImmutableServiceHealth.builder(); if (json.node != null) { builder.node(json.node); } if (json.service != null) { builder.service(json.service); } if (json.checks != null) { builder.addAllChecks(json.checks); } return builder.build(); } /** * Creates an immutable copy of a {@link ServiceHealth} value. * Uses accessors to get values to initialize the new immutable instance. * If an instance is already immutable, it is returned as is. * @param instance The instance to copy * @return A copied immutable ServiceHealth instance */ public static ImmutableServiceHealth copyOf(ServiceHealth instance) { if (instance instanceof ImmutableServiceHealth) { return (ImmutableServiceHealth) instance; } return ImmutableServiceHealth.builder() .from(instance) .build(); } /** * Creates a builder for {@link ImmutableServiceHealth ImmutableServiceHealth}. *

   * ImmutableServiceHealth.builder()
   *    .node(org.kiwiproject.consul.model.health.Node) // required {@link ServiceHealth#getNode() node}
   *    .service(org.kiwiproject.consul.model.health.Service) // required {@link ServiceHealth#getService() service}
   *    .addChecks|addAllChecks(org.kiwiproject.consul.model.health.HealthCheck) // {@link ServiceHealth#getChecks() checks} elements
   *    .build();
   * 
* @return A new ImmutableServiceHealth builder */ public static ImmutableServiceHealth.Builder builder() { return new ImmutableServiceHealth.Builder(); } /** * Builds instances of type {@link ImmutableServiceHealth ImmutableServiceHealth}. * Initialize attributes and then invoke the {@link #build()} method to create an * immutable instance. *

{@code Builder} is not thread-safe and generally should not be stored in a field or collection, * but instead used immediately to create instances. */ @Generated(from = "ServiceHealth", generator = "Immutables") public static final class Builder { private static final long INIT_BIT_NODE = 0x1L; private static final long INIT_BIT_SERVICE = 0x2L; private long initBits = 0x3L; private @Nullable Node node; private @Nullable Service service; private ImmutableList.Builder checks = ImmutableList.builder(); private Builder() { } /** * Fill a builder with attribute values from the provided {@code ServiceHealth} instance. * Regular attribute values will be replaced with those from the given instance. * Absent optional values will not replace present values. * Collection elements and entries will be added, not replaced. * @param instance The instance from which to copy values * @return {@code this} builder for use in a chained invocation */ @CanIgnoreReturnValue public final Builder from(ServiceHealth instance) { Objects.requireNonNull(instance, "instance"); node(instance.getNode()); service(instance.getService()); addAllChecks(instance.getChecks()); return this; } /** * Initializes the value for the {@link ServiceHealth#getNode() node} attribute. * @param node The value for node * @return {@code this} builder for use in a chained invocation */ @CanIgnoreReturnValue @JsonProperty("Node") public final Builder node(Node node) { this.node = Objects.requireNonNull(node, "node"); initBits &= ~INIT_BIT_NODE; return this; } /** * Initializes the value for the {@link ServiceHealth#getService() service} attribute. * @param service The value for service * @return {@code this} builder for use in a chained invocation */ @CanIgnoreReturnValue @JsonProperty("Service") public final Builder service(Service service) { this.service = Objects.requireNonNull(service, "service"); initBits &= ~INIT_BIT_SERVICE; return this; } /** * Adds one element to {@link ServiceHealth#getChecks() checks} list. * @param element A checks element * @return {@code this} builder for use in a chained invocation */ @CanIgnoreReturnValue public final Builder addChecks(HealthCheck element) { this.checks.add(element); return this; } /** * Adds elements to {@link ServiceHealth#getChecks() checks} list. * @param elements An array of checks elements * @return {@code this} builder for use in a chained invocation */ @CanIgnoreReturnValue public final Builder addChecks(HealthCheck... elements) { this.checks.add(elements); return this; } /** * Sets or replaces all elements for {@link ServiceHealth#getChecks() checks} list. * @param elements An iterable of checks elements * @return {@code this} builder for use in a chained invocation */ @CanIgnoreReturnValue @JsonProperty("Checks") @JsonDeserialize(as = ImmutableList.class, contentAs = HealthCheck.class) public final Builder checks(Iterable elements) { this.checks = ImmutableList.builder(); return addAllChecks(elements); } /** * Adds elements to {@link ServiceHealth#getChecks() checks} list. * @param elements An iterable of checks elements * @return {@code this} builder for use in a chained invocation */ @CanIgnoreReturnValue public final Builder addAllChecks(Iterable elements) { this.checks.addAll(elements); return this; } /** * Builds a new {@link ImmutableServiceHealth ImmutableServiceHealth}. * @return An immutable instance of ServiceHealth * @throws java.lang.IllegalStateException if any required attributes are missing */ public ImmutableServiceHealth build() { if (initBits != 0) { throw new IllegalStateException(formatRequiredAttributesMessage()); } return new ImmutableServiceHealth(node, service, checks.build()); } private String formatRequiredAttributesMessage() { List attributes = new ArrayList<>(); if ((initBits & INIT_BIT_NODE) != 0) attributes.add("node"); if ((initBits & INIT_BIT_SERVICE) != 0) attributes.add("service"); return "Cannot build ServiceHealth, some of required attributes are not set " + attributes; } } }





© 2015 - 2025 Weber Informatics LLC | Privacy Policy