org.immutables.fixture.ImmutableSourceOrderingEntity Maven / Gradle / Ivy
package org.immutables.fixture;
import com.google.common.base.MoreObjects;
import com.google.common.base.Preconditions;
import com.google.common.collect.Lists;
import java.util.List;
import javax.annotation.Generated;
import javax.annotation.Nullable;
import javax.annotation.ParametersAreNonnullByDefault;
import javax.annotation.concurrent.Immutable;
import javax.annotation.concurrent.NotThreadSafe;
/**
* Immutable implementation of {@link SourceOrderingEntity}.
*
* Use the builder to create immutable instances:
* {@code ImmutableSourceOrderingEntity.builder()}.
*/
@SuppressWarnings("all")
@ParametersAreNonnullByDefault
@Generated({"Immutables.generator", "SourceOrderingEntity"})
@Immutable
public final class ImmutableSourceOrderingEntity extends SourceOrderingEntity {
private final int z;
private final int y;
private final int b;
private final int a;
private ImmutableSourceOrderingEntity(int z, int y, int b, int a) {
this.z = z;
this.y = y;
this.b = b;
this.a = a;
}
/**
* @return The value of the {@code z} attribute
*/
@Override
public int z() {
return z;
}
/**
* @return The value of the {@code y} attribute
*/
@Override
public int y() {
return y;
}
/**
* @return The value of the {@code b} attribute
*/
@Override
public int b() {
return b;
}
/**
* @return The value of the {@code a} attribute
*/
@Override
public int a() {
return a;
}
/**
* Copy the current immutable object by setting a value for the {@link SourceOrderingEntity#z() z} attribute.
* A value equality check is used to prevent copying of the same value by returning {@code this}.
* @param z A new value for z
* @return A modified copy of the {@code this} object
*/
public final ImmutableSourceOrderingEntity withZ(int z) {
if (this.z == z) return this;
return new ImmutableSourceOrderingEntity(z, this.y, this.b, this.a);
}
/**
* Copy the current immutable object by setting a value for the {@link SourceOrderingEntity#y() y} attribute.
* A value equality check is used to prevent copying of the same value by returning {@code this}.
* @param y A new value for y
* @return A modified copy of the {@code this} object
*/
public final ImmutableSourceOrderingEntity withY(int y) {
if (this.y == y) return this;
return new ImmutableSourceOrderingEntity(this.z, y, this.b, this.a);
}
/**
* Copy the current immutable object by setting a value for the {@link SourceOrderingEntity#b() b} attribute.
* A value equality check is used to prevent copying of the same value by returning {@code this}.
* @param b A new value for b
* @return A modified copy of the {@code this} object
*/
public final ImmutableSourceOrderingEntity withB(int b) {
if (this.b == b) return this;
return new ImmutableSourceOrderingEntity(this.z, this.y, b, this.a);
}
/**
* Copy the current immutable object by setting a value for the {@link SourceOrderingEntity#a() a} attribute.
* A value equality check is used to prevent copying of the same value by returning {@code this}.
* @param a A new value for a
* @return A modified copy of the {@code this} object
*/
public final ImmutableSourceOrderingEntity withA(int a) {
if (this.a == a) return this;
return new ImmutableSourceOrderingEntity(this.z, this.y, this.b, a);
}
/**
* This instance is equal to all instances of {@code ImmutableSourceOrderingEntity} 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 ImmutableSourceOrderingEntity
&& equalTo((ImmutableSourceOrderingEntity) another);
}
private boolean equalTo(ImmutableSourceOrderingEntity another) {
return z == another.z
&& y == another.y
&& b == another.b
&& a == another.a;
}
/**
* Computes a hash code from attributes: {@code z}, {@code y}, {@code b}, {@code a}.
* @return hashCode value
*/
@Override
public int hashCode() {
int h = 31;
h = h * 17 + z;
h = h * 17 + y;
h = h * 17 + b;
h = h * 17 + a;
return h;
}
/**
* Prints the immutable value {@code SourceOrderingEntity} with attribute values.
* @return A string representation of the value
*/
@Override
public String toString() {
return MoreObjects.toStringHelper("SourceOrderingEntity")
.omitNullValues()
.add("z", z)
.add("y", y)
.add("b", b)
.add("a", a)
.toString();
}
/**
* Creates an immutable copy of a {@link SourceOrderingEntity} 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 SourceOrderingEntity instance
*/
public static ImmutableSourceOrderingEntity copyOf(SourceOrderingEntity instance) {
if (instance instanceof ImmutableSourceOrderingEntity) {
return (ImmutableSourceOrderingEntity) instance;
}
return ImmutableSourceOrderingEntity.builder()
.from(instance)
.build();
}
/**
* Creates a builder for {@link ImmutableSourceOrderingEntity ImmutableSourceOrderingEntity}.
* @return A new ImmutableSourceOrderingEntity builder
*/
public static ImmutableSourceOrderingEntity.Builder builder() {
return new ImmutableSourceOrderingEntity.Builder();
}
/**
* Builds instances of type {@link ImmutableSourceOrderingEntity ImmutableSourceOrderingEntity}.
* 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.
*/
@NotThreadSafe
public static final class Builder {
private static final long INIT_BIT_Z = 0x1L;
private static final long INIT_BIT_Y = 0x2L;
private static final long INIT_BIT_B = 0x4L;
private static final long INIT_BIT_A = 0x8L;
private long initBits = 0xfL;
private int z;
private int y;
private int b;
private int a;
private Builder() {
}
/**
* Fill a builder with attribute values from the provided {@code org.immutables.fixture.InheritedInterface} instance.
* @param instance The instance from which to copy values
* @return {@code this} builder for use in a chained invocation
*/
public final Builder from(InheritedInterface instance) {
Preconditions.checkNotNull(instance, "instance");
from((Object) instance);
return this;
}
/**
* Fill a builder with attribute values from the provided {@code org.immutables.fixture.SourceOrderingEntity} instance.
* @param instance The instance from which to copy values
* @return {@code this} builder for use in a chained invocation
*/
public final Builder from(SourceOrderingEntity instance) {
Preconditions.checkNotNull(instance, "instance");
from((Object) instance);
return this;
}
private void from(Object object) {
if (object instanceof InheritedInterface) {
InheritedInterface instance = (InheritedInterface) object;
a(instance.a());
b(instance.b());
}
if (object instanceof SourceOrderingEntity) {
SourceOrderingEntity instance = (SourceOrderingEntity) object;
y(instance.y());
z(instance.z());
}
}
/**
* Initializes the value for the {@link SourceOrderingEntity#z() z} attribute.
* @param z The value for z
* @return {@code this} builder for use in a chained invocation
*/
public final Builder z(int z) {
this.z = z;
initBits &= ~INIT_BIT_Z;
return this;
}
/**
* Initializes the value for the {@link SourceOrderingEntity#y() y} attribute.
* @param y The value for y
* @return {@code this} builder for use in a chained invocation
*/
public final Builder y(int y) {
this.y = y;
initBits &= ~INIT_BIT_Y;
return this;
}
/**
* Initializes the value for the {@link SourceOrderingEntity#b() b} attribute.
* @param b The value for b
* @return {@code this} builder for use in a chained invocation
*/
public final Builder b(int b) {
this.b = b;
initBits &= ~INIT_BIT_B;
return this;
}
/**
* Initializes the value for the {@link SourceOrderingEntity#a() a} attribute.
* @param a The value for a
* @return {@code this} builder for use in a chained invocation
*/
public final Builder a(int a) {
this.a = a;
initBits &= ~INIT_BIT_A;
return this;
}
/**
* Builds a new {@link ImmutableSourceOrderingEntity ImmutableSourceOrderingEntity}.
* @return An immutable instance of SourceOrderingEntity
* @throws java.lang.IllegalStateException if any required attributes are missing
*/
public ImmutableSourceOrderingEntity build() {
if (initBits != 0) {
throw new IllegalStateException(formatRequiredAttributesMessage());
}
return new ImmutableSourceOrderingEntity(z, y, b, a);
}
private String formatRequiredAttributesMessage() {
List attributes = Lists.newArrayList();
if ((initBits & INIT_BIT_Z) != 0) attributes.add("z");
if ((initBits & INIT_BIT_Y) != 0) attributes.add("y");
if ((initBits & INIT_BIT_B) != 0) attributes.add("b");
if ((initBits & INIT_BIT_A) != 0) attributes.add("a");
return "Cannot build SourceOrderingEntity, some of required attributes are not set " + attributes;
}
}
}