![JAR search and dependency download from the Maven repository](/logo.png)
org.immutables.fixture.modifiable.ModifiableNoFrom Maven / Gradle / Ivy
Show all versions of value-fixture Show documentation
package org.immutables.fixture.modifiable;
import com.google.common.base.MoreObjects;
import com.google.errorprone.annotations.CanIgnoreReturnValue;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import javax.annotation.Nullable;
import javax.annotation.ParametersAreNonnullByDefault;
import javax.annotation.concurrent.NotThreadSafe;
import org.immutables.value.Generated;
/**
* A modifiable implementation of the {@link FromTypesModifiables.NoFrom NoFrom} type.
* Use the {@link #create()} static factory methods to create new instances.
* Use the {@link #toImmutable()} method to convert to canonical immutable instances.
*
ModifiableNoFrom is not thread-safe
* @see ImmutableNoFrom
*/
@Generated(from = "FromTypesModifiables.NoFrom", generator = "Modifiables")
@SuppressWarnings({"all"})
@ParametersAreNonnullByDefault
@javax.annotation.processing.Generated({"Modifiables.generator", "FromTypesModifiables.NoFrom"})
@NotThreadSafe
public final class ModifiableNoFrom implements FromTypesModifiables.NoFrom {
private static final long INIT_BIT_A = 0x1L;
private static final long INIT_BIT_B = 0x2L;
private long initBits = 0x3L;
private int a;
private String b;
private ModifiableNoFrom() {}
/**
* Construct a modifiable instance of {@code NoFrom}.
* @return A new modifiable instance
*/
public static ModifiableNoFrom create() {
return new ModifiableNoFrom();
}
/**
* @return value of {@code a} attribute
*/
@Override
public final int a() {
return a;
}
/**
* @return value of {@code b} attribute
*/
@Override
public final String b() {
return b;
}
/**
* Clears the object by setting all attributes to their initial values.
* @return {@code this} for use in a chained invocation
*/
@CanIgnoreReturnValue
public ModifiableNoFrom clear() {
initBits = 0x3L;
a = 0;
b = null;
return this;
}
/**
* Fill this modifiable instance with attribute values from the provided {@link FromTypesModifiables.NoFrom} instance.
* Regular attribute values will be overridden, i.e. replaced with ones of an instance.
* Any of the instance's absent optional values will not be copied (will not override current values).
* @param instance The instance from which to copy values
* @return {@code this} for use in a chained invocation
*/
public ModifiableNoFrom NoFrom(FromTypesModifiables.NoFrom instance) {
Objects.requireNonNull(instance, "instance");
if (instance instanceof ModifiableNoFrom) {
NoFrom((ModifiableNoFrom) instance);
return this;
}
setA(instance.a());
setB(instance.b());
return this;
}
/**
* Fill this modifiable instance with attribute values from the provided {@link FromTypesModifiables.NoFrom} instance.
* Regular attribute values will be overridden, i.e. replaced with ones of an instance.
* Any of the instance's absent optional values will not be copied (will not override current values).
* @param instance The instance from which to copy values
* @return {@code this} for use in a chained invocation
*/
public ModifiableNoFrom NoFrom(ModifiableNoFrom instance) {
Objects.requireNonNull(instance, "instance");
if (instance.aIsSet()) {
setA(instance.a());
}
if (instance.bIsSet()) {
setB(instance.b());
}
return this;
}
/**
* Assigns a value to the {@link FromTypesModifiables.NoFrom#a() a} attribute.
* @param a The value for a
* @return {@code this} for use in a chained invocation
*/
@CanIgnoreReturnValue
public ModifiableNoFrom setA(int a) {
this.a = a;
initBits &= ~INIT_BIT_A;
return this;
}
/**
* Assigns a value to the {@link FromTypesModifiables.NoFrom#b() b} attribute.
* @param b The value for b
* @return {@code this} for use in a chained invocation
*/
@CanIgnoreReturnValue
public ModifiableNoFrom setB(String b) {
this.b = Objects.requireNonNull(b, "b");
initBits &= ~INIT_BIT_B;
return this;
}
/**
* Returns {@code true} if the required attribute {@link FromTypesModifiables.NoFrom#a() a} is set.
* @return {@code true} if set
*/
public final boolean aIsSet() {
return (initBits & INIT_BIT_A) == 0;
}
/**
* Returns {@code true} if the required attribute {@link FromTypesModifiables.NoFrom#b() b} is set.
* @return {@code true} if set
*/
public final boolean bIsSet() {
return (initBits & INIT_BIT_B) == 0;
}
/**
* Reset an attribute to its initial value.
* @return {@code this} for use in a chained invocation
*/
@CanIgnoreReturnValue
public final ModifiableNoFrom unsetA() {
initBits |= INIT_BIT_A;
a = 0;
return this;
}
/**
* Reset an attribute to its initial value.
* @return {@code this} for use in a chained invocation
*/
@CanIgnoreReturnValue
public final ModifiableNoFrom unsetB() {
initBits |= INIT_BIT_B;
b = null;
return this;
}
/**
* Returns {@code true} if all required attributes are set, indicating that the object is initialized.
* @return {@code true} if set
*/
public final boolean isInitialized() {
return initBits == 0;
}
private void checkRequiredAttributes() {
if (!isInitialized()) {
throw new IllegalStateException(formatRequiredAttributesMessage());
}
}
private String formatRequiredAttributesMessage() {
List attributes = new ArrayList<>();
if (!aIsSet()) attributes.add("a");
if (!bIsSet()) attributes.add("b");
return "NoFrom is not initialized, some of the required attributes are not set " + attributes;
}
/**
* Converts to {@link ImmutableNoFrom ImmutableNoFrom}.
* @return An immutable instance of NoFrom
*/
public final ImmutableNoFrom toImmutable() {
checkRequiredAttributes();
return ImmutableNoFrom.copyOf(this);
}
/**
* This instance is equal to all instances of {@code ModifiableNoFrom} that have equal attribute values.
* An uninitialized instance is equal only to itself.
* @return {@code true} if {@code this} is equal to {@code another} instance
*/
@Override
public boolean equals(@Nullable Object another) {
if (this == another) return true;
if (!(another instanceof ModifiableNoFrom)) return false;
ModifiableNoFrom other = (ModifiableNoFrom) another;
if (!isInitialized() || !other.isInitialized()) {
return false;
}
return equalTo(other);
}
private boolean equalTo(ModifiableNoFrom another) {
return a == another.a
&& b.equals(another.b);
}
/**
* Computes a hash code from attributes: {@code a}, {@code b}.
* @return hashCode value
*/
@Override
public int hashCode() {
int h = 5381;
h += (h << 5) + a;
h += (h << 5) + b.hashCode();
return h;
}
/**
* Generates a string representation of this {@code NoFrom}.
* If uninitialized, some attribute values may appear as question marks.
* @return A string representation
*/
@Override
public String toString() {
return MoreObjects.toStringHelper("ModifiableNoFrom")
.add("a", aIsSet() ? a() : "?")
.add("b", bIsSet() ? b() : "?")
.toString();
}
}