org.immutables.fixture.nullable.ImmutableNullablyElements Maven / Gradle / Ivy
Show all versions of value-fixture Show documentation
package org.immutables.fixture.nullable;
import com.google.errorprone.annotations.CanIgnoreReturnValue;
import com.google.errorprone.annotations.Var;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
import javax.annotation.CheckReturnValue;
import javax.annotation.Nullable;
import javax.annotation.ParametersAreNonnullByDefault;
import javax.annotation.concurrent.Immutable;
import javax.annotation.concurrent.NotThreadSafe;
import org.immutables.value.Generated;
/**
* Immutable implementation of {@link NullablyElements}.
*
* Use the builder to create immutable instances:
* {@code ImmutableNullablyElements.builder()}.
*/
@Generated(from = "NullablyElements", generator = "Immutables")
@SuppressWarnings({"all"})
@ParametersAreNonnullByDefault
@javax.annotation.processing.Generated("org.immutables.processor.ProxyProcessor")
@Immutable
@CheckReturnValue
public final class ImmutableNullablyElements implements NullablyElements {
private final List al;
private final List sk;
private final Map bl;
private final Map sm;
private final Set rg;
private final Set ri;
private final List rj;
private final Set rk;
private ImmutableNullablyElements(
List al,
List sk,
Map bl,
Map sm,
Set rg,
Set ri,
List rj,
Set rk) {
this.al = al;
this.sk = sk;
this.bl = bl;
this.sm = sm;
this.rg = rg;
this.ri = ri;
this.rj = rj;
this.rk = rk;
}
/**
* @return The value of the {@code al} attribute
*/
@Override
public List al() {
return al;
}
/**
* @return The value of the {@code sk} attribute
*/
@Override
public List sk() {
return sk;
}
/**
* @return The value of the {@code bl} attribute
*/
@Override
public Map bl() {
return bl;
}
/**
* @return The value of the {@code sm} attribute
*/
@Override
public Map sm() {
return sm;
}
/**
* @return The value of the {@code rg} attribute
*/
@Override
public Set rg() {
return rg;
}
/**
* @return The value of the {@code ri} attribute
*/
@Override
public Set ri() {
return ri;
}
/**
* @return The value of the {@code rj} attribute
*/
@Override
public List rj() {
return rj;
}
/**
* @return The value of the {@code rk} attribute
*/
@Override
public Set rk() {
return rk;
}
/**
* Copy the current immutable object with elements that replace the content of {@link NullablyElements#al() al}.
* @param elements The elements to set
* @return A modified copy of {@code this} object
*/
public final ImmutableNullablyElements withAl(Void... elements) {
List newValue = createUnmodifiableList(false, createSafeList(Arrays.asList(elements), false, false));
return new ImmutableNullablyElements(newValue, this.sk, this.bl, this.sm, this.rg, this.ri, this.rj, this.rk);
}
/**
* Copy the current immutable object with elements that replace the content of {@link NullablyElements#al() al}.
* A shallow reference equality check is used to prevent copying of the same value by returning {@code this}.
* @param elements An iterable of al elements to set
* @return A modified copy of {@code this} object
*/
public final ImmutableNullablyElements withAl(Iterable extends Void> elements) {
if (this.al == elements) return this;
List newValue = createUnmodifiableList(false, createSafeList(elements, false, false));
return new ImmutableNullablyElements(newValue, this.sk, this.bl, this.sm, this.rg, this.ri, this.rj, this.rk);
}
/**
* Copy the current immutable object with elements that replace the content of {@link NullablyElements#sk() sk}.
* @param elements The elements to set
* @return A modified copy of {@code this} object
*/
public final ImmutableNullablyElements withSk(String... elements) {
List newValue = createUnmodifiableList(false, createSafeList(Arrays.asList(elements), false, true));
return new ImmutableNullablyElements(this.al, newValue, this.bl, this.sm, this.rg, this.ri, this.rj, this.rk);
}
/**
* Copy the current immutable object with elements that replace the content of {@link NullablyElements#sk() sk}.
* A shallow reference equality check is used to prevent copying of the same value by returning {@code this}.
* @param elements An iterable of sk elements to set
* @return A modified copy of {@code this} object
*/
public final ImmutableNullablyElements withSk(Iterable elements) {
if (this.sk == elements) return this;
List newValue = createUnmodifiableList(false, createSafeList(elements, false, true));
return new ImmutableNullablyElements(this.al, newValue, this.bl, this.sm, this.rg, this.ri, this.rj, this.rk);
}
/**
* Copy the current immutable object by replacing the {@link NullablyElements#bl() bl} map with the specified map.
* Nulls are not permitted as keys or values.
* A shallow reference equality check is used to prevent copying of the same value by returning {@code this}.
* @param entries The entries to be added to the bl map
* @return A modified copy of {@code this} object
*/
public final ImmutableNullablyElements withBl(Map entries) {
if (this.bl == entries) return this;
Map newValue = createUnmodifiableMap(false, false, entries);
return new ImmutableNullablyElements(this.al, this.sk, newValue, this.sm, this.rg, this.ri, this.rj, this.rk);
}
/**
* Copy the current immutable object by replacing the {@link NullablyElements#sm() sm} map with the specified map.
* Nulls are not permitted as keys or values.
* A shallow reference equality check is used to prevent copying of the same value by returning {@code this}.
* @param entries The entries to be added to the sm map
* @return A modified copy of {@code this} object
*/
public final ImmutableNullablyElements withSm(Map entries) {
if (this.sm == entries) return this;
Map newValue = createUnmodifiableMap(false, true, entries);
return new ImmutableNullablyElements(this.al, this.sk, this.bl, newValue, this.rg, this.ri, this.rj, this.rk);
}
/**
* Copy the current immutable object with elements that replace the content of {@link NullablyElements#rg() rg}.
* @param elements The elements to set
* @return A modified copy of {@code this} object
*/
public final ImmutableNullablyElements withRg(String... elements) {
Set newValue = createUnmodifiableSet(createSafeList(Arrays.asList(elements), true, false));
return new ImmutableNullablyElements(this.al, this.sk, this.bl, this.sm, newValue, this.ri, this.rj, this.rk);
}
/**
* Copy the current immutable object with elements that replace the content of {@link NullablyElements#rg() rg}.
* A shallow reference equality check is used to prevent copying of the same value by returning {@code this}.
* @param elements An iterable of rg elements to set
* @return A modified copy of {@code this} object
*/
public final ImmutableNullablyElements withRg(Iterable elements) {
if (this.rg == elements) return this;
Set newValue = createUnmodifiableSet(createSafeList(elements, true, false));
return new ImmutableNullablyElements(this.al, this.sk, this.bl, this.sm, newValue, this.ri, this.rj, this.rk);
}
/**
* Copy the current immutable object with elements that replace the content of {@link NullablyElements#ri() ri}.
* @param elements The elements to set
* @return A modified copy of {@code this} object
*/
public final ImmutableNullablyElements withRi(Integer... elements) {
Set newValue = createUnmodifiableSet(createSafeList(Arrays.asList(elements), false, true));
return new ImmutableNullablyElements(this.al, this.sk, this.bl, this.sm, this.rg, newValue, this.rj, this.rk);
}
/**
* Copy the current immutable object with elements that replace the content of {@link NullablyElements#ri() ri}.
* A shallow reference equality check is used to prevent copying of the same value by returning {@code this}.
* @param elements An iterable of ri elements to set
* @return A modified copy of {@code this} object
*/
public final ImmutableNullablyElements withRi(Iterable extends Integer> elements) {
if (this.ri == elements) return this;
Set newValue = createUnmodifiableSet(createSafeList(elements, false, true));
return new ImmutableNullablyElements(this.al, this.sk, this.bl, this.sm, this.rg, newValue, this.rj, this.rk);
}
/**
* Copy the current immutable object with elements that replace the content of {@link NullablyElements#rj() rj}.
* @param elements The elements to set
* @return A modified copy of {@code this} object
*/
public final ImmutableNullablyElements withRj(Integer... elements) {
List newValue = createUnmodifiableList(false, createSafeList(Arrays.asList(elements), false, false));
return new ImmutableNullablyElements(this.al, this.sk, this.bl, this.sm, this.rg, this.ri, newValue, this.rk);
}
/**
* Copy the current immutable object with elements that replace the content of {@link NullablyElements#rj() rj}.
* A shallow reference equality check is used to prevent copying of the same value by returning {@code this}.
* @param elements An iterable of rj elements to set
* @return A modified copy of {@code this} object
*/
public final ImmutableNullablyElements withRj(Iterable extends Integer> elements) {
if (this.rj == elements) return this;
List newValue = createUnmodifiableList(false, createSafeList(elements, false, false));
return new ImmutableNullablyElements(this.al, this.sk, this.bl, this.sm, this.rg, this.ri, newValue, this.rk);
}
/**
* Copy the current immutable object with elements that replace the content of {@link NullablyElements#rk() rk}.
* @param elements The elements to set
* @return A modified copy of {@code this} object
*/
public final ImmutableNullablyElements withRk(int... elements) {
ArrayList wrappedList = new ArrayList<>(elements.length);
for (int element : elements) {
wrappedList.add(element);
}
Set newValue = createUnmodifiableSet(wrappedList);
return new ImmutableNullablyElements(this.al, this.sk, this.bl, this.sm, this.rg, this.ri, this.rj, newValue);
}
/**
* Copy the current immutable object with elements that replace the content of {@link NullablyElements#rk() rk}.
* A shallow reference equality check is used to prevent copying of the same value by returning {@code this}.
* @param elements An iterable of rk elements to set
* @return A modified copy of {@code this} object
*/
public final ImmutableNullablyElements withRk(Iterable elements) {
if (this.rk == elements) return this;
Set newValue = createUnmodifiableSet(createSafeList(elements, true, false));
return new ImmutableNullablyElements(this.al, this.sk, this.bl, this.sm, this.rg, this.ri, this.rj, newValue);
}
/**
* This instance is equal to all instances of {@code ImmutableNullablyElements} 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 ImmutableNullablyElements
&& equalTo(0, (ImmutableNullablyElements) another);
}
private boolean equalTo(int synthetic, ImmutableNullablyElements another) {
return al.equals(another.al)
&& sk.equals(another.sk)
&& bl.equals(another.bl)
&& sm.equals(another.sm)
&& rg.equals(another.rg)
&& ri.equals(another.ri)
&& rj.equals(another.rj)
&& rk.equals(another.rk);
}
/**
* Computes a hash code from attributes: {@code al}, {@code sk}, {@code bl}, {@code sm}, {@code rg}, {@code ri}, {@code rj}, {@code rk}.
* @return hashCode value
*/
@Override
public int hashCode() {
@Var int h = 5381;
h += (h << 5) + al.hashCode();
h += (h << 5) + sk.hashCode();
h += (h << 5) + bl.hashCode();
h += (h << 5) + sm.hashCode();
h += (h << 5) + rg.hashCode();
h += (h << 5) + ri.hashCode();
h += (h << 5) + rj.hashCode();
h += (h << 5) + rk.hashCode();
return h;
}
/**
* Prints the immutable value {@code NullablyElements} with attribute values.
* @return A string representation of the value
*/
@Override
public String toString() {
return "NullablyElements{"
+ "al=" + al
+ ", sk=" + sk
+ ", bl=" + bl
+ ", sm=" + sm
+ ", rg=" + rg
+ ", ri=" + ri
+ ", rj=" + rj
+ ", rk=" + rk
+ "}";
}
/**
* Creates an immutable copy of a {@link NullablyElements} 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 NullablyElements instance
*/
public static ImmutableNullablyElements copyOf(NullablyElements instance) {
if (instance instanceof ImmutableNullablyElements) {
return (ImmutableNullablyElements) instance;
}
return ImmutableNullablyElements.builder()
.from(instance)
.build();
}
/**
* Creates a builder for {@link ImmutableNullablyElements ImmutableNullablyElements}.
*
* ImmutableNullablyElements.builder()
* .addAl|addAllAl(Void) // {@link NullablyElements#al() al} elements
* .addSk|addAllSk(String) // {@link NullablyElements#sk() sk} elements
* .putBl|putAllBl(String => Integer) // {@link NullablyElements#bl() bl} mappings
* .putSm|putAllSm(String => Integer) // {@link NullablyElements#sm() sm} mappings
* .addRg|addAllRg(String) // {@link NullablyElements#rg() rg} elements
* .addRi|addAllRi(Integer) // {@link NullablyElements#ri() ri} elements
* .addRj|addAllRj(Integer) // {@link NullablyElements#rj() rj} elements
* .addRk|addAllRk(int) // {@link NullablyElements#rk() rk} elements
* .build();
*
* @return A new ImmutableNullablyElements builder
*/
public static ImmutableNullablyElements.Builder builder() {
return new ImmutableNullablyElements.Builder();
}
/**
* Builds instances of type {@link ImmutableNullablyElements ImmutableNullablyElements}.
* 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.
*/
@Generated(from = "NullablyElements", generator = "Immutables")
@NotThreadSafe
public static final class Builder {
private List al = new ArrayList();
private List sk = new ArrayList();
private Map bl = new LinkedHashMap();
private Map sm = new LinkedHashMap();
private List rg = new ArrayList();
private List ri = new ArrayList();
private List rj = new ArrayList();
private List rk = new ArrayList();
private Builder() {
}
/**
* Fill a builder with attribute values from the provided {@code NullablyElements} instance.
* Regular attribute values will be replaced with those from the given instance.
* Absent optional values will not replace present values.
* Collection elements and entries will be added, not replaced.
* @param instance The instance from which to copy values
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
public final Builder from(NullablyElements instance) {
Objects.requireNonNull(instance, "instance");
addAllAl(instance.al());
addAllSk(instance.sk());
putAllBl(instance.bl());
putAllSm(instance.sm());
addAllRg(instance.rg());
addAllRi(instance.ri());
addAllRj(instance.rj());
addAllRk(instance.rk());
return this;
}
/**
* Adds one element to {@link NullablyElements#al() al} list.
* @param element A al element
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
public final Builder addAl(@Nullable Void element) {
this.al.add(element);
return this;
}
/**
* Adds elements to {@link NullablyElements#al() al} list.
* @param elements An array of al elements
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
public final Builder addAl(Void... elements) {
for (Void element : elements) {
this.al.add(element);
}
return this;
}
/**
* Sets or replaces all elements for {@link NullablyElements#al() al} list.
* @param elements An iterable of al elements
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
public final Builder al(Iterable extends Void> elements) {
this.al.clear();
return addAllAl(elements);
}
/**
* Adds elements to {@link NullablyElements#al() al} list.
* @param elements An iterable of al elements
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
public final Builder addAllAl(Iterable extends Void> elements) {
for (Void element : elements) {
this.al.add(element);
}
return this;
}
/**
* Adds one element to {@link NullablyElements#sk() sk} list.
* @param element A sk element
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
public final Builder addSk(@Nullable String element) {
if (element != null) this.sk.add(element);
return this;
}
/**
* Adds elements to {@link NullablyElements#sk() sk} list.
* @param elements An array of sk elements
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
public final Builder addSk(String... elements) {
for (String element : elements) {
if (element != null) this.sk.add(element);
}
return this;
}
/**
* Sets or replaces all elements for {@link NullablyElements#sk() sk} list.
* @param elements An iterable of sk elements
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
public final Builder sk(Iterable elements) {
this.sk.clear();
return addAllSk(elements);
}
/**
* Adds elements to {@link NullablyElements#sk() sk} list.
* @param elements An iterable of sk elements
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
public final Builder addAllSk(Iterable elements) {
for (String element : elements) {
if (element != null) this.sk.add(element);
}
return this;
}
/**
* Put one entry to the {@link NullablyElements#bl() bl} map.
* @param key The key in the bl map
* @param value The associated value in the bl map
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
public final Builder putBl(@Nullable String key, @Nullable Integer value) {
this.bl.put(key, value);
return this;
}
/**
* Put one entry to the {@link NullablyElements#bl() bl} map. Nulls are not permitted
* @param entry The key and value entry
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
public final Builder putBl(Map.Entry entry) {
String k = entry.getKey();
Integer v = entry.getValue();
this.bl.put(k, v);
return this;
}
/**
* Sets or replaces all mappings from the specified map as entries for the {@link NullablyElements#bl() bl} map. Nulls are not permitted
* @param entries The entries that will be added to the bl map
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
public final Builder bl(Map entries) {
this.bl.clear();
return putAllBl(entries);
}
/**
* Put all mappings from the specified map as entries to {@link NullablyElements#bl() bl} map. Nulls are not permitted
* @param entries The entries that will be added to the bl map
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
public final Builder putAllBl(Map entries) {
for (Map.Entry e : entries.entrySet()) {
String k = e.getKey();
Integer v = e.getValue();
this.bl.put(k, v);
}
return this;
}
/**
* Put one entry to the {@link NullablyElements#sm() sm} map.
* @param key The key in the sm map
* @param value The associated value in the sm map
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
public final Builder putSm(@Nullable String key, @Nullable Integer value) {
if (value != null && key != null) this.sm.put(key, value);
return this;
}
/**
* Put one entry to the {@link NullablyElements#sm() sm} map. Nulls are not permitted
* @param entry The key and value entry
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
public final Builder putSm(Map.Entry entry) {
String k = entry.getKey();
Integer v = entry.getValue();
if (k != null && v != null) this.sm.put(k, v);
return this;
}
/**
* Sets or replaces all mappings from the specified map as entries for the {@link NullablyElements#sm() sm} map. Nulls are not permitted
* @param entries The entries that will be added to the sm map
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
public final Builder sm(Map entries) {
this.sm.clear();
return putAllSm(entries);
}
/**
* Put all mappings from the specified map as entries to {@link NullablyElements#sm() sm} map. Nulls are not permitted
* @param entries The entries that will be added to the sm map
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
public final Builder putAllSm(Map entries) {
for (Map.Entry e : entries.entrySet()) {
String k = e.getKey();
Integer v = e.getValue();
if (k != null && v != null) this.sm.put(k, v);
}
return this;
}
/**
* Adds one element to {@link NullablyElements#rg() rg} set.
* @param element A rg element
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
public final Builder addRg(String element) {
this.rg.add(Objects.requireNonNull(element, "rg element"));
return this;
}
/**
* Adds elements to {@link NullablyElements#rg() rg} set.
* @param elements An array of rg elements
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
public final Builder addRg(String... elements) {
for (String element : elements) {
this.rg.add(Objects.requireNonNull(element, "rg element"));
}
return this;
}
/**
* Sets or replaces all elements for {@link NullablyElements#rg() rg} set.
* @param elements An iterable of rg elements
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
public final Builder rg(Iterable elements) {
this.rg.clear();
return addAllRg(elements);
}
/**
* Adds elements to {@link NullablyElements#rg() rg} set.
* @param elements An iterable of rg elements
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
public final Builder addAllRg(Iterable elements) {
for (String element : elements) {
this.rg.add(Objects.requireNonNull(element, "rg element"));
}
return this;
}
/**
* Adds one element to {@link NullablyElements#ri() ri} set.
* @param element A ri element
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
public final Builder addRi(@Nullable Integer element) {
if (element != null) this.ri.add(element);
return this;
}
/**
* Adds elements to {@link NullablyElements#ri() ri} set.
* @param elements An array of ri elements
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
public final Builder addRi(Integer... elements) {
for (Integer element : elements) {
if (element != null) this.ri.add(element);
}
return this;
}
/**
* Sets or replaces all elements for {@link NullablyElements#ri() ri} set.
* @param elements An iterable of ri elements
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
public final Builder ri(Iterable extends Integer> elements) {
this.ri.clear();
return addAllRi(elements);
}
/**
* Adds elements to {@link NullablyElements#ri() ri} set.
* @param elements An iterable of ri elements
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
public final Builder addAllRi(Iterable extends Integer> elements) {
for (Integer element : elements) {
if (element != null) this.ri.add(element);
}
return this;
}
/**
* Adds one element to {@link NullablyElements#rj() rj} list.
* @param element A rj element
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
public final Builder addRj(@Nullable Integer element) {
this.rj.add(element);
return this;
}
/**
* Adds elements to {@link NullablyElements#rj() rj} list.
* @param elements An array of rj elements
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
public final Builder addRj(Integer... elements) {
for (Integer element : elements) {
this.rj.add(element);
}
return this;
}
/**
* Sets or replaces all elements for {@link NullablyElements#rj() rj} list.
* @param elements An iterable of rj elements
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
public final Builder rj(Iterable extends Integer> elements) {
this.rj.clear();
return addAllRj(elements);
}
/**
* Adds elements to {@link NullablyElements#rj() rj} list.
* @param elements An iterable of rj elements
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
public final Builder addAllRj(Iterable extends Integer> elements) {
for (Integer element : elements) {
this.rj.add(element);
}
return this;
}
/**
* Adds one element to {@link NullablyElements#rk() rk} set.
* @param element A rk element
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
public final Builder addRk(int element) {
this.rk.add(element);
return this;
}
/**
* Adds elements to {@link NullablyElements#rk() rk} set.
* @param elements An array of rk elements
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
public final Builder addRk(int... elements) {
for (int element : elements) {
this.rk.add(element);
}
return this;
}
/**
* Sets or replaces all elements for {@link NullablyElements#rk() rk} set.
* @param elements An iterable of rk elements
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
public final Builder rk(Iterable elements) {
this.rk.clear();
return addAllRk(elements);
}
/**
* Adds elements to {@link NullablyElements#rk() rk} set.
* @param elements An iterable of rk elements
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
public final Builder addAllRk(Iterable elements) {
for (Integer element : elements) {
this.rk.add(Objects.requireNonNull(element, "rk element"));
}
return this;
}
/**
* Builds a new {@link ImmutableNullablyElements ImmutableNullablyElements}.
* @return An immutable instance of NullablyElements
* @throws java.lang.IllegalStateException if any required attributes are missing
*/
public ImmutableNullablyElements build() {
return new ImmutableNullablyElements(
createUnmodifiableList(true, al),
createUnmodifiableList(true, sk),
createUnmodifiableMap(false, false, bl),
createUnmodifiableMap(false, false, sm),
createUnmodifiableSet(rg),
createUnmodifiableSet(ri),
createUnmodifiableList(true, rj),
createUnmodifiableSet(rk));
}
}
private static List createSafeList(Iterable extends T> iterable, boolean checkNulls, boolean skipNulls) {
ArrayList list;
if (iterable instanceof Collection>) {
int size = ((Collection>) iterable).size();
if (size == 0) return Collections.emptyList();
list = new ArrayList<>();
} else {
list = new ArrayList<>();
}
for (T element : iterable) {
if (skipNulls && element == null) continue;
if (checkNulls) Objects.requireNonNull(element, "element");
list.add(element);
}
return list;
}
private static List createUnmodifiableList(boolean clone, List list) {
switch(list.size()) {
case 0: return Collections.emptyList();
case 1: return Collections.singletonList(list.get(0));
default:
if (clone) {
return Collections.unmodifiableList(new ArrayList<>(list));
} else {
if (list instanceof ArrayList>) {
((ArrayList>) list).trimToSize();
}
return Collections.unmodifiableList(list);
}
}
}
/** Unmodifiable set constructed from list to avoid rehashing. */
private static Set createUnmodifiableSet(List list) {
switch(list.size()) {
case 0: return Collections.emptySet();
case 1: return Collections.singleton(list.get(0));
default:
Set set = new LinkedHashSet<>(list.size());
set.addAll(list);
return Collections.unmodifiableSet(set);
}
}
private static Map createUnmodifiableMap(boolean checkNulls, boolean skipNulls, Map extends K, ? extends V> map) {
switch (map.size()) {
case 0: return Collections.emptyMap();
case 1: {
Map.Entry extends K, ? extends V> e = map.entrySet().iterator().next();
K k = e.getKey();
V v = e.getValue();
if (checkNulls) {
Objects.requireNonNull(k, "key");
Objects.requireNonNull(v, "value");
}
if (skipNulls && (k == null || v == null)) {
return Collections.emptyMap();
}
return Collections.singletonMap(k, v);
}
default: {
Map linkedMap = new LinkedHashMap<>(map.size());
if (skipNulls || checkNulls) {
for (Map.Entry extends K, ? extends V> e : map.entrySet()) {
K k = e.getKey();
V v = e.getValue();
if (skipNulls) {
if (k == null || v == null) continue;
} else if (checkNulls) {
Objects.requireNonNull(k, "key");
Objects.requireNonNull(v, "value");
}
linkedMap.put(k, v);
}
} else {
linkedMap.putAll(map);
}
return Collections.unmodifiableMap(linkedMap);
}
}
}
}