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

com.io7m.minisite.core.MinBugTrackerConfiguration Maven / Gradle / Ivy

package com.io7m.minisite.core;

import java.net.URI;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

/**
 * Configurations for bug trackers.
 */
@SuppressWarnings({"all"})
public final class MinBugTrackerConfiguration implements MinBugTrackerConfigurationType {
  private final String system;
  private final URI uri;

  private MinBugTrackerConfiguration(String system, URI uri) {
    this.system = Objects.requireNonNull(system, "system");
    this.uri = Objects.requireNonNull(uri, "uri");
  }

  private MinBugTrackerConfiguration(MinBugTrackerConfiguration original, String system, URI uri) {
    this.system = system;
    this.uri = uri;
  }

  /**
   * @return The type of bug tracker
   */
  @Override
  public String system() {
    return system;
  }

  /**
   * @return The bug tracker URL
   */
  @Override
  public URI uri() {
    return uri;
  }

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

  /**
   * Copy the current immutable object by setting a value for the {@link MinBugTrackerConfigurationType#uri() uri} attribute.
   * A shallow reference equality check is used to prevent copying of the same value by returning {@code this}.
   * @param value A new value for uri
   * @return A modified copy of the {@code this} object
   */
  public final MinBugTrackerConfiguration withUri(URI value) {
    if (this.uri == value) return this;
    URI newValue = Objects.requireNonNull(value, "uri");
    return new MinBugTrackerConfiguration(this, this.system, newValue);
  }

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

  private boolean equalTo(int synthetic, MinBugTrackerConfiguration another) {
    return system.equals(another.system)
        && uri.equals(another.uri);
  }

  /**
   * Computes a hash code from attributes: {@code system}, {@code uri}.
   * @return hashCode value
   */
  @Override
  public int hashCode() {
    int h = 5381;
    h += (h << 5) + system.hashCode();
    h += (h << 5) + uri.hashCode();
    return h;
  }

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

  /**
   * Construct a new immutable {@code MinBugTrackerConfiguration} instance.
   * @param system The value for the {@code system} attribute
   * @param uri The value for the {@code uri} attribute
   * @return An immutable MinBugTrackerConfiguration instance
   */
  public static MinBugTrackerConfiguration of(String system, URI uri) {
    return new MinBugTrackerConfiguration(system, uri);
  }

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

  /**
   * Creates a builder for {@link MinBugTrackerConfiguration MinBugTrackerConfiguration}.
   * 
   * MinBugTrackerConfiguration.builder()
   *    .setSystem(String) // required {@link MinBugTrackerConfigurationType#system() system}
   *    .setUri(java.net.URI) // required {@link MinBugTrackerConfigurationType#uri() uri}
   *    .build();
   * 
* @return A new MinBugTrackerConfiguration builder */ public static MinBugTrackerConfiguration.Builder builder() { return new MinBugTrackerConfiguration.Builder(); } /** * Builds instances of type {@link MinBugTrackerConfiguration MinBugTrackerConfiguration}. * 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_SYSTEM = 0x1L; private static final long INIT_BIT_URI = 0x2L; private long initBits = 0x3L; private String system; private URI uri; private Builder() { } /** * Fill a builder with attribute values from the provided {@code MinBugTrackerConfigurationType} instance. * Regular attribute values will be replaced with those from the given instance. * Absent optional values will not replace present values. * @param instance The instance from which to copy values * @return {@code this} builder for use in a chained invocation */ public final Builder from(MinBugTrackerConfigurationType instance) { Objects.requireNonNull(instance, "instance"); this.setSystem(instance.system()); this.setUri(instance.uri()); return this; } /** * Initializes the value for the {@link MinBugTrackerConfigurationType#system() system} attribute. * @param system The value for system * @return {@code this} builder for use in a chained invocation */ public final Builder setSystem(String system) { this.system = Objects.requireNonNull(system, "system"); initBits &= ~INIT_BIT_SYSTEM; return this; } /** * Initializes the value for the {@link MinBugTrackerConfigurationType#uri() uri} attribute. * @param uri The value for uri * @return {@code this} builder for use in a chained invocation */ public final Builder setUri(URI uri) { this.uri = Objects.requireNonNull(uri, "uri"); initBits &= ~INIT_BIT_URI; return this; } /** * Builds a new {@link MinBugTrackerConfiguration MinBugTrackerConfiguration}. * @return An immutable instance of MinBugTrackerConfiguration * @throws java.lang.IllegalStateException if any required attributes are missing */ public MinBugTrackerConfiguration build() { if (initBits != 0) { throw new IllegalStateException(formatRequiredAttributesMessage()); } return new MinBugTrackerConfiguration(null, system, uri); } private String formatRequiredAttributesMessage() { List attributes = new ArrayList<>(); if ((initBits & INIT_BIT_SYSTEM) != 0) attributes.add("system"); if ((initBits & INIT_BIT_URI) != 0) attributes.add("uri"); return "Cannot build MinBugTrackerConfiguration, some of required attributes are not set " + attributes; } } }





© 2015 - 2025 Weber Informatics LLC | Privacy Policy