org.immutables.fixture.ImmutableSampleNesting Maven / Gradle / Ivy
package org.immutables.fixture;
import com.google.common.base.Preconditions;
import javax.annotation.Generated;
import javax.annotation.Nullable;
import javax.annotation.ParametersAreNonnullByDefault;
import javax.annotation.concurrent.Immutable;
import javax.annotation.concurrent.NotThreadSafe;
/**
* {@code ImmutableSampleNesting} contains immutable implementation classes generated from
* abstract value types defined as nested inside {@link SampleNesting}.
* @see ImmutableSampleNesting.B
* @see ImmutableSampleNesting.A
*/
@SuppressWarnings("all")
@ParametersAreNonnullByDefault
@Generated({"Immutables.generator", "SampleNesting"})
public final class ImmutableSampleNesting {
private ImmutableSampleNesting() {}
/**
* Immutable implementation of {@link SampleNesting.B}.
*
* Use the builder to create immutable instances:
* {@code ImmutableSampleNesting.B.builder()}.
*/
@Immutable
public static final class B extends SampleNesting.B {
private B(ImmutableSampleNesting.B.Builder builder) {
}
/**
* This instance is equal to all instances of {@code B} 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 B
&& equalTo((B) another);
}
private boolean equalTo(B another) {
return true;
}
/**
* Returns a constant hash code value.
* @return hashCode value
*/
@Override
public int hashCode() {
return 655875323;
}
/**
* Prints the immutable value {@code B}.
* @return A string representation of the value
*/
@Override
public String toString() {
return "B{}";
}
/**
* Creates an immutable copy of a {@link SampleNesting.B} 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 B instance
*/
public static ImmutableSampleNesting.B copyOf(SampleNesting.B instance) {
if (instance instanceof ImmutableSampleNesting.B) {
return (ImmutableSampleNesting.B) instance;
}
return ImmutableSampleNesting.B.builder()
.from(instance)
.build();
}
/**
* Creates a builder for {@link ImmutableSampleNesting.B B}.
* @return A new B builder
*/
public static ImmutableSampleNesting.B.Builder builder() {
return new ImmutableSampleNesting.B.Builder();
}
/**
* Builds instances of type {@link ImmutableSampleNesting.B B}.
* 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 Builder() {
}
/**
* Fill a builder with attribute values from the provided {@code B} 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
*/
public final Builder from(SampleNesting.B instance) {
Preconditions.checkNotNull(instance, "instance");
return this;
}
/**
* Builds a new {@link ImmutableSampleNesting.B B}.
* @return An immutable instance of B
* @throws java.lang.IllegalStateException if any required attributes are missing
*/
public ImmutableSampleNesting.B build() {
return new ImmutableSampleNesting.B(this);
}
}
}
/**
* Immutable implementation of {@link SampleNesting.A}.
*
* Use the builder to create immutable instances:
* {@code ImmutableSampleNesting.A.builder()}.
*/
@Immutable
static final class A implements SampleNesting.A {
private A(ImmutableSampleNesting.A.Builder builder) {
}
/**
* This instance is equal to all instances of {@code A} 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 A
&& equalTo((A) another);
}
private boolean equalTo(A another) {
return true;
}
/**
* Returns a constant hash code value.
* @return hashCode value
*/
@Override
public int hashCode() {
return 655875322;
}
/**
* Prints the immutable value {@code A}.
* @return A string representation of the value
*/
@Override
public String toString() {
return "A{}";
}
/**
* Creates an immutable copy of a {@link SampleNesting.A} 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 A instance
*/
public static ImmutableSampleNesting.A copyOf(SampleNesting.A instance) {
if (instance instanceof ImmutableSampleNesting.A) {
return (ImmutableSampleNesting.A) instance;
}
return ImmutableSampleNesting.A.builder()
.from(instance)
.build();
}
/**
* Creates a builder for {@link ImmutableSampleNesting.A A}.
* @return A new A builder
*/
public static ImmutableSampleNesting.A.Builder builder() {
return new ImmutableSampleNesting.A.Builder();
}
/**
* Builds instances of type {@link ImmutableSampleNesting.A A}.
* 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
static final class Builder {
private Builder() {
}
/**
* Fill a builder with attribute values from the provided {@code A} 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
*/
public final Builder from(SampleNesting.A instance) {
Preconditions.checkNotNull(instance, "instance");
return this;
}
/**
* Builds a new {@link ImmutableSampleNesting.A A}.
* @return An immutable instance of A
* @throws java.lang.IllegalStateException if any required attributes are missing
*/
public ImmutableSampleNesting.A build() {
return new ImmutableSampleNesting.A(this);
}
}
}
}