com.vrbo.jarviz.model.ImmutableShadowClass Maven / Gradle / Ivy
package com.vrbo.jarviz.model;
import com.fasterxml.jackson.annotation.JsonAutoDetect;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonIgnore;
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.Arrays;
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 ShadowClass}.
*
* Use the builder to create immutable instances:
* {@code new ShadowClass.Builder()}.
*/
@Generated(from = "ShadowClass", generator = "Immutables")
@SuppressWarnings({"all"})
@ParametersAreNonnullByDefault
@javax.annotation.Generated("org.immutables.processor.ProxyProcessor")
@Immutable
@CheckReturnValue
final class ImmutableShadowClass implements ShadowClass {
private final String className;
private final byte[] classBytes;
private ImmutableShadowClass(ImmutableShadowClass.Builder builder) {
this.className = builder.className;
this.classBytes = builder.classBytes != null
? builder.classBytes
: ShadowClass.super.getClassBytes().clone();
}
private ImmutableShadowClass(String className, byte[] classBytes) {
this.className = className;
this.classBytes = classBytes;
}
/**
* @return The value of the {@code className} attribute
*/
@JsonProperty("className")
@Override
public String getClassName() {
return className;
}
/**
* @return A cloned {@code classBytes} array
*/
@JsonProperty("classBytes")
@JsonIgnore
@Override
public byte[] getClassBytes() {
return classBytes.clone();
}
/**
* Copy the current immutable object by setting a value for the {@link ShadowClass#getClassName() className} attribute.
* An equals check used to prevent copying of the same value by returning {@code this}.
* @param value A new value for className
* @return A modified copy of the {@code this} object
*/
public final ImmutableShadowClass withClassName(String value) {
String newValue = Objects.requireNonNull(value, "className");
if (this.className.equals(newValue)) return this;
return new ImmutableShadowClass(newValue, this.classBytes);
}
/**
* Copy the current immutable object with elements that replace the content of {@link ShadowClass#getClassBytes() classBytes}.
* The array is cloned before being saved as attribute values.
* @param elements The non-null elements for classBytes
* @return A modified copy of {@code this} object
*/
public final ImmutableShadowClass withClassBytes(byte... elements) {
byte[] newValue = elements.clone();
return new ImmutableShadowClass(this.className, newValue);
}
/**
* This instance is equal to all instances of {@code ImmutableShadowClass} 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 ImmutableShadowClass
&& equalTo((ImmutableShadowClass) another);
}
private boolean equalTo(ImmutableShadowClass another) {
return className.equals(another.className)
&& Arrays.equals(classBytes, another.classBytes);
}
/**
* Computes a hash code from attributes: {@code className}, {@code classBytes}.
* @return hashCode value
*/
@Override
public int hashCode() {
@Var int h = 5381;
h += (h << 5) + className.hashCode();
h += (h << 5) + Arrays.hashCode(classBytes);
return h;
}
/**
* Prints the immutable value {@code ShadowClass} with attribute values.
* @return A string representation of the value
*/
@Override
public String toString() {
return MoreObjects.toStringHelper("ShadowClass")
.omitNullValues()
.add("className", className)
.add("classBytes", "####")
.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 = "ShadowClass", generator = "Immutables")
@Deprecated
@SuppressWarnings("Immutable")
@JsonDeserialize
@JsonAutoDetect(fieldVisibility = JsonAutoDetect.Visibility.NONE)
static final class Json implements ShadowClass {
@Nullable String className;
@Nullable byte[] classBytes;
@JsonProperty("className")
public void setClassName(String className) {
this.className = className;
}
@JsonProperty("classBytes")
@JsonIgnore
public void setClassBytes(byte[] classBytes) {
this.classBytes = classBytes;
}
@Override
public String getClassName() { throw new UnsupportedOperationException(); }
@Override
public byte[] getClassBytes() { 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 ImmutableShadowClass fromJson(Json json) {
ShadowClass.Builder builder = new ShadowClass.Builder();
if (json.className != null) {
builder.className(json.className);
}
if (json.classBytes != null) {
builder.classBytes(json.classBytes);
}
return (ImmutableShadowClass) builder.build();
}
/**
* Creates an immutable copy of a {@link ShadowClass} 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 ShadowClass instance
*/
public static ImmutableShadowClass copyOf(ShadowClass instance) {
if (instance instanceof ImmutableShadowClass) {
return (ImmutableShadowClass) instance;
}
return new ShadowClass.Builder()
.from(instance)
.build();
}
/**
* Builds instances of type {@link ImmutableShadowClass ImmutableShadowClass}.
* 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 = "ShadowClass", generator = "Immutables")
@NotThreadSafe
static class Builder {
private static final long INIT_BIT_CLASS_NAME = 0x1L;
private long initBits = 0x1L;
private @Nullable String className;
private @Nullable byte[] classBytes;
/**
* Creates a builder for {@link ImmutableShadowClass ImmutableShadowClass} instances.
*
* new ShadowClass.Builder()
* .className(String) // required {@link ShadowClass#getClassName() className}
* .classBytes(byte) // optional {@link ShadowClass#getClassBytes() classBytes}
* .build();
*
*/
Builder() {
if (!(this instanceof ShadowClass.Builder)) {
throw new UnsupportedOperationException("Use: new ShadowClass.Builder()");
}
}
/**
* Fill a builder with attribute values from the provided {@code ShadowClass} 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 ShadowClass.Builder from(ShadowClass instance) {
Objects.requireNonNull(instance, "instance");
className(instance.getClassName());
classBytes(instance.getClassBytes());
return (ShadowClass.Builder) this;
}
/**
* Initializes the value for the {@link ShadowClass#getClassName() className} attribute.
* @param className The value for className
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
@JsonProperty("className")
public final ShadowClass.Builder className(String className) {
this.className = Objects.requireNonNull(className, "className");
initBits &= ~INIT_BIT_CLASS_NAME;
return (ShadowClass.Builder) this;
}
/**
* Initializes the value for the {@link ShadowClass#getClassBytes() classBytes} attribute.
* If not set, this attribute will have a default value as defined by {@link ShadowClass#getClassBytes() classBytes}.
* @param classBytes The elements for classBytes
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
@JsonProperty("classBytes")
@JsonIgnore
public final ShadowClass.Builder classBytes(byte... classBytes) {
this.classBytes = classBytes.clone();
return (ShadowClass.Builder) this;
}
/**
* Builds a new {@link ImmutableShadowClass ImmutableShadowClass}.
* @return An immutable instance of ShadowClass
* @throws java.lang.IllegalStateException if any required attributes are missing
*/
public ImmutableShadowClass build() {
if (initBits != 0) {
throw new IllegalStateException(formatRequiredAttributesMessage());
}
return new ImmutableShadowClass(this);
}
private String formatRequiredAttributesMessage() {
List attributes = new ArrayList<>();
if ((initBits & INIT_BIT_CLASS_NAME) != 0) attributes.add("className");
return "Cannot build ShadowClass, some of required attributes are not set " + attributes;
}
}
}