org.immutables.fixture.ImmutableProperInitInternNoBuilder Maven / Gradle / Ivy
package org.immutables.fixture;
import com.google.common.base.MoreObjects;
import com.google.common.collect.Interner;
import com.google.common.collect.Interners;
import javax.annotation.Generated;
import javax.annotation.Nullable;
import javax.annotation.ParametersAreNonnullByDefault;
import javax.annotation.concurrent.Immutable;
/**
* Immutable implementation of {@link ProperInitInternNoBuilder}.
*
* Use the static factory method to get the default singleton instance:
* {@code ImmutableProperInitInternNoBuilder.of()}.
*/
@SuppressWarnings("all")
@ParametersAreNonnullByDefault
@Generated({"Immutables.generator", "ProperInitInternNoBuilder"})
@Immutable
public final class ImmutableProperInitInternNoBuilder
implements ProperInitInternNoBuilder {
private final int x;
private ImmutableProperInitInternNoBuilder() {
this.x = ProperInitInternNoBuilder.super.x();
}
private ImmutableProperInitInternNoBuilder(int x) {
this.x = x;
}
/**
* @return The value of the {@code x} attribute
*/
@Override
public int x() {
return x;
}
/**
* Copy the current immutable object by setting a value for the {@link ProperInitInternNoBuilder#x() x} attribute.
* A value equality check is used to prevent copying of the same value by returning {@code this}.
* @param x A new value for x
* @return A modified copy of the {@code this} object
*/
public final ImmutableProperInitInternNoBuilder withX(int x) {
if (this.x == x) return this;
return validate(new ImmutableProperInitInternNoBuilder(x));
}
/**
* This instance is equal to all instances of {@code ImmutableProperInitInternNoBuilder} that have equal attribute values.
* As instances of the {@code ImmutableProperInitInternNoBuilder} class are interned, the {@code equals} method is implemented
* as an efficient reference equality check.
* @return {@code true} if {@code this} is equal to {@code another} instance
*/
@Override
public boolean equals(@Nullable Object another) {
return this == another;
}
private boolean equalTo(ImmutableProperInitInternNoBuilder another) {
return x == another.x;
}
/**
* Computes a hash code from attributes: {@code x}.
* @return hashCode value
*/
@Override
public int hashCode() {
int h = 31;
h = h * 17 + x;
return h;
}
/**
* Prints the immutable value {@code ProperInitInternNoBuilder} with attribute values.
* @return A string representation of the value
*/
@Override
public String toString() {
return MoreObjects.toStringHelper("ProperInitInternNoBuilder")
.omitNullValues()
.add("x", x)
.toString();
}
private static class InternProxy {
final ImmutableProperInitInternNoBuilder instance;
InternProxy(ImmutableProperInitInternNoBuilder instance) {
this.instance = instance;
}
@Override
public boolean equals(@Nullable Object another) {
return instance.equalTo(((InternProxy) another).instance);
}
@Override
public int hashCode() {
return instance.hashCode();
}
}
private static final Interner INTERNER = Interners.newStrongInterner();
private static final ImmutableProperInitInternNoBuilder INSTANCE = validate(new ImmutableProperInitInternNoBuilder());
/**
* Returns the default immutable singleton value of {@code ProperInitInternNoBuilder}
* @return An immutable instance of ProperInitInternNoBuilder
*/
public static ImmutableProperInitInternNoBuilder of() {
return INSTANCE;
}
private static ImmutableProperInitInternNoBuilder validate(ImmutableProperInitInternNoBuilder instance) {
return INTERNER.intern(new InternProxy(instance)).instance;
}
}