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

org.immutables.fixture.generics.ModifiableSecondie Maven / Gradle / Ivy

package org.immutables.fixture.generics;

import com.google.common.base.MoreObjects;
import com.google.common.base.Objects;
import com.google.common.base.Preconditions;
import com.google.common.collect.ArrayListMultimap;
import com.google.common.collect.Multimap;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import javax.annotation.Generated;
import javax.annotation.Nullable;
import javax.annotation.ParametersAreNonnullByDefault;
import javax.annotation.concurrent.NotThreadSafe;

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

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

ModifiableSecondie is not thread-safe * @param generic parameter T * @param generic parameter V * @see ImmutableSecondie */ @SuppressWarnings("all") @ParametersAreNonnullByDefault @Generated({"Modifiables.generator", "Secondie"}) @NotThreadSafe public final class ModifiableSecondie implements Secondie { private static final long OPT_BIT_SET = 0x1L; private long optBits; private @Nullable V integer; private ArrayList list = null; private LinkedHashSet set = null; private final ArrayListMultimap coll = ArrayListMultimap.create(); private ModifiableSecondie() {} /** * Construct a modifiable instance of {@code Secondie}. * @param generic parameter T * @param generic parameter V * @param integer The value for the {@link Secondie#integer() integer} attribute (can be {@code null}) * @param list The value for the {@link Secondie#list() list} attribute (can be {@code null}) * @return A new modifiable instance */ public static ModifiableSecondie create(@Nullable V integer, @Nullable Iterable list) { return new ModifiableSecondie() .setInteger(integer) .addAllList(list); } /** * Construct a modifiable instance of {@code Secondie}. * @param generic parameter T * @param generic parameter V * @return A new modifiable instance */ public static ModifiableSecondie create() { return new ModifiableSecondie<>(); } /** * @return value of {@code integer} attribute, may be {@code null} */ @Override public final @Nullable V integer() { return integer; } /** * @return modifiable list {@code list} */ @Override public final @Nullable List list() { return list; } /** * @return assigned or, otherwise, newly computed, not cached value of {@code set} attribute */ @Override public final @Nullable Set set() { return setIsSet() ? set : Secondie.super.set(); } /** * @return value of {@code coll} attribute */ @Override public final Multimap coll() { return coll; } /** * @return newly computed, not cached value of {@code lst} attribute */ @Override public final @Nullable List lst() { return Secondie.super.lst(); } /** * Clears the object by setting all attributes to their initial values. * @return {@code this} for use in a chained invocation */ public ModifiableSecondie clear() { optBits = 0; integer = null; list = null; set = null; coll.clear(); return this; } /** * Fill this modifiable instance with attribute values from the provided {@link Secondie} 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 ModifiableSecondie from(Secondie instance) { Preconditions.checkNotNull(instance, "instance"); @Nullable V integerValue = instance.integer(); if (integerValue != null) { setInteger(integerValue); } addAllList(instance.list()); addAllSet(instance.set()); putAllColl(instance.coll()); return this; } /** * Assigns a value to the {@link Secondie#integer() integer} attribute. * @param integer The value for integer, can be {@code null} * @return {@code this} for use in a chained invocation */ public ModifiableSecondie setInteger(@Nullable V integer) { this.integer = integer; return this; } /** * Adds one element to {@link Secondie#list() list} list. * @param element The list element * @return {@code this} for use in a chained invocation */ public ModifiableSecondie addList(T element) { if (list == null) { list = new ArrayList(); } list.add(Preconditions.checkNotNull(element, "list element")); return this; } /** * Adds elements to {@link Secondie#list() list} list. * @param elements An array of list elements * @return {@code this} for use in a chained invocation */ @SafeVarargs public final ModifiableSecondie addList(T... elements) { for (T element : elements) { addList(Preconditions.checkNotNull(element, "list element")); } return this; } /** * Sets or replaces all elements for {@link Secondie#list() list} list. * @param elements An iterable of list elements, can be {@code null} * @return {@code this} for use in a chained invocation */ public ModifiableSecondie setList(@Nullable Iterable elements) { if (elements == null) { list = null; return this; } if (list == null) { list = new ArrayList(); } else { list.clear(); } return addAllList(elements); } /** * Adds elements to {@link Secondie#list() list} list. * @param elements An iterable of list elements * @return {@code this} for use in a chained invocation */ public ModifiableSecondie addAllList(Iterable elements) { if (list == null) { list = new ArrayList(); } for (T element : elements) { list.add(Preconditions.checkNotNull(element, "list element")); } return this; } /** * Adds one element to {@link Secondie#set() set} set. * @param element The set element * @return {@code this} for use in a chained invocation */ public ModifiableSecondie addSet(V element) { if (set == null) { set = new LinkedHashSet(); } set.add(Preconditions.checkNotNull(element, "set element")); optBits |= OPT_BIT_SET; return this; } /** * Adds elements to {@link Secondie#set() set} set. * @param elements An array of set elements * @return {@code this} for use in a chained invocation */ @SafeVarargs public final ModifiableSecondie addSet(V... elements) { for (V element : elements) { addSet(Preconditions.checkNotNull(element, "set element")); } optBits |= OPT_BIT_SET; return this; } /** * Sets or replaces all elements for {@link Secondie#set() set} set. * @param elements An iterable of set elements, can be {@code null} * @return {@code this} for use in a chained invocation */ public ModifiableSecondie setSet(@Nullable Iterable elements) { if (elements == null) { set = null; optBits |= OPT_BIT_SET; return this; } if (set == null) { set = new LinkedHashSet(); } else { set.clear(); } return addAllSet(elements); } /** * Adds elements to {@link Secondie#set() set} set. * @param elements An iterable of set elements * @return {@code this} for use in a chained invocation */ public ModifiableSecondie addAllSet(Iterable elements) { if (set == null) { set = new LinkedHashSet(); } for (V element : elements) { set.add(Preconditions.checkNotNull(element, "set element")); } optBits |= OPT_BIT_SET; return this; } /** * Put all mappings from the specified key to values for {@link Secondie#coll() coll} true. Nulls are not permitted * @param key The key for coll * @param values The values for coll * @return {@code this} for use in a chained invocation */ @SafeVarargs public final ModifiableSecondie putColl(T key, V... values) { return putAllColl(key, Arrays.asList(values)); } /** * Put all mappings from the specified key to values for {@link Secondie#coll() coll} true. Nulls are not permitted * @param key The key for coll * @param values The values for coll * @return {@code this} for use in a chained invocation */ public ModifiableSecondie putAllColl(T key, Iterable values) { coll.putAll(key, values); return this; } /** * Put one entry to the {@link Secondie#coll() coll} map. * @param key The key in coll map * @param value The associated value in the coll map * @return {@code this} for use in a chained invocation */ public ModifiableSecondie putColl(T key, V value) { coll.put( Preconditions.checkNotNull(key, "coll key"), Preconditions.checkNotNull(value, "coll value")); return this; } /** * Sets or replaces all mappings from the specified map as entries for the {@link Secondie#coll() coll} map. * Nulls are not permitted as keys or values. * @param entries The entries that will be added to the coll map * @return {@code this} for use in a chained invocation */ public ModifiableSecondie setColl(Multimap entries) { coll.clear(); return putAllColl(entries); } /** * Put all mappings from the specified map as entries to the {@link Secondie#coll() coll} map. * Nulls are not permitted as keys or values. * @param entries to be added to coll map * @return {@code this} for use in a chained invocation */ public ModifiableSecondie putAllColl(Multimap entries) { for (Map.Entry entry : entries.entries()) { coll.put( Preconditions.checkNotNull(entry.getKey(), "coll key"), Preconditions.checkNotNull(entry.getValue(), "coll value")); } return this; } /** * Returns {@code true} if the default attribute {@link Secondie#set() set} is set. * @return {@code true} if set */ public final boolean setIsSet() { return (optBits & OPT_BIT_SET) != 0; } /** * 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 ImmutableSecondie ImmutableSecondie}. * @return An immutable instance of Secondie */ public final ImmutableSecondie toImmutable() { return ImmutableSecondie.copyOf(this); } /** * This instance is equal to all instances of {@code ModifiableSecondie} 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 ModifiableSecondie)) return false; ModifiableSecondie other = (ModifiableSecondie) another; return equalTo(other); } private boolean equalTo(ModifiableSecondie another) { Set set = set(); List lst = lst(); return Objects.equal(integer, another.integer) && Objects.equal(list, another.list) && Objects.equal(set, another.set()) && coll.equals(another.coll) && Objects.equal(lst, another.lst()); } /** * Computes a hash code from attributes: {@code integer}, {@code list}, {@code set}, {@code coll}, {@code lst}. * @return hashCode value */ @Override public int hashCode() { int h = 31; h = h * 17 + Objects.hashCode(integer); h = h * 17 + Objects.hashCode(list); Set set = set(); h = h * 17 + Objects.hashCode(set); h = h * 17 + coll.hashCode(); List lst = lst(); h = h * 17 + Objects.hashCode(lst); return h; } /** * Generates a string representation of this {@code Secondie}. * If uninitialized, some attribute values may appear as question marks. * @return A string representation */ @Override public String toString() { return MoreObjects.toStringHelper("ModifiableSecondie") .add("integer", integer()) .add("list", list()) .add("set", set()) .add("coll", coll()) .toString(); } }





© 2015 - 2025 Weber Informatics LLC | Privacy Policy