org.immutables.fixture.ImmutableSing2 Maven / Gradle / Ivy
package org.immutables.fixture;
import com.google.common.base.MoreObjects;
import javax.annotation.Generated;
import javax.annotation.Nullable;
import javax.annotation.ParametersAreNonnullByDefault;
import javax.annotation.concurrent.Immutable;
/**
* Immutable implementation of {@link Sing2}.
*
* Use the static factory method to get the default singleton instance:
* {@code ImmutableSing2.of()}.
*/
@SuppressWarnings("all")
@ParametersAreNonnullByDefault
@Generated({"Immutables.generator", "Sing2"})
@Immutable
final class ImmutableSing2 implements Sing2 {
private final int a;
private ImmutableSing2() {
this.a = Sing2.super.a();
}
private ImmutableSing2(int a) {
this.a = a;
}
/**
* @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 Sing2#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 ImmutableSing2 withA(int a) {
if (this.a == a) return this;
return validate(new ImmutableSing2(a));
}
/**
* This instance is equal to all instances of {@code ImmutableSing2} 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 ImmutableSing2
&& equalTo((ImmutableSing2) another);
}
private boolean equalTo(ImmutableSing2 another) {
return a == another.a;
}
/**
* Computes a hash code from attributes: {@code a}.
* @return hashCode value
*/
@Override
public int hashCode() {
int h = 31;
h = h * 17 + a;
return h;
}
/**
* Prints the immutable value {@code Sing2} with attribute values.
* @return A string representation of the value
*/
@Override
public String toString() {
return MoreObjects.toStringHelper("Sing2")
.omitNullValues()
.add("a", a)
.toString();
}
private static final ImmutableSing2 INSTANCE = validate(new ImmutableSing2());
/**
* Returns the default immutable singleton value of {@code Sing2}
* @return An immutable instance of Sing2
*/
public static ImmutableSing2 of() {
return INSTANCE;
}
private static ImmutableSing2 validate(ImmutableSing2 instance) {
return INSTANCE != null && INSTANCE.equalTo(instance) ? INSTANCE : instance;
}
}