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

org.cloudfoundry.client.lib.domain.ImmutableInstanceInfo Maven / Gradle / Ivy

The newest version!
package org.cloudfoundry.client.lib.domain;

import com.fasterxml.jackson.annotation.JsonAutoDetect;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import org.immutables.value.Generated;

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

* Use the builder to create immutable instances: * {@code ImmutableInstanceInfo.builder()}. */ @Generated(from = "InstanceInfo", generator = "Immutables") @SuppressWarnings({"all"}) @javax.annotation.processing.Generated("org.immutables.processor.ProxyProcessor") public final class ImmutableInstanceInfo implements InstanceInfo { private final int index; private final InstanceState state; private ImmutableInstanceInfo(int index, InstanceState state) { this.index = index; this.state = state; } /** * @return The value of the {@code index} attribute */ @JsonProperty("index") @Override public int getIndex() { return index; } /** * @return The value of the {@code state} attribute */ @JsonProperty("state") @Override public InstanceState getState() { return state; } /** * Copy the current immutable object by setting a value for the {@link InstanceInfo#getIndex() index} attribute. * A value equality check is used to prevent copying of the same value by returning {@code this}. * @param value A new value for index * @return A modified copy of the {@code this} object */ public final ImmutableInstanceInfo withIndex(int value) { if (this.index == value) return this; return new ImmutableInstanceInfo(value, this.state); } /** * Copy the current immutable object by setting a value for the {@link InstanceInfo#getState() state} attribute. * A value equality check is used to prevent copying of the same value by returning {@code this}. * @param value A new value for state * @return A modified copy of the {@code this} object */ public final ImmutableInstanceInfo withState(InstanceState value) { if (this.state == value) return this; InstanceState newValue = Objects.requireNonNull(value, "state"); if (this.state.equals(newValue)) return this; return new ImmutableInstanceInfo(this.index, newValue); } /** * This instance is equal to all instances of {@code ImmutableInstanceInfo} that have equal attribute values. * @return {@code true} if {@code this} is equal to {@code another} instance */ @Override public boolean equals(Object another) { if (this == another) return true; return another instanceof ImmutableInstanceInfo && equalTo((ImmutableInstanceInfo) another); } private boolean equalTo(ImmutableInstanceInfo another) { return index == another.index && state.equals(another.state); } /** * Computes a hash code from attributes: {@code index}, {@code state}. * @return hashCode value */ @Override public int hashCode() { int h = 5381; h += (h << 5) + index; h += (h << 5) + state.hashCode(); return h; } /** * Prints the immutable value {@code InstanceInfo} with attribute values. * @return A string representation of the value */ @Override public String toString() { return "InstanceInfo{" + "index=" + index + ", state=" + state + "}"; } /** * 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 = "InstanceInfo", generator = "Immutables") @Deprecated @JsonDeserialize @JsonAutoDetect(fieldVisibility = JsonAutoDetect.Visibility.NONE) static final class Json implements InstanceInfo { int index; boolean indexIsSet; InstanceState state; @JsonProperty("index") public void setIndex(int index) { this.index = index; this.indexIsSet = true; } @JsonProperty("state") public void setState(InstanceState state) { this.state = state; } @Override public int getIndex() { throw new UnsupportedOperationException(); } @Override public InstanceState getState() { 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 ImmutableInstanceInfo fromJson(Json json) { ImmutableInstanceInfo.Builder builder = ImmutableInstanceInfo.builder(); if (json.indexIsSet) { builder.index(json.index); } if (json.state != null) { builder.state(json.state); } return builder.build(); } /** * Creates an immutable copy of a {@link InstanceInfo} 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 InstanceInfo instance */ public static ImmutableInstanceInfo copyOf(InstanceInfo instance) { if (instance instanceof ImmutableInstanceInfo) { return (ImmutableInstanceInfo) instance; } return ImmutableInstanceInfo.builder() .from(instance) .build(); } /** * Creates a builder for {@link ImmutableInstanceInfo ImmutableInstanceInfo}. *

   * ImmutableInstanceInfo.builder()
   *    .index(int) // required {@link InstanceInfo#getIndex() index}
   *    .state(org.cloudfoundry.client.lib.domain.InstanceState) // required {@link InstanceInfo#getState() state}
   *    .build();
   * 
* @return A new ImmutableInstanceInfo builder */ public static ImmutableInstanceInfo.Builder builder() { return new ImmutableInstanceInfo.Builder(); } /** * Builds instances of type {@link ImmutableInstanceInfo ImmutableInstanceInfo}. * 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 = "InstanceInfo", generator = "Immutables") public static final class Builder { private static final long INIT_BIT_INDEX = 0x1L; private static final long INIT_BIT_STATE = 0x2L; private long initBits = 0x3L; private int index; private InstanceState state; private Builder() { } /** * Fill a builder with attribute values from the provided {@code InstanceInfo} instance. * Regular attribute values will be replaced with those from the given instance. * Absent optional values will not replace present values. * @param instance The instance from which to copy values * @return {@code this} builder for use in a chained invocation */ public final Builder from(InstanceInfo instance) { Objects.requireNonNull(instance, "instance"); index(instance.getIndex()); state(instance.getState()); return this; } /** * Initializes the value for the {@link InstanceInfo#getIndex() index} attribute. * @param index The value for index * @return {@code this} builder for use in a chained invocation */ @JsonProperty("index") public final Builder index(int index) { this.index = index; initBits &= ~INIT_BIT_INDEX; return this; } /** * Initializes the value for the {@link InstanceInfo#getState() state} attribute. * @param state The value for state * @return {@code this} builder for use in a chained invocation */ @JsonProperty("state") public final Builder state(InstanceState state) { this.state = Objects.requireNonNull(state, "state"); initBits &= ~INIT_BIT_STATE; return this; } /** * Builds a new {@link ImmutableInstanceInfo ImmutableInstanceInfo}. * @return An immutable instance of InstanceInfo * @throws java.lang.IllegalStateException if any required attributes are missing */ public ImmutableInstanceInfo build() { if (initBits != 0) { throw new IllegalStateException(formatRequiredAttributesMessage()); } return new ImmutableInstanceInfo(index, state); } private String formatRequiredAttributesMessage() { List attributes = new ArrayList<>(); if ((initBits & INIT_BIT_INDEX) != 0) attributes.add("index"); if ((initBits & INIT_BIT_STATE) != 0) attributes.add("state"); return "Cannot build InstanceInfo, some of required attributes are not set " + attributes; } } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy