All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.immutables.fixture.routine.ImmutableBb Maven / Gradle / Ivy

package org.immutables.fixture.routine;

import com.google.common.base.MoreObjects;
import com.google.common.base.Preconditions;
import com.google.common.collect.Lists;
import java.util.List;
import javax.annotation.Generated;
import javax.annotation.Nullable;
import javax.annotation.ParametersAreNonnullByDefault;
import javax.annotation.concurrent.Immutable;
import javax.annotation.concurrent.NotThreadSafe;
import static org.immutables.fixture.routine.Defaults.immutableCopyOf;
import static org.immutables.fixture.routine.Routines.immutableCopyOf;

/**
 * Immutable implementation of {@link Bb}.
 * 

* Use the builder to create immutable instances: * {@code ImmutableBb.builder()}. */ @SuppressWarnings("all") @ParametersAreNonnullByDefault @Generated({"Immutables.generator", "Bb"}) @Immutable public final class ImmutableBb implements Bb { private final Aa aa; private final Bb bb; private ImmutableBb(Aa aa, Bb bb) { this.aa = aa; this.bb = bb; } /** * @return The value of the {@code aa} attribute */ @Override public Aa aa() { return aa; } /** * @return The value of the {@code bb} attribute */ @Override public Bb bb() { return bb; } /** * Copy the current immutable object by setting a value for the {@link Bb#aa() aa} attribute. * A shallow reference equality check is used to prevent copying of the same value by returning {@code this}. * @param aa A new value for aa * @return A modified copy of the {@code this} object */ public final ImmutableBb withAa(Aa aa) { if (this.aa == aa) return this; Aa newValue = Preconditions.checkNotNull(immutableCopyOf(aa), "aa"); return new ImmutableBb(newValue, this.bb); } /** * Copy the current immutable object by setting a value for the {@link Bb#bb() bb} attribute. * A shallow reference equality check is used to prevent copying of the same value by returning {@code this}. * @param bb A new value for bb * @return A modified copy of the {@code this} object */ public final ImmutableBb withBb(Bb bb) { if (this.bb == bb) return this; Bb newValue = Preconditions.checkNotNull(immutableCopyOf(bb), "bb"); return new ImmutableBb(this.aa, newValue); } /** * This instance is equal to all instances of {@code ImmutableBb} 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 ImmutableBb && equalTo((ImmutableBb) another); } private boolean equalTo(ImmutableBb another) { return aa.equals(another.aa) && bb.equals(another.bb); } /** * Computes a hash code from attributes: {@code aa}, {@code bb}. * @return hashCode value */ @Override public int hashCode() { int h = 31; h = h * 17 + aa.hashCode(); h = h * 17 + bb.hashCode(); return h; } /** * Prints the immutable value {@code Bb} with attribute values. * @return A string representation of the value */ @Override public String toString() { return MoreObjects.toStringHelper("Bb") .omitNullValues() .add("aa", aa) .add("bb", bb) .toString(); } /** * Creates an immutable copy of a {@link Bb} 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 Bb instance */ public static ImmutableBb copyOf(Bb instance) { if (instance instanceof ImmutableBb) { return (ImmutableBb) instance; } return ImmutableBb.builder() .from(instance) .build(); } /** * Creates a builder for {@link ImmutableBb ImmutableBb}. * @return A new ImmutableBb builder */ public static ImmutableBb.Builder builder() { return new ImmutableBb.Builder(); } /** * Builds instances of type {@link ImmutableBb ImmutableBb}. * 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 static final long INIT_BIT_AA = 0x1L; private static final long INIT_BIT_BB = 0x2L; private long initBits = 0x3L; private @Nullable Aa aa; private @Nullable Bb bb; private Builder() { } /** * Fill a builder with attribute values from the provided {@code Bb} 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(Bb instance) { Preconditions.checkNotNull(instance, "instance"); aa(instance.aa()); bb(instance.bb()); return this; } /** * Initializes the value for the {@link Bb#aa() aa} attribute. * @param aa The value for aa * @return {@code this} builder for use in a chained invocation */ public final Builder aa(Aa aa) { this.aa = Preconditions.checkNotNull(immutableCopyOf(aa), "aa"); initBits &= ~INIT_BIT_AA; return this; } /** * Initializes the value for the {@link Bb#bb() bb} attribute. * @param bb The value for bb * @return {@code this} builder for use in a chained invocation */ public final Builder bb(Bb bb) { this.bb = Preconditions.checkNotNull(immutableCopyOf(bb), "bb"); initBits &= ~INIT_BIT_BB; return this; } /** * Builds a new {@link ImmutableBb ImmutableBb}. * @return An immutable instance of Bb * @throws java.lang.IllegalStateException if any required attributes are missing */ public ImmutableBb build() { if (initBits != 0) { throw new IllegalStateException(formatRequiredAttributesMessage()); } return new ImmutableBb(aa, bb); } private String formatRequiredAttributesMessage() { List attributes = Lists.newArrayList(); if ((initBits & INIT_BIT_AA) != 0) attributes.add("aa"); if ((initBits & INIT_BIT_BB) != 0) attributes.add("bb"); return "Cannot build Bb, some of required attributes are not set " + attributes; } } }





© 2015 - 2025 Weber Informatics LLC | Privacy Policy