io.resys.hdes.client.api.ImmutableDiffRequest Maven / Gradle / Ivy
package io.resys.hdes.client.api;
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 com.google.common.base.MoreObjects;
import com.google.errorprone.annotations.CanIgnoreReturnValue;
import com.google.errorprone.annotations.Var;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import javax.annotation.CheckReturnValue;
import javax.annotation.Nullable;
import javax.annotation.ParametersAreNonnullByDefault;
import javax.annotation.concurrent.Immutable;
import javax.annotation.concurrent.NotThreadSafe;
import org.immutables.value.Generated;
/**
* Immutable implementation of {@link HdesComposer.DiffRequest}.
*
* Use the builder to create immutable instances:
* {@code ImmutableDiffRequest.builder()}.
*/
@Generated(from = "HdesComposer.DiffRequest", generator = "Immutables")
@SuppressWarnings({"all"})
@ParametersAreNonnullByDefault
@javax.annotation.processing.Generated("org.immutables.processor.ProxyProcessor")
@Immutable
@CheckReturnValue
public final class ImmutableDiffRequest implements HdesComposer.DiffRequest {
private final String baseId;
private final String targetId;
private ImmutableDiffRequest(String baseId, String targetId) {
this.baseId = baseId;
this.targetId = targetId;
}
/**
* @return The value of the {@code baseId} attribute
*/
@JsonProperty("baseId")
@Override
public String getBaseId() {
return baseId;
}
/**
* @return The value of the {@code targetId} attribute
*/
@JsonProperty("targetId")
@Override
public String getTargetId() {
return targetId;
}
/**
* Copy the current immutable object by setting a value for the {@link HdesComposer.DiffRequest#getBaseId() baseId} attribute.
* An equals check used to prevent copying of the same value by returning {@code this}.
* @param value A new value for baseId
* @return A modified copy of the {@code this} object
*/
public final ImmutableDiffRequest withBaseId(String value) {
String newValue = Objects.requireNonNull(value, "baseId");
if (this.baseId.equals(newValue)) return this;
return new ImmutableDiffRequest(newValue, this.targetId);
}
/**
* Copy the current immutable object by setting a value for the {@link HdesComposer.DiffRequest#getTargetId() targetId} attribute.
* An equals check used to prevent copying of the same value by returning {@code this}.
* @param value A new value for targetId
* @return A modified copy of the {@code this} object
*/
public final ImmutableDiffRequest withTargetId(String value) {
String newValue = Objects.requireNonNull(value, "targetId");
if (this.targetId.equals(newValue)) return this;
return new ImmutableDiffRequest(this.baseId, newValue);
}
/**
* This instance is equal to all instances of {@code ImmutableDiffRequest} 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 ImmutableDiffRequest
&& equalTo((ImmutableDiffRequest) another);
}
private boolean equalTo(ImmutableDiffRequest another) {
return baseId.equals(another.baseId)
&& targetId.equals(another.targetId);
}
/**
* Computes a hash code from attributes: {@code baseId}, {@code targetId}.
* @return hashCode value
*/
@Override
public int hashCode() {
@Var int h = 5381;
h += (h << 5) + baseId.hashCode();
h += (h << 5) + targetId.hashCode();
return h;
}
/**
* Prints the immutable value {@code DiffRequest} with attribute values.
* @return A string representation of the value
*/
@Override
public String toString() {
return MoreObjects.toStringHelper("DiffRequest")
.omitNullValues()
.add("baseId", baseId)
.add("targetId", targetId)
.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 = "HdesComposer.DiffRequest", generator = "Immutables")
@Deprecated
@SuppressWarnings("Immutable")
@JsonDeserialize
@JsonAutoDetect(fieldVisibility = JsonAutoDetect.Visibility.NONE)
static final class Json implements HdesComposer.DiffRequest {
@Nullable String baseId;
@Nullable String targetId;
@JsonProperty("baseId")
public void setBaseId(String baseId) {
this.baseId = baseId;
}
@JsonProperty("targetId")
public void setTargetId(String targetId) {
this.targetId = targetId;
}
@Override
public String getBaseId() { throw new UnsupportedOperationException(); }
@Override
public String getTargetId() { 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 ImmutableDiffRequest fromJson(Json json) {
ImmutableDiffRequest.Builder builder = ImmutableDiffRequest.builder();
if (json.baseId != null) {
builder.baseId(json.baseId);
}
if (json.targetId != null) {
builder.targetId(json.targetId);
}
return builder.build();
}
/**
* Creates an immutable copy of a {@link HdesComposer.DiffRequest} 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 DiffRequest instance
*/
public static ImmutableDiffRequest copyOf(HdesComposer.DiffRequest instance) {
if (instance instanceof ImmutableDiffRequest) {
return (ImmutableDiffRequest) instance;
}
return ImmutableDiffRequest.builder()
.from(instance)
.build();
}
/**
* Creates a builder for {@link ImmutableDiffRequest ImmutableDiffRequest}.
*
* ImmutableDiffRequest.builder()
* .baseId(String) // required {@link HdesComposer.DiffRequest#getBaseId() baseId}
* .targetId(String) // required {@link HdesComposer.DiffRequest#getTargetId() targetId}
* .build();
*
* @return A new ImmutableDiffRequest builder
*/
public static ImmutableDiffRequest.Builder builder() {
return new ImmutableDiffRequest.Builder();
}
/**
* Builds instances of type {@link ImmutableDiffRequest ImmutableDiffRequest}.
* 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 = "HdesComposer.DiffRequest", generator = "Immutables")
@NotThreadSafe
public static final class Builder {
private static final long INIT_BIT_BASE_ID = 0x1L;
private static final long INIT_BIT_TARGET_ID = 0x2L;
private long initBits = 0x3L;
private @Nullable String baseId;
private @Nullable String targetId;
private Builder() {
}
/**
* Fill a builder with attribute values from the provided {@code DiffRequest} 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
*/
@CanIgnoreReturnValue
public final Builder from(HdesComposer.DiffRequest instance) {
Objects.requireNonNull(instance, "instance");
baseId(instance.getBaseId());
targetId(instance.getTargetId());
return this;
}
/**
* Initializes the value for the {@link HdesComposer.DiffRequest#getBaseId() baseId} attribute.
* @param baseId The value for baseId
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
@JsonProperty("baseId")
public final Builder baseId(String baseId) {
this.baseId = Objects.requireNonNull(baseId, "baseId");
initBits &= ~INIT_BIT_BASE_ID;
return this;
}
/**
* Initializes the value for the {@link HdesComposer.DiffRequest#getTargetId() targetId} attribute.
* @param targetId The value for targetId
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
@JsonProperty("targetId")
public final Builder targetId(String targetId) {
this.targetId = Objects.requireNonNull(targetId, "targetId");
initBits &= ~INIT_BIT_TARGET_ID;
return this;
}
/**
* Builds a new {@link ImmutableDiffRequest ImmutableDiffRequest}.
* @return An immutable instance of DiffRequest
* @throws java.lang.IllegalStateException if any required attributes are missing
*/
public ImmutableDiffRequest build() {
if (initBits != 0) {
throw new IllegalStateException(formatRequiredAttributesMessage());
}
return new ImmutableDiffRequest(baseId, targetId);
}
private String formatRequiredAttributesMessage() {
List attributes = new ArrayList<>();
if ((initBits & INIT_BIT_BASE_ID) != 0) attributes.add("baseId");
if ((initBits & INIT_BIT_TARGET_ID) != 0) attributes.add("targetId");
return "Cannot build DiffRequest, some of required attributes are not set " + attributes;
}
}
}