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

com.io7m.r2.core.R2MaskInstances Maven / Gradle / Ivy

There is a newer version: 0.2.1
Show newest version
package com.io7m.r2.core;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Objects;
import javax.annotation.Generated;

/**
 * The set of mask instances that will be rendered.
 */
@SuppressWarnings({"all"})
@Generated({"Immutables.generator", "R2MaskInstancesType"})
public final class R2MaskInstances implements R2MaskInstancesType {
  private final List singles;
  private final List batched;

  private R2MaskInstances(
      List singles,
      List batched) {
    this.singles = singles;
    this.batched = batched;
  }

  /**
   * @return The list of single instances that will be rendered
   */
  @Override
  public List singles() {
    return singles;
  }

  /**
   * @return The list of batched instances that will be rendered
   */
  @Override
  public List batched() {
    return batched;
  }

  /**
   * Copy the current immutable object with elements that replace the content of {@link R2MaskInstancesType#singles() singles}.
   * @param elements The elements to set
   * @return A modified copy of {@code this} object
   */
  public final R2MaskInstances withSingles(R2InstanceSingleType... elements) {
    List newValue = createUnmodifiableList(false, createSafeList(Arrays.asList(elements), true, false));
    return new R2MaskInstances(newValue, this.batched);
  }

  /**
   * Copy the current immutable object with elements that replace the content of {@link R2MaskInstancesType#singles() singles}.
   * A shallow reference equality check is used to prevent copying of the same value by returning {@code this}.
   * @param elements An iterable of singles elements to set
   * @return A modified copy of {@code this} object
   */
  public final R2MaskInstances withSingles(Iterable elements) {
    if (this.singles == elements) return this;
    List newValue = createUnmodifiableList(false, createSafeList(elements, true, false));
    return new R2MaskInstances(newValue, this.batched);
  }

  /**
   * Copy the current immutable object with elements that replace the content of {@link R2MaskInstancesType#batched() batched}.
   * @param elements The elements to set
   * @return A modified copy of {@code this} object
   */
  public final R2MaskInstances withBatched(R2InstanceBatchedType... elements) {
    List newValue = createUnmodifiableList(false, createSafeList(Arrays.asList(elements), true, false));
    return new R2MaskInstances(this.singles, newValue);
  }

  /**
   * Copy the current immutable object with elements that replace the content of {@link R2MaskInstancesType#batched() batched}.
   * A shallow reference equality check is used to prevent copying of the same value by returning {@code this}.
   * @param elements An iterable of batched elements to set
   * @return A modified copy of {@code this} object
   */
  public final R2MaskInstances withBatched(Iterable elements) {
    if (this.batched == elements) return this;
    List newValue = createUnmodifiableList(false, createSafeList(elements, true, false));
    return new R2MaskInstances(this.singles, newValue);
  }

  /**
   * This instance is equal to all instances of {@code R2MaskInstances} that have equal attribute values.
   * @return {@code true} if {@code this} is equal to {@code another} instance
   */
  @Override
  public boolean equals(Object another) {
    if (this == another) return true;
    return another instanceof R2MaskInstances
        && equalTo((R2MaskInstances) another);
  }

  private boolean equalTo(R2MaskInstances another) {
    return singles.equals(another.singles)
        && batched.equals(another.batched);
  }

  /**
   * Computes a hash code from attributes: {@code singles}, {@code batched}.
   * @return hashCode value
   */
  @Override
  public int hashCode() {
    int h = 31;
    h = h * 17 + singles.hashCode();
    h = h * 17 + batched.hashCode();
    return h;
  }

  /**
   * Prints the immutable value {@code R2MaskInstances} with attribute values.
   * @return A string representation of the value
   */
  @Override
  public String toString() {
    return "R2MaskInstances{"
        + "singles=" + singles
        + ", batched=" + batched
        + "}";
  }

  /**
   * Creates an immutable copy of a {@link R2MaskInstancesType} 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 R2MaskInstances instance
   */
  public static R2MaskInstances copyOf(R2MaskInstancesType instance) {
    if (instance instanceof R2MaskInstances) {
      return (R2MaskInstances) instance;
    }
    return R2MaskInstances.builder()
        .from(instance)
        .build();
  }

  /**
   * Creates a builder for {@link R2MaskInstances R2MaskInstances}.
   * @return A new R2MaskInstances builder
   */
  public static R2MaskInstances.Builder builder() {
    return new R2MaskInstances.Builder();
  }

  /**
   * Builds instances of type {@link R2MaskInstances R2MaskInstances}.
   * 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. */ public static final class Builder { private List singles = new ArrayList(); private List batched = new ArrayList(); private Builder() { } /** * Fill a builder with attribute values from the provided {@code R2MaskInstancesType} 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 */ public final Builder from(R2MaskInstancesType instance) { Objects.requireNonNull(instance, "instance"); addAllSingles(instance.singles()); addAllBatched(instance.batched()); return this; } /** * Adds one element to {@link R2MaskInstancesType#singles() singles} list. * @param element A singles element * @return {@code this} builder for use in a chained invocation */ public final Builder addSingles(R2InstanceSingleType element) { this.singles.add(Objects.requireNonNull(element, "singles element")); return this; } /** * Adds elements to {@link R2MaskInstancesType#singles() singles} list. * @param elements An array of singles elements * @return {@code this} builder for use in a chained invocation */ public final Builder addSingles(R2InstanceSingleType... elements) { for (R2InstanceSingleType element : elements) { this.singles.add(Objects.requireNonNull(element, "singles element")); } return this; } /** * Sets or replaces all elements for {@link R2MaskInstancesType#singles() singles} list. * @param elements An iterable of singles elements * @return {@code this} builder for use in a chained invocation */ public final Builder setSingles(Iterable elements) { this.singles.clear(); return addAllSingles(elements); } /** * Adds elements to {@link R2MaskInstancesType#singles() singles} list. * @param elements An iterable of singles elements * @return {@code this} builder for use in a chained invocation */ public final Builder addAllSingles(Iterable elements) { for (R2InstanceSingleType element : elements) { this.singles.add(Objects.requireNonNull(element, "singles element")); } return this; } /** * Adds one element to {@link R2MaskInstancesType#batched() batched} list. * @param element A batched element * @return {@code this} builder for use in a chained invocation */ public final Builder addBatched(R2InstanceBatchedType element) { this.batched.add(Objects.requireNonNull(element, "batched element")); return this; } /** * Adds elements to {@link R2MaskInstancesType#batched() batched} list. * @param elements An array of batched elements * @return {@code this} builder for use in a chained invocation */ public final Builder addBatched(R2InstanceBatchedType... elements) { for (R2InstanceBatchedType element : elements) { this.batched.add(Objects.requireNonNull(element, "batched element")); } return this; } /** * Sets or replaces all elements for {@link R2MaskInstancesType#batched() batched} list. * @param elements An iterable of batched elements * @return {@code this} builder for use in a chained invocation */ public final Builder setBatched(Iterable elements) { this.batched.clear(); return addAllBatched(elements); } /** * Adds elements to {@link R2MaskInstancesType#batched() batched} list. * @param elements An iterable of batched elements * @return {@code this} builder for use in a chained invocation */ public final Builder addAllBatched(Iterable elements) { for (R2InstanceBatchedType element : elements) { this.batched.add(Objects.requireNonNull(element, "batched element")); } return this; } /** * Builds a new {@link R2MaskInstances R2MaskInstances}. * @return An immutable instance of R2MaskInstances * @throws java.lang.IllegalStateException if any required attributes are missing */ public R2MaskInstances build() { return new R2MaskInstances(createUnmodifiableList(true, singles), createUnmodifiableList(true, batched)); } } private static List createSafeList(Iterable 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); } } } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy