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

com.io7m.changelog.core.CTicketSystem Maven / Gradle / Ivy

There is a newer version: 3.0.3
Show newest version
package com.io7m.changelog.core;

import java.net.URI;
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 definition of a ticket system.
 */
@SuppressWarnings({"all"})
@Generated({"Immutables.generator", "CTicketSystemType"})
public final class CTicketSystem implements CTicketSystemType {
  private final String id;
  private final List uris;

  private CTicketSystem(String id, Iterable uris) {
    this.id = Objects.requireNonNull(id, "id");
    this.uris = createUnmodifiableList(false, createSafeList(uris, true, false));
  }

  private CTicketSystem(CTicketSystem original, String id, List uris) {
    this.id = id;
    this.uris = uris;
  }

  /**
   * @return The ID of the ticket system
   */
  @Override
  public String id() {
    return id;
  }

  /**
   * @return The list of URIs for the ticket system
   */
  @Override
  public List uris() {
    return uris;
  }

  /**
   * Copy the current immutable object by setting a value for the {@link CTicketSystemType#id() id} attribute.
   * An equals check used to prevent copying of the same value by returning {@code this}.
   * @param value A new value for id
   * @return A modified copy of the {@code this} object
   */
  public final CTicketSystem withId(String value) {
    if (this.id.equals(value)) return this;
    String newValue = Objects.requireNonNull(value, "id");
    return new CTicketSystem(this, newValue, this.uris);
  }

  /**
   * Copy the current immutable object with elements that replace the content of {@link CTicketSystemType#uris() uris}.
   * @param elements The elements to set
   * @return A modified copy of {@code this} object
   */
  public final CTicketSystem withUris(URI... elements) {
    List newValue = createUnmodifiableList(false, createSafeList(Arrays.asList(elements), true, false));
    return new CTicketSystem(this, this.id, newValue);
  }

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

  /**
   * This instance is equal to all instances of {@code CTicketSystem} 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 CTicketSystem
        && equalTo((CTicketSystem) another);
  }

  private boolean equalTo(CTicketSystem another) {
    return id.equals(another.id)
        && uris.equals(another.uris);
  }

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

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

  /**
   * Construct a new immutable {@code CTicketSystem} instance.
   * @param id The value for the {@code id} attribute
   * @param uris The value for the {@code uris} attribute
   * @return An immutable CTicketSystem instance
   */
  public static CTicketSystem of(String id, List uris) {
    return of(id, (Iterable) uris);
  }

  /**
   * Construct a new immutable {@code CTicketSystem} instance.
   * @param id The value for the {@code id} attribute
   * @param uris The value for the {@code uris} attribute
   * @return An immutable CTicketSystem instance
   */
  public static CTicketSystem of(String id, Iterable uris) {
    return new CTicketSystem(id, uris);
  }

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

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

  /**
   * Builds instances of type {@link CTicketSystem CTicketSystem}.
   * 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 static final long INIT_BIT_ID = 0x1L; private long initBits = 0x1L; private String id; private List uris = new ArrayList(); private Builder() { } /** * Fill a builder with attribute values from the provided {@code CTicketSystemType} 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(CTicketSystemType instance) { Objects.requireNonNull(instance, "instance"); setId(instance.id()); addAllUris(instance.uris()); return this; } /** * Initializes the value for the {@link CTicketSystemType#id() id} attribute. * @param id The value for id * @return {@code this} builder for use in a chained invocation */ public final Builder setId(String id) { this.id = Objects.requireNonNull(id, "id"); initBits &= ~INIT_BIT_ID; return this; } /** * Adds one element to {@link CTicketSystemType#uris() uris} list. * @param element A uris element * @return {@code this} builder for use in a chained invocation */ public final Builder addUris(URI element) { this.uris.add(Objects.requireNonNull(element, "uris element")); return this; } /** * Adds elements to {@link CTicketSystemType#uris() uris} list. * @param elements An array of uris elements * @return {@code this} builder for use in a chained invocation */ public final Builder addUris(URI... elements) { for (URI element : elements) { this.uris.add(Objects.requireNonNull(element, "uris element")); } return this; } /** * Sets or replaces all elements for {@link CTicketSystemType#uris() uris} list. * @param elements An iterable of uris elements * @return {@code this} builder for use in a chained invocation */ public final Builder setUris(Iterable elements) { this.uris.clear(); return addAllUris(elements); } /** * Adds elements to {@link CTicketSystemType#uris() uris} list. * @param elements An iterable of uris elements * @return {@code this} builder for use in a chained invocation */ public final Builder addAllUris(Iterable elements) { for (URI element : elements) { this.uris.add(Objects.requireNonNull(element, "uris element")); } return this; } /** * Builds a new {@link CTicketSystem CTicketSystem}. * @return An immutable instance of CTicketSystem * @throws java.lang.IllegalStateException if any required attributes are missing */ public CTicketSystem build() { if (initBits != 0) { throw new IllegalStateException(formatRequiredAttributesMessage()); } return new CTicketSystem(null, id, createUnmodifiableList(true, uris)); } private String formatRequiredAttributesMessage() { List attributes = new ArrayList(); if ((initBits & INIT_BIT_ID) != 0) attributes.add("id"); return "Cannot build CTicketSystem, some of required attributes are not set " + attributes; } } 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 - 2025 Weber Informatics LLC | Privacy Policy