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

org.immutables.fixture.modifiable.ModifiableNullableAndDefault Maven / Gradle / Ivy

package org.immutables.fixture.modifiable;

import com.google.common.base.MoreObjects;
import com.google.common.base.Objects;
import com.google.common.base.Preconditions;
import java.lang.annotation.RetentionPolicy;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.EnumSet;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.NavigableSet;
import java.util.Set;
import java.util.SortedSet;
import java.util.TreeSet;
import javax.annotation.Generated;
import javax.annotation.Nullable;
import javax.annotation.ParametersAreNonnullByDefault;
import javax.annotation.concurrent.NotThreadSafe;

/**
 * A modifiable implementation of the {@link Companion.NullableAndDefault NullableAndDefault} type.
 * 

Use the {@link #create()} static factory methods to create new instances. * Use the {@link #toImmutable()} method to convert to canonical immutable instances. *

ModifiableNullableAndDefault is not thread-safe * @see ImmutableNullableAndDefault */ @SuppressWarnings("all") @ParametersAreNonnullByDefault @Generated({"Modifiables.generator", "Companion.NullableAndDefault"}) @NotThreadSafe public final class ModifiableNullableAndDefault implements Companion.NullableAndDefault { private static final long OPT_BIT_STR = 0x1L; private static final long OPT_BIT_INTS = 0x2L; private static final long OPT_BIT_ORDS = 0x4L; private static final long OPT_BIT_POLS = 0x8L; private static final long OPT_BIT_NAVS = 0x10L; private long optBits; private ArrayList lst = null; private ArrayList str = null; private LinkedHashSet ints = null; private int[] arrayInts; private TreeSet ords = null; private EnumSet pols = null; private TreeSet navs = null; private ModifiableNullableAndDefault() {} /** * Construct a modifiable instance of {@code NullableAndDefault}. * @return A new modifiable instance */ public static ModifiableNullableAndDefault create() { return new ModifiableNullableAndDefault(); } /** * @return modifiable list {@code lst} */ @Override public final List lst() { if (lst == null) { lst = new ArrayList(0); } return lst; } /** * @return assigned or, otherwise, newly computed, not cached value of {@code str} attribute */ @Override public final @Nullable List str() { return strIsSet() ? str : Companion.NullableAndDefault.super.str(); } /** * @return assigned or, otherwise, newly computed, not cached value of {@code ints} attribute */ @Override public final Set ints() { return intsIsSet() ? ints : Companion.NullableAndDefault.super.ints(); } /** * @return assigned modifiable {@code arrayInts} array */ @Override public final int[] arrayInts() { return arrayIntsIsSet() ? arrayInts : Companion.NullableAndDefault.super.arrayInts(); } /** * @return assigned or, otherwise, newly computed, not cached value of {@code ords} attribute */ @Override public final @Nullable SortedSet ords() { return ordsIsSet() ? ords : Companion.NullableAndDefault.super.ords(); } /** * @return assigned or, otherwise, newly computed, not cached value of {@code pols} attribute */ @Override public final Set pols() { return polsIsSet() ? pols : Companion.NullableAndDefault.super.pols(); } /** * @return assigned or, otherwise, newly computed, not cached value of {@code navs} attribute */ @Override public final NavigableSet navs() { return navsIsSet() ? navs : Companion.NullableAndDefault.super.navs(); } /** * Clears the object by setting all attributes to their initial values. * @return {@code this} for use in a chained invocation */ public ModifiableNullableAndDefault clear() { optBits = 0; lst = null; str = null; ints = null; arrayInts = null; ords = null; pols = null; navs = null; return this; } /** * Fill this modifiable instance with attribute values from the provided {@link Companion.NullableAndDefault} 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). * Collection elements and entries will be added, not replaced. * @param instance The instance from which to copy values * @return {@code this} for use in a chained invocation */ public ModifiableNullableAndDefault from(Companion.NullableAndDefault instance) { Preconditions.checkNotNull(instance, "instance"); addAllLst(instance.lst()); addAllStr(instance.str()); addAllInts(instance.ints()); setArrayInts(instance.arrayInts()); addAllOrds(instance.ords()); addAllPols(instance.pols()); addAllNavs(instance.navs()); return this; } /** * Adds one element to {@link Companion.NullableAndDefault#lst() lst} list. * @param element The lst element * @return {@code this} for use in a chained invocation */ public ModifiableNullableAndDefault addLst(String element) { if (lst == null) { lst = new ArrayList(); } lst.add(Preconditions.checkNotNull(element, "lst element")); return this; } /** * Adds elements to {@link Companion.NullableAndDefault#lst() lst} list. * @param elements An array of lst elements * @return {@code this} for use in a chained invocation */ public final ModifiableNullableAndDefault addLst(String... elements) { for (String element : elements) { addLst(Preconditions.checkNotNull(element, "lst element")); } return this; } /** * Sets or replaces all elements for {@link Companion.NullableAndDefault#lst() lst} list. * @param elements An iterable of lst elements * @return {@code this} for use in a chained invocation */ public ModifiableNullableAndDefault setLst(Iterable elements) { if (lst == null) { lst = new ArrayList(); } else { lst.clear(); } return addAllLst(elements); } /** * Adds elements to {@link Companion.NullableAndDefault#lst() lst} list. * @param elements An iterable of lst elements * @return {@code this} for use in a chained invocation */ public ModifiableNullableAndDefault addAllLst(Iterable elements) { if (lst == null) { lst = new ArrayList(); } for (String element : elements) { lst.add(Preconditions.checkNotNull(element, "lst element")); } return this; } /** * Adds one element to {@link Companion.NullableAndDefault#str() str} list. * @param element The str element * @return {@code this} for use in a chained invocation */ public ModifiableNullableAndDefault addStr(String element) { if (str == null) { str = new ArrayList(); } str.add(Preconditions.checkNotNull(element, "str element")); optBits |= OPT_BIT_STR; return this; } /** * Adds elements to {@link Companion.NullableAndDefault#str() str} list. * @param elements An array of str elements * @return {@code this} for use in a chained invocation */ public final ModifiableNullableAndDefault addStr(String... elements) { for (String element : elements) { addStr(Preconditions.checkNotNull(element, "str element")); } optBits |= OPT_BIT_STR; return this; } /** * Sets or replaces all elements for {@link Companion.NullableAndDefault#str() str} list. * @param elements An iterable of str elements, can be {@code null} * @return {@code this} for use in a chained invocation */ public ModifiableNullableAndDefault setStr(@Nullable Iterable elements) { if (elements == null) { str = null; optBits |= OPT_BIT_STR; return this; } if (str == null) { str = new ArrayList(); } else { str.clear(); } return addAllStr(elements); } /** * Adds elements to {@link Companion.NullableAndDefault#str() str} list. * @param elements An iterable of str elements * @return {@code this} for use in a chained invocation */ public ModifiableNullableAndDefault addAllStr(Iterable elements) { if (str == null) { str = new ArrayList(); } for (String element : elements) { str.add(Preconditions.checkNotNull(element, "str element")); } optBits |= OPT_BIT_STR; return this; } /** * Adds one element to {@link Companion.NullableAndDefault#ints() ints} set. * @param element The ints element * @return {@code this} for use in a chained invocation */ public ModifiableNullableAndDefault addInts(int element) { if (ints == null) { ints = new LinkedHashSet(); } ints.add(element); optBits |= OPT_BIT_INTS; return this; } /** * Adds elements to {@link Companion.NullableAndDefault#ints() ints} set. * @param elements An array of ints elements * @return {@code this} for use in a chained invocation */ public final ModifiableNullableAndDefault addInts(int... elements) { for (int element : elements) { addInts(element); } optBits |= OPT_BIT_INTS; return this; } /** * Sets or replaces all elements for {@link Companion.NullableAndDefault#ints() ints} set. * @param elements An iterable of ints elements * @return {@code this} for use in a chained invocation */ public ModifiableNullableAndDefault setInts(Iterable elements) { if (ints == null) { ints = new LinkedHashSet(); } else { ints.clear(); } return addAllInts(elements); } /** * Adds elements to {@link Companion.NullableAndDefault#ints() ints} set. * @param elements An iterable of ints elements * @return {@code this} for use in a chained invocation */ public ModifiableNullableAndDefault addAllInts(Iterable elements) { if (ints == null) { ints = new LinkedHashSet(); } for (int element : elements) { ints.add(element); } optBits |= OPT_BIT_INTS; return this; } /** * Assigns a value to the {@link Companion.NullableAndDefault#arrayInts() arrayInts} attribute. *

If not set, this attribute will have a default value as defined by {@link Companion.NullableAndDefault#arrayInts() arrayInts}. * @param elements The elements for arrayInts * @return {@code this} for use in a chained invocation */ public final ModifiableNullableAndDefault setArrayInts(int... elements) { this.arrayInts = elements.clone(); return this; } /** * Adds one element to {@link Companion.NullableAndDefault#ords() ords} sortedSet. * @param element The ords element * @return {@code this} for use in a chained invocation */ public ModifiableNullableAndDefault addOrds(int element) { if (ords == null) { ords = new TreeSet(); } ords.add(element); optBits |= OPT_BIT_ORDS; return this; } /** * Adds elements to {@link Companion.NullableAndDefault#ords() ords} sortedSet. * @param elements An array of ords elements * @return {@code this} for use in a chained invocation */ public final ModifiableNullableAndDefault addOrds(int... elements) { for (int element : elements) { addOrds(element); } optBits |= OPT_BIT_ORDS; return this; } /** * Sets or replaces all elements for {@link Companion.NullableAndDefault#ords() ords} sortedSet. * @param elements An iterable of ords elements, can be {@code null} * @return {@code this} for use in a chained invocation */ public ModifiableNullableAndDefault setOrds(@Nullable Iterable elements) { if (elements == null) { ords = null; optBits |= OPT_BIT_ORDS; return this; } if (ords == null) { ords = new TreeSet(); } else { ords.clear(); } return addAllOrds(elements); } /** * Adds elements to {@link Companion.NullableAndDefault#ords() ords} sortedSet. * @param elements An iterable of ords elements * @return {@code this} for use in a chained invocation */ public ModifiableNullableAndDefault addAllOrds(Iterable elements) { if (ords == null) { ords = new TreeSet(); } for (int element : elements) { ords.add(element); } optBits |= OPT_BIT_ORDS; return this; } /** * Adds one element to {@link Companion.NullableAndDefault#pols() pols} set. * @param element The pols element * @return {@code this} for use in a chained invocation */ public ModifiableNullableAndDefault addPols(RetentionPolicy element) { if (pols == null) { pols = EnumSet.noneOf(RetentionPolicy.class); } pols.add(Preconditions.checkNotNull(element, "pols element")); optBits |= OPT_BIT_POLS; return this; } /** * Adds elements to {@link Companion.NullableAndDefault#pols() pols} set. * @param elements An array of pols elements * @return {@code this} for use in a chained invocation */ public final ModifiableNullableAndDefault addPols(RetentionPolicy... elements) { for (RetentionPolicy element : elements) { addPols(Preconditions.checkNotNull(element, "pols element")); } optBits |= OPT_BIT_POLS; return this; } /** * Sets or replaces all elements for {@link Companion.NullableAndDefault#pols() pols} set. * @param elements An iterable of pols elements * @return {@code this} for use in a chained invocation */ public ModifiableNullableAndDefault setPols(Iterable elements) { if (pols == null) { pols = EnumSet.noneOf(RetentionPolicy.class); } else { pols.clear(); } return addAllPols(elements); } /** * Adds elements to {@link Companion.NullableAndDefault#pols() pols} set. * @param elements An iterable of pols elements * @return {@code this} for use in a chained invocation */ public ModifiableNullableAndDefault addAllPols(Iterable elements) { if (pols == null) { pols = EnumSet.noneOf(RetentionPolicy.class); } for (RetentionPolicy element : elements) { pols.add(Preconditions.checkNotNull(element, "pols element")); } optBits |= OPT_BIT_POLS; return this; } /** * Adds one element to {@link Companion.NullableAndDefault#navs() navs} sortedSet. * @param element The navs element * @return {@code this} for use in a chained invocation */ public ModifiableNullableAndDefault addNavs(int element) { if (navs == null) { navs = new TreeSet(Collections.reverseOrder()); } navs.add(element); optBits |= OPT_BIT_NAVS; return this; } /** * Adds elements to {@link Companion.NullableAndDefault#navs() navs} sortedSet. * @param elements An array of navs elements * @return {@code this} for use in a chained invocation */ public final ModifiableNullableAndDefault addNavs(int... elements) { for (int element : elements) { addNavs(element); } optBits |= OPT_BIT_NAVS; return this; } /** * Sets or replaces all elements for {@link Companion.NullableAndDefault#navs() navs} sortedSet. * @param elements An iterable of navs elements * @return {@code this} for use in a chained invocation */ public ModifiableNullableAndDefault setNavs(Iterable elements) { if (navs == null) { navs = new TreeSet(Collections.reverseOrder()); } else { navs.clear(); } return addAllNavs(elements); } /** * Adds elements to {@link Companion.NullableAndDefault#navs() navs} sortedSet. * @param elements An iterable of navs elements * @return {@code this} for use in a chained invocation */ public ModifiableNullableAndDefault addAllNavs(Iterable elements) { if (navs == null) { navs = new TreeSet(Collections.reverseOrder()); } for (int element : elements) { navs.add(element); } optBits |= OPT_BIT_NAVS; return this; } /** * Returns {@code true} if the default attribute {@link Companion.NullableAndDefault#str() str} is set. * @return {@code true} if set */ public final boolean strIsSet() { return (optBits & OPT_BIT_STR) != 0; } /** * Returns {@code true} if the default attribute {@link Companion.NullableAndDefault#ints() ints} is set. * @return {@code true} if set */ public final boolean intsIsSet() { return (optBits & OPT_BIT_INTS) != 0; } /** * Returns {@code true} if the default attribute {@link Companion.NullableAndDefault#ords() ords} is set. * @return {@code true} if set */ public final boolean ordsIsSet() { return (optBits & OPT_BIT_ORDS) != 0; } /** * Returns {@code true} if the default attribute {@link Companion.NullableAndDefault#pols() pols} is set. * @return {@code true} if set */ public final boolean polsIsSet() { return (optBits & OPT_BIT_POLS) != 0; } /** * Returns {@code true} if the default attribute {@link Companion.NullableAndDefault#navs() navs} is set. * @return {@code true} if set */ public final boolean navsIsSet() { return (optBits & OPT_BIT_NAVS) != 0; } /** * Returns {@code true} if the {@link Companion.NullableAndDefault#lst() lst} has not been initialized * and will default to an empty list. * @return {@code true} if set */ public final boolean lstIsSet() { return lst != null; } /** * Returns {@code true} if the default attribute {@link Companion.NullableAndDefault#arrayInts() arrayInts} is set. * @return {@code true} if set */ public final boolean arrayIntsIsSet() { return arrayInts != null; } /** * 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 true; } /** * Converts to {@link ImmutableNullableAndDefault ImmutableNullableAndDefault}. * @return An immutable instance of NullableAndDefault */ public final ImmutableNullableAndDefault toImmutable() { return ImmutableNullableAndDefault.copyOf(this); } /** * This instance is equal to all instances of {@code ModifiableNullableAndDefault} 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; if (!(another instanceof ModifiableNullableAndDefault)) return false; ModifiableNullableAndDefault other = (ModifiableNullableAndDefault) another; return equalTo(other); } private boolean equalTo(ModifiableNullableAndDefault another) { List lst = this.lst != null ? this.lst : Collections.emptyList(); List str = str(); Set ints = ints(); int[] arrayInts = arrayInts(); SortedSet ords = ords(); Set pols = pols(); NavigableSet navs = navs(); return lst.equals(another.lst()) && Objects.equal(str, another.str()) && ints.equals(another.ints()) && Arrays.equals(arrayInts, another.arrayInts()) && Objects.equal(ords, another.ords()) && pols.equals(another.pols()) && navs.equals(another.navs()); } /** * Computes a hash code from attributes: {@code lst}, {@code str}, {@code ints}, {@code arrayInts}, {@code ords}, {@code pols}, {@code navs}. * @return hashCode value */ @Override public int hashCode() { int h = 31; h = h * 17 + (lst == null ? 1 : lst.hashCode()); List str = str(); h = h * 17 + Objects.hashCode(str); Set ints = ints(); h = h * 17 + (ints == null ? 0 : ints.hashCode()); int[] arrayInts = arrayInts(); h = h * 17 + Arrays.hashCode(arrayInts); SortedSet ords = ords(); h = h * 17 + Objects.hashCode(ords); Set pols = pols(); h = h * 17 + (pols == null ? 0 : pols.hashCode()); NavigableSet navs = navs(); h = h * 17 + (navs == null ? 0 : navs.hashCode()); return h; } /** * Generates a string representation of this {@code NullableAndDefault}. * If uninitialized, some attribute values may appear as question marks. * @return A string representation */ @Override public String toString() { return MoreObjects.toStringHelper("ModifiableNullableAndDefault") .add("lst", lst()) .add("str", str()) .add("ints", ints()) .add("arrayInts", Arrays.toString(arrayInts())) .add("ords", ords()) .add("pols", pols()) .add("navs", navs()) .toString(); } }





© 2015 - 2025 Weber Informatics LLC | Privacy Policy