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

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

package org.immutables.fixture.modifiable;

import com.google.common.base.MoreObjects;
import com.google.common.base.Preconditions;
import com.google.common.collect.ArrayListMultimap;
import com.google.common.collect.BiMap;
import com.google.common.collect.HashBiMap;
import com.google.common.collect.HashMultimap;
import com.google.common.collect.HashMultiset;
import com.google.common.collect.ListMultimap;
import com.google.common.collect.Multimap;
import com.google.common.collect.Multiset;
import com.google.common.collect.SetMultimap;
import java.util.Arrays;
import java.util.Map;
import javax.annotation.Generated;
import javax.annotation.Nullable;
import javax.annotation.ParametersAreNonnullByDefault;
import javax.annotation.concurrent.NotThreadSafe;

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

Use the {@link #create()} static factory methods to create new instances. *

ModifiableExtra is not thread-safe */ @SuppressWarnings("all") @ParametersAreNonnullByDefault @Generated({"Modifiables.generator", "Companion.Extra"}) @NotThreadSafe public final class ModifiableExtra implements Companion.Extra { private final HashMultiset bag = HashMultiset.create(); private final ArrayListMultimap index = ArrayListMultimap.create(); private final ArrayListMultimap indexList = ArrayListMultimap.create(); private final HashMultimap indexSet = HashMultimap.create(); private final HashBiMap biMap = HashBiMap.create(); private ModifiableExtra() {} /** * Construct a modifiable instance of {@code Extra}. * @param bag The value for the {@code bag} attribute * @param index The value for the {@code index} attribute * @param indexList The value for the {@code indexList} attribute * @param indexSet The value for the {@code indexSet} attribute * @param biMap The value for the {@code biMap} attribute * @return A new modifiable instance */ public static ModifiableExtra create(Iterable bag, Multimap index, Multimap indexList, Multimap indexSet, Map biMap) { return new ModifiableExtra() .addAllBag(bag) .putAllIndex(index) .putAllIndexList(indexList) .putAllIndexSet(indexSet) .putAllBiMap(biMap); } /** * Construct a modifiable instance of {@code Extra}. * @return A new modifiable instance */ public static ModifiableExtra create() { return new ModifiableExtra(); } /** * @return modifiable multiset {@code bag} */ @Override public final Multiset bag() { return bag; } /** * @return value of {@code index} attribute */ @Override public final Multimap index() { return index; } /** * @return value of {@code indexList} attribute */ @Override public final ListMultimap indexList() { return indexList; } /** * @return value of {@code indexSet} attribute */ @Override public final SetMultimap indexSet() { return indexSet; } /** * @return value of {@code biMap} attribute */ @Override public final BiMap biMap() { return biMap; } /** * Clears the object by setting all attributes to their initial values. * @return {@code this} for use in a chained invocation */ public ModifiableExtra clear() { bag.clear(); index.clear(); indexList.clear(); indexSet.clear(); biMap.clear(); return this; } /** * Fill this modifiable instance with attribute values from the provided {@link Companion.Extra} 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 ModifiableExtra from(Companion.Extra instance) { Preconditions.checkNotNull(instance, "instance"); addAllBag(instance.bag()); putAllIndex(instance.index()); putAllIndexList(instance.indexList()); putAllIndexSet(instance.indexSet()); putAllBiMap(instance.biMap()); return this; } /** * Adds one element to {@code bag} multiset. * @param element The bag element * @return {@code this} for use in a chained invocation */ public ModifiableExtra addBag(String element) { bag.add(Preconditions.checkNotNull(element, "bag element")); return this; } /** * Adds elements to {@code bag} multiset. * @param elements An array of bag elements * @return {@code this} for use in a chained invocation */ public final ModifiableExtra addBag(String... elements) { for (String element : elements) { addBag(Preconditions.checkNotNull(element, "bag element")); } return this; } /** * Sets or replaces all elements for {@code bag} multiset. * @param elements An iterable of bag elements * @return {@code this} for use in a chained invocation */ public ModifiableExtra setBag(Iterable elements) { bag.clear(); return addAllBag(elements); } /** * Adds elements to {@code bag} multiset. * @param elements An iterable of bag elements * @return {@code this} for use in a chained invocation */ public ModifiableExtra addAllBag(Iterable elements) { for (String element : elements) { bag.add(Preconditions.checkNotNull(element, "bag element")); } return this; } /** * Put all mappings from the specified key to values for {@code index} true. Nulls are not permitted * @param key The key for index * @param values The values for index * @return {@code this} for use in a chained invocation */ public final ModifiableExtra putIndex(int key, String... values) { return putAllIndex(key, Arrays.asList(values)); } /** * Put all mappings from the specified key to values for {@code index} true. Nulls are not permitted * @param key The key for index * @param values The values for index * @return {@code this} for use in a chained invocation */ public ModifiableExtra putAllIndex(int key, Iterable values) { index.putAll(key, values); return this; } /** * Put one entry to the {@code index} map. * @param key The key in index map * @param value The associated value in the index map * @return {@code this} for use in a chained invocation */ public ModifiableExtra putIndex(int key, String value) { index.put( key, Preconditions.checkNotNull(value, "index value")); return this; } /** * Sets or replaces all mappings from the specified map as entries for the {@code index} map. * Nulls are not permitted as keys or values. * @param entries The entries that will be added to the index map * @return {@code this} for use in a chained invocation */ public ModifiableExtra setIndex(Multimap entries) { index.clear(); return putAllIndex(entries); } /** * Put all mappings from the specified map as entries to the {@code index} map. * Nulls are not permitted as keys or values. * @param entries to be added to index map * @return {@code this} for use in a chained invocation */ public ModifiableExtra putAllIndex(Multimap entries) { for (Map.Entry entry : entries.entries()) { index.put( Preconditions.checkNotNull(entry.getKey(), "index key"), Preconditions.checkNotNull(entry.getValue(), "index value")); } return this; } /** * Put all mappings from the specified key to values for {@code indexList} true. Nulls are not permitted * @param key The key for indexList * @param values The values for indexList * @return {@code this} for use in a chained invocation */ public final ModifiableExtra putIndexList(int key, String... values) { return putAllIndexList(key, Arrays.asList(values)); } /** * Put all mappings from the specified key to values for {@code indexList} true. Nulls are not permitted * @param key The key for indexList * @param values The values for indexList * @return {@code this} for use in a chained invocation */ public ModifiableExtra putAllIndexList(int key, Iterable values) { indexList.putAll(key, values); return this; } /** * Put one entry to the {@code indexList} map. * @param key The key in indexList map * @param value The associated value in the indexList map * @return {@code this} for use in a chained invocation */ public ModifiableExtra putIndexList(int key, String value) { indexList.put( key, Preconditions.checkNotNull(value, "indexList value")); return this; } /** * Sets or replaces all mappings from the specified map as entries for the {@code indexList} map. * Nulls are not permitted as keys or values. * @param entries The entries that will be added to the indexList map * @return {@code this} for use in a chained invocation */ public ModifiableExtra setIndexList(Multimap entries) { indexList.clear(); return putAllIndexList(entries); } /** * Put all mappings from the specified map as entries to the {@code indexList} map. * Nulls are not permitted as keys or values. * @param entries to be added to indexList map * @return {@code this} for use in a chained invocation */ public ModifiableExtra putAllIndexList(Multimap entries) { for (Map.Entry entry : entries.entries()) { indexList.put( Preconditions.checkNotNull(entry.getKey(), "indexList key"), Preconditions.checkNotNull(entry.getValue(), "indexList value")); } return this; } /** * Put all mappings from the specified key to values for {@code indexSet} true. Nulls are not permitted * @param key The key for indexSet * @param values The values for indexSet * @return {@code this} for use in a chained invocation */ public final ModifiableExtra putIndexSet(int key, String... values) { return putAllIndexSet(key, Arrays.asList(values)); } /** * Put all mappings from the specified key to values for {@code indexSet} true. Nulls are not permitted * @param key The key for indexSet * @param values The values for indexSet * @return {@code this} for use in a chained invocation */ public ModifiableExtra putAllIndexSet(int key, Iterable values) { indexSet.putAll(key, values); return this; } /** * Put one entry to the {@code indexSet} map. * @param key The key in indexSet map * @param value The associated value in the indexSet map * @return {@code this} for use in a chained invocation */ public ModifiableExtra putIndexSet(int key, String value) { indexSet.put( key, Preconditions.checkNotNull(value, "indexSet value")); return this; } /** * Sets or replaces all mappings from the specified map as entries for the {@code indexSet} map. * Nulls are not permitted as keys or values. * @param entries The entries that will be added to the indexSet map * @return {@code this} for use in a chained invocation */ public ModifiableExtra setIndexSet(Multimap entries) { indexSet.clear(); return putAllIndexSet(entries); } /** * Put all mappings from the specified map as entries to the {@code indexSet} map. * Nulls are not permitted as keys or values. * @param entries to be added to indexSet map * @return {@code this} for use in a chained invocation */ public ModifiableExtra putAllIndexSet(Multimap entries) { for (Map.Entry entry : entries.entries()) { indexSet.put( Preconditions.checkNotNull(entry.getKey(), "indexSet key"), Preconditions.checkNotNull(entry.getValue(), "indexSet value")); } return this; } /** * Put one entry to the {@code biMap} map. * @param key The key in biMap map * @param value The associated value in the biMap map * @return {@code this} for use in a chained invocation */ public ModifiableExtra putBiMap(int key, String value) { biMap.put( key, Preconditions.checkNotNull(value, "biMap value")); return this; } /** * Sets or replaces all mappings from the specified map as entries for the {@code biMap} map. * Nulls are not permitted as keys or values. * @param entries The entries that will be added to the biMap map * @return {@code this} for use in a chained invocation */ public ModifiableExtra setBiMap(Map entries) { biMap.clear(); return putAllBiMap(entries); } /** * Put all mappings from the specified map as entries to the {@code biMap} map. * Nulls are not permitted as keys or values. * @param entries to be added to biMap map * @return {@code this} for use in a chained invocation */ public ModifiableExtra putAllBiMap(Map entries) { for (Map.Entry entry : entries.entrySet()) { biMap.put( Preconditions.checkNotNull(entry.getKey(), "biMap key"), Preconditions.checkNotNull(entry.getValue(), "biMap value")); } 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 true; } /** * This instance is equal to all instances of {@code ModifiableExtra} 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 ModifiableExtra)) return false; ModifiableExtra other = (ModifiableExtra) another; return equalTo(other); } private boolean equalTo(ModifiableExtra another) { return bag.equals(another.bag) && index.equals(another.index) && indexList.equals(another.indexList) && indexSet.equals(another.indexSet) && biMap.equals(another.biMap); } /** * Computes a hash code from attributes: {@code bag}, {@code index}, {@code indexList}, {@code indexSet}, {@code biMap}. * @return hashCode value */ @Override public int hashCode() { int h = 31; h = h * 17 + bag.hashCode(); h = h * 17 + index.hashCode(); h = h * 17 + indexList.hashCode(); h = h * 17 + indexSet.hashCode(); h = h * 17 + biMap.hashCode(); return h; } /** * Generates a string representation of this {@code Extra}. * If uninitialized, some attribute values may appear as question marks. * @return A string representation */ @Override public String toString() { return MoreObjects.toStringHelper("ModifiableExtra") .add("bag", bag()) .add("index", index()) .add("indexList", indexList()) .add("indexSet", indexSet()) .add("biMap", biMap()) .toString(); } }





© 2015 - 2025 Weber Informatics LLC | Privacy Policy