org.immutables.fixture.ImmutableSillyStructure Maven / Gradle / Ivy
Show all versions of value-fixture Show documentation
package org.immutables.fixture;
import com.google.common.base.MoreObjects;
import com.google.common.base.Optional;
import com.google.common.collect.ImmutableList;
import com.google.common.primitives.Booleans;
import com.google.common.primitives.Doubles;
import com.google.common.primitives.Longs;
import com.google.errorprone.annotations.CanIgnoreReturnValue;
import com.google.errorprone.annotations.Var;
import java.util.ArrayList;
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.fixture.subpack.SillySubstructure;
import org.immutables.value.Generated;
/**
* Immutable implementation of {@link SillyStructure}.
*
* Use the builder to create immutable instances:
* {@code ImmutableSillyStructure.builder()}.
*/
@Generated(from = "SillyStructure", generator = "Immutables")
@SuppressWarnings({"all"})
@ParametersAreNonnullByDefault
@javax.annotation.processing.Generated("org.immutables.processor.ProxyProcessor")
@Immutable
@CheckReturnValue
public final class ImmutableSillyStructure extends SillyStructure {
private final String attr1;
private final boolean flag2;
private final Optional opt3;
private final long very4;
private final double wet5;
private final ImmutableList subs6;
private final SillySubstructure nest7;
private final Optional tup3;
private final int int9;
private ImmutableSillyStructure(
String attr1,
boolean flag2,
Optional opt3,
long very4,
double wet5,
ImmutableList subs6,
SillySubstructure nest7,
Optional tup3,
int int9) {
this.attr1 = attr1;
this.flag2 = flag2;
this.opt3 = opt3;
this.very4 = very4;
this.wet5 = wet5;
this.subs6 = subs6;
this.nest7 = nest7;
this.tup3 = tup3;
this.int9 = int9;
}
/**
* @return The value of the {@code attr1} attribute
*/
@Override
public String attr1() {
return attr1;
}
/**
* @return The value of the {@code flag2} attribute
*/
@Override
public boolean flag2() {
return flag2;
}
/**
* @return The value of the {@code opt3} attribute
*/
@Override
public Optional opt3() {
return opt3;
}
/**
* @return The value of the {@code very4} attribute
*/
@Override
public long very4() {
return very4;
}
/**
* @return The value of the {@code wet5} attribute
*/
@Override
public double wet5() {
return wet5;
}
/**
* @return The value of the {@code subs6} attribute
*/
@Override
public ImmutableList subs6() {
return subs6;
}
/**
* @return The value of the {@code nest7} attribute
*/
@Override
public SillySubstructure nest7() {
return nest7;
}
/**
* @return The value of the {@code tup3} attribute
*/
@Override
public Optional tup3() {
return tup3;
}
/**
* @return The value of the {@code int9} attribute
*/
@Override
public int int9() {
return int9;
}
/**
* Copy the current immutable object by setting a value for the {@link SillyStructure#attr1() attr1} attribute.
* An equals check used to prevent copying of the same value by returning {@code this}.
* @param value A new value for attr1
* @return A modified copy of the {@code this} object
*/
public final ImmutableSillyStructure withAttr1(String value) {
String newValue = Objects.requireNonNull(value, "attr1");
if (this.attr1.equals(newValue)) return this;
return new ImmutableSillyStructure(
newValue,
this.flag2,
this.opt3,
this.very4,
this.wet5,
this.subs6,
this.nest7,
this.tup3,
this.int9);
}
/**
* Copy the current immutable object by setting a value for the {@link SillyStructure#flag2() flag2} attribute.
* A value equality check is used to prevent copying of the same value by returning {@code this}.
* @param value A new value for flag2
* @return A modified copy of the {@code this} object
*/
public final ImmutableSillyStructure withFlag2(boolean value) {
if (this.flag2 == value) return this;
return new ImmutableSillyStructure(
this.attr1,
value,
this.opt3,
this.very4,
this.wet5,
this.subs6,
this.nest7,
this.tup3,
this.int9);
}
/**
* Copy the current immutable object by setting a present value for the optional {@link SillyStructure#opt3() opt3} attribute.
* @param value The value for opt3
* @return A modified copy of {@code this} object
*/
public final ImmutableSillyStructure withOpt3(int value) {
Optional newValue = Optional.of(value);
if (this.opt3.equals(newValue)) return this;
return new ImmutableSillyStructure(
this.attr1,
this.flag2,
newValue,
this.very4,
this.wet5,
this.subs6,
this.nest7,
this.tup3,
this.int9);
}
/**
* Copy the current immutable object by setting an optional value for the {@link SillyStructure#opt3() opt3} attribute.
* An equality check is used to prevent copying of the same value by returning {@code this}.
* @param optional A value for opt3
* @return A modified copy of {@code this} object
*/
public final ImmutableSillyStructure withOpt3(Optional optional) {
Optional value = optional;
if (this.opt3.equals(value)) return this;
return new ImmutableSillyStructure(
this.attr1,
this.flag2,
value,
this.very4,
this.wet5,
this.subs6,
this.nest7,
this.tup3,
this.int9);
}
/**
* Copy the current immutable object by setting a value for the {@link SillyStructure#very4() very4} attribute.
* A value equality check is used to prevent copying of the same value by returning {@code this}.
* @param value A new value for very4
* @return A modified copy of the {@code this} object
*/
public final ImmutableSillyStructure withVery4(long value) {
if (this.very4 == value) return this;
return new ImmutableSillyStructure(
this.attr1,
this.flag2,
this.opt3,
value,
this.wet5,
this.subs6,
this.nest7,
this.tup3,
this.int9);
}
/**
* Copy the current immutable object by setting a value for the {@link SillyStructure#wet5() wet5} attribute.
* A value strict bits equality used to prevent copying of the same value by returning {@code this}.
* @param value A new value for wet5
* @return A modified copy of the {@code this} object
*/
public final ImmutableSillyStructure withWet5(double value) {
if (Double.doubleToLongBits(this.wet5) == Double.doubleToLongBits(value)) return this;
return new ImmutableSillyStructure(
this.attr1,
this.flag2,
this.opt3,
this.very4,
value,
this.subs6,
this.nest7,
this.tup3,
this.int9);
}
/**
* Copy the current immutable object with elements that replace the content of {@link SillyStructure#subs6() subs6}.
* @param elements The elements to set
* @return A modified copy of {@code this} object
*/
public final ImmutableSillyStructure withSubs6(SillySubstructure... elements) {
ImmutableList newValue = ImmutableList.copyOf(elements);
return new ImmutableSillyStructure(
this.attr1,
this.flag2,
this.opt3,
this.very4,
this.wet5,
newValue,
this.nest7,
this.tup3,
this.int9);
}
/**
* Copy the current immutable object with elements that replace the content of {@link SillyStructure#subs6() subs6}.
* A shallow reference equality check is used to prevent copying of the same value by returning {@code this}.
* @param elements An iterable of subs6 elements to set
* @return A modified copy of {@code this} object
*/
public final ImmutableSillyStructure withSubs6(Iterable extends SillySubstructure> elements) {
if (this.subs6 == elements) return this;
ImmutableList newValue = ImmutableList.copyOf(elements);
return new ImmutableSillyStructure(
this.attr1,
this.flag2,
this.opt3,
this.very4,
this.wet5,
newValue,
this.nest7,
this.tup3,
this.int9);
}
/**
* Copy the current immutable object by setting a value for the {@link SillyStructure#nest7() nest7} attribute.
* A shallow reference equality check is used to prevent copying of the same value by returning {@code this}.
* @param value A new value for nest7
* @return A modified copy of the {@code this} object
*/
public final ImmutableSillyStructure withNest7(SillySubstructure value) {
if (this.nest7 == value) return this;
SillySubstructure newValue = Objects.requireNonNull(value, "nest7");
return new ImmutableSillyStructure(
this.attr1,
this.flag2,
this.opt3,
this.very4,
this.wet5,
this.subs6,
newValue,
this.tup3,
this.int9);
}
/**
* Copy the current immutable object by setting a present value for the optional {@link SillyStructure#tup3() tup3} attribute.
* @param value The value for tup3
* @return A modified copy of {@code this} object
*/
public final ImmutableSillyStructure withTup3(SillyTuplie value) {
Optional newValue = Optional.of(value);
if (this.tup3.isPresent() && this.tup3.get() == value) return this;
return new ImmutableSillyStructure(
this.attr1,
this.flag2,
this.opt3,
this.very4,
this.wet5,
this.subs6,
this.nest7,
newValue,
this.int9);
}
/**
* Copy the current immutable object by setting an optional value for the {@link SillyStructure#tup3() tup3} attribute.
* A shallow reference equality check on the optional value is used to prevent copying of the same value by returning {@code this}.
* @param optional A value for tup3
* @return A modified copy of {@code this} object
*/
@SuppressWarnings("unchecked") // safe covariant cast
public final ImmutableSillyStructure withTup3(Optional extends SillyTuplie> optional) {
Optional value = (Optional) optional;
if (!this.tup3.isPresent() && !value.isPresent()) return this;
if (this.tup3.isPresent() && value.isPresent() && this.tup3.get() == value.get()) return this;
return new ImmutableSillyStructure(
this.attr1,
this.flag2,
this.opt3,
this.very4,
this.wet5,
this.subs6,
this.nest7,
value,
this.int9);
}
/**
* Copy the current immutable object by setting a value for the {@link SillyStructure#int9() int9} attribute.
* A value equality check is used to prevent copying of the same value by returning {@code this}.
* @param value A new value for int9
* @return A modified copy of the {@code this} object
*/
public final ImmutableSillyStructure withInt9(int value) {
if (this.int9 == value) return this;
return new ImmutableSillyStructure(
this.attr1,
this.flag2,
this.opt3,
this.very4,
this.wet5,
this.subs6,
this.nest7,
this.tup3,
value);
}
/**
* This instance is equal to all instances of {@code ImmutableSillyStructure} 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 ImmutableSillyStructure
&& equalTo(0, (ImmutableSillyStructure) another);
}
private boolean equalTo(int synthetic, ImmutableSillyStructure another) {
return attr1.equals(another.attr1)
&& flag2 == another.flag2
&& opt3.equals(another.opt3)
&& very4 == another.very4
&& Double.doubleToLongBits(wet5) == Double.doubleToLongBits(another.wet5)
&& subs6.equals(another.subs6)
&& nest7.equals(another.nest7)
&& tup3.equals(another.tup3)
&& int9 == another.int9;
}
/**
* Computes a hash code from attributes: {@code attr1}, {@code flag2}, {@code opt3}, {@code very4}, {@code wet5}, {@code subs6}, {@code nest7}, {@code tup3}, {@code int9}.
* @return hashCode value
*/
@Override
public int hashCode() {
@Var int h = 5381;
h += (h << 5) + attr1.hashCode();
h += (h << 5) + Booleans.hashCode(flag2);
h += (h << 5) + opt3.hashCode();
h += (h << 5) + Longs.hashCode(very4);
h += (h << 5) + Doubles.hashCode(wet5);
h += (h << 5) + subs6.hashCode();
h += (h << 5) + nest7.hashCode();
h += (h << 5) + tup3.hashCode();
h += (h << 5) + int9;
return h;
}
/**
* Prints the immutable value {@code SillyStructure} with attribute values.
* @return A string representation of the value
*/
@Override
public String toString() {
return MoreObjects.toStringHelper("SillyStructure")
.omitNullValues()
.add("attr1", attr1)
.add("flag2", flag2)
.add("opt3", opt3.orNull())
.add("very4", very4)
.add("wet5", wet5)
.add("subs6", subs6)
.add("nest7", nest7)
.add("tup3", tup3.orNull())
.add("int9", int9)
.toString();
}
/**
* Creates an immutable copy of a {@link SillyStructure} 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 SillyStructure instance
*/
public static ImmutableSillyStructure copyOf(SillyStructure instance) {
if (instance instanceof ImmutableSillyStructure) {
return (ImmutableSillyStructure) instance;
}
return ImmutableSillyStructure.builder()
.from(instance)
.build();
}
/**
* Creates a builder for {@link ImmutableSillyStructure ImmutableSillyStructure}.
*
* ImmutableSillyStructure.builder()
* .attr1(String) // required {@link SillyStructure#attr1() attr1}
* .flag2(boolean) // required {@link SillyStructure#flag2() flag2}
* .opt3(Integer) // optional {@link SillyStructure#opt3() opt3}
* .very4(long) // required {@link SillyStructure#very4() very4}
* .wet5(double) // required {@link SillyStructure#wet5() wet5}
* .addSubs6|addAllSubs6(org.immutables.fixture.subpack.SillySubstructure) // {@link SillyStructure#subs6() subs6} elements
* .nest7(org.immutables.fixture.subpack.SillySubstructure) // required {@link SillyStructure#nest7() nest7}
* .tup3(org.immutables.fixture.SillyTuplie) // optional {@link SillyStructure#tup3() tup3}
* .int9(int) // required {@link SillyStructure#int9() int9}
* .build();
*
* @return A new ImmutableSillyStructure builder
*/
public static ImmutableSillyStructure.Builder builder() {
return new ImmutableSillyStructure.Builder();
}
/**
* Builds instances of type {@link ImmutableSillyStructure ImmutableSillyStructure}.
* 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 = "SillyStructure", generator = "Immutables")
@NotThreadSafe
public static final class Builder {
private static final long INIT_BIT_ATTR1 = 0x1L;
private static final long INIT_BIT_FLAG2 = 0x2L;
private static final long INIT_BIT_VERY4 = 0x4L;
private static final long INIT_BIT_WET5 = 0x8L;
private static final long INIT_BIT_NEST7 = 0x10L;
private static final long INIT_BIT_INT9 = 0x20L;
private long initBits = 0x3fL;
private @Nullable String attr1;
private boolean flag2;
private Optional opt3 = Optional.absent();
private long very4;
private double wet5;
private ImmutableList.Builder subs6 = ImmutableList.builder();
private @Nullable SillySubstructure nest7;
private Optional tup3 = Optional.absent();
private int int9;
private Builder() {
}
/**
* Fill a builder with attribute values from the provided {@code SillyStructure} instance.
* Regular attribute values will be replaced with those from the given instance.
* Absent optional values will not replace present values.
* Collection elements and entries will be added, not replaced.
* @param instance The instance from which to copy values
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
public final Builder from(SillyStructure instance) {
Objects.requireNonNull(instance, "instance");
attr1(instance.attr1());
flag2(instance.flag2());
Optional opt3Optional = instance.opt3();
if (opt3Optional.isPresent()) {
opt3(opt3Optional);
}
very4(instance.very4());
wet5(instance.wet5());
addAllSubs6(instance.subs6());
nest7(instance.nest7());
Optional tup3Optional = instance.tup3();
if (tup3Optional.isPresent()) {
tup3(tup3Optional);
}
int9(instance.int9());
return this;
}
/**
* Initializes the value for the {@link SillyStructure#attr1() attr1} attribute.
* @param attr1 The value for attr1
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
public final Builder attr1(String attr1) {
this.attr1 = Objects.requireNonNull(attr1, "attr1");
initBits &= ~INIT_BIT_ATTR1;
return this;
}
/**
* Initializes the value for the {@link SillyStructure#flag2() flag2} attribute.
* @param flag2 The value for flag2
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
public final Builder flag2(boolean flag2) {
this.flag2 = flag2;
initBits &= ~INIT_BIT_FLAG2;
return this;
}
/**
* Initializes the optional value {@link SillyStructure#opt3() opt3} to opt3.
* @param opt3 The value for opt3
* @return {@code this} builder for chained invocation
*/
@CanIgnoreReturnValue
public final Builder opt3(int opt3) {
this.opt3 = Optional.of(opt3);
return this;
}
/**
* Initializes the optional value {@link SillyStructure#opt3() opt3} to opt3.
* @param opt3 The value for opt3
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
public final Builder opt3(Optional opt3) {
this.opt3 = opt3;
return this;
}
/**
* Initializes the value for the {@link SillyStructure#very4() very4} attribute.
* @param very4 The value for very4
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
public final Builder very4(long very4) {
this.very4 = very4;
initBits &= ~INIT_BIT_VERY4;
return this;
}
/**
* Initializes the value for the {@link SillyStructure#wet5() wet5} attribute.
* @param wet5 The value for wet5
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
public final Builder wet5(double wet5) {
this.wet5 = wet5;
initBits &= ~INIT_BIT_WET5;
return this;
}
/**
* Adds one element to {@link SillyStructure#subs6() subs6} list.
* @param element A subs6 element
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
public final Builder addSubs6(SillySubstructure element) {
this.subs6.add(element);
return this;
}
/**
* Adds elements to {@link SillyStructure#subs6() subs6} list.
* @param elements An array of subs6 elements
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
public final Builder addSubs6(SillySubstructure... elements) {
this.subs6.add(elements);
return this;
}
/**
* Sets or replaces all elements for {@link SillyStructure#subs6() subs6} list.
* @param elements An iterable of subs6 elements
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
public final Builder subs6(Iterable extends SillySubstructure> elements) {
this.subs6 = ImmutableList.builder();
return addAllSubs6(elements);
}
/**
* Adds elements to {@link SillyStructure#subs6() subs6} list.
* @param elements An iterable of subs6 elements
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
public final Builder addAllSubs6(Iterable extends SillySubstructure> elements) {
this.subs6.addAll(elements);
return this;
}
/**
* Initializes the value for the {@link SillyStructure#nest7() nest7} attribute.
* @param nest7 The value for nest7
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
public final Builder nest7(SillySubstructure nest7) {
this.nest7 = Objects.requireNonNull(nest7, "nest7");
initBits &= ~INIT_BIT_NEST7;
return this;
}
/**
* Initializes the optional value {@link SillyStructure#tup3() tup3} to tup3.
* @param tup3 The value for tup3
* @return {@code this} builder for chained invocation
*/
@CanIgnoreReturnValue
public final Builder tup3(SillyTuplie tup3) {
this.tup3 = Optional.of(tup3);
return this;
}
/**
* Initializes the optional value {@link SillyStructure#tup3() tup3} to tup3.
* @param tup3 The value for tup3
* @return {@code this} builder for use in a chained invocation
*/
@SuppressWarnings("unchecked") // safe covariant cast
@CanIgnoreReturnValue
public final Builder tup3(Optional extends SillyTuplie> tup3) {
this.tup3 = (Optional) tup3;
return this;
}
/**
* Initializes the value for the {@link SillyStructure#int9() int9} attribute.
* @param int9 The value for int9
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
public final Builder int9(int int9) {
this.int9 = int9;
initBits &= ~INIT_BIT_INT9;
return this;
}
/**
* Builds a new {@link ImmutableSillyStructure ImmutableSillyStructure}.
* @return An immutable instance of SillyStructure
* @throws java.lang.IllegalStateException if any required attributes are missing
*/
public ImmutableSillyStructure build() {
if (initBits != 0) {
throw new IllegalStateException(formatRequiredAttributesMessage());
}
return new ImmutableSillyStructure(attr1, flag2, opt3, very4, wet5, subs6.build(), nest7, tup3, int9);
}
private String formatRequiredAttributesMessage() {
List attributes = new ArrayList<>();
if ((initBits & INIT_BIT_ATTR1) != 0) attributes.add("attr1");
if ((initBits & INIT_BIT_FLAG2) != 0) attributes.add("flag2");
if ((initBits & INIT_BIT_VERY4) != 0) attributes.add("very4");
if ((initBits & INIT_BIT_WET5) != 0) attributes.add("wet5");
if ((initBits & INIT_BIT_NEST7) != 0) attributes.add("nest7");
if ((initBits & INIT_BIT_INT9) != 0) attributes.add("int9");
return "Cannot build SillyStructure, some of required attributes are not set " + attributes;
}
}
}