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

com.io7m.jwheatsheaf.api.JWFileListingFailed Maven / Gradle / Ivy

There is a newer version: 4.0.0
Show newest version
package com.io7m.jwheatsheaf.api;

import java.nio.file.Path;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

/**
 * An error occurred whilst trying to list a directory.
 */
@SuppressWarnings({"all"})
public final class JWFileListingFailed
    implements JWFileChooserEventType.JWFileListingFailedType {
  private final Path path;
  private final Exception exception;

  private JWFileListingFailed(Path path, Exception exception) {
    this.path = Objects.requireNonNull(path, "path");
    this.exception = Objects.requireNonNull(exception, "exception");
  }

  private JWFileListingFailed(JWFileListingFailed original, Path path, Exception exception) {
    this.path = path;
    this.exception = exception;
  }

  /**
   * @return The directory that could not be listed
   */
  @Override
  public Path path() {
    return path;
  }

  /**
   * @return The exception
   */
  @Override
  public Exception exception() {
    return exception;
  }

  /**
   * Copy the current immutable object by setting a value for the {@link JWFileChooserEventType.JWFileListingFailedType#path() path} 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 path
   * @return A modified copy of the {@code this} object
   */
  public final JWFileListingFailed withPath(Path value) {
    if (this.path == value) return this;
    Path newValue = Objects.requireNonNull(value, "path");
    return new JWFileListingFailed(this, newValue, this.exception);
  }

  /**
   * Copy the current immutable object by setting a value for the {@link JWFileChooserEventType.JWFileListingFailedType#exception() exception} 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 exception
   * @return A modified copy of the {@code this} object
   */
  public final JWFileListingFailed withException(Exception value) {
    if (this.exception == value) return this;
    Exception newValue = Objects.requireNonNull(value, "exception");
    return new JWFileListingFailed(this, this.path, newValue);
  }

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

  private boolean equalTo(JWFileListingFailed another) {
    return path.equals(another.path)
        && exception.equals(another.exception);
  }

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

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

  /**
   * Construct a new immutable {@code JWFileListingFailed} instance.
   * @param path The value for the {@code path} attribute
   * @param exception The value for the {@code exception} attribute
   * @return An immutable JWFileListingFailed instance
   */
  public static JWFileListingFailed of(Path path, Exception exception) {
    return new JWFileListingFailed(path, exception);
  }

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

  /**
   * Creates a builder for {@link JWFileListingFailed JWFileListingFailed}.
   * 
   * JWFileListingFailed.builder()
   *    .setPath(java.nio.file.Path) // required {@link JWFileChooserEventType.JWFileListingFailedType#path() path}
   *    .setException(Exception) // required {@link JWFileChooserEventType.JWFileListingFailedType#exception() exception}
   *    .build();
   * 
* @return A new JWFileListingFailed builder */ public static JWFileListingFailed.Builder builder() { return new JWFileListingFailed.Builder(); } /** * Builds instances of type {@link JWFileListingFailed JWFileListingFailed}. * 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_PATH = 0x1L; private static final long INIT_BIT_EXCEPTION = 0x2L; private long initBits = 0x3L; private Path path; private Exception exception; private Builder() { } /** * Fill a builder with attribute values from the provided {@code com.io7m.jwheatsheaf.api.JWFileChooserEventType.JWFileChooserEventErrorType} instance. * @param instance The instance from which to copy values * @return {@code this} builder for use in a chained invocation */ public final Builder from(JWFileChooserEventType.JWFileChooserEventErrorType instance) { Objects.requireNonNull(instance, "instance"); from((Object) instance); return this; } /** * Fill a builder with attribute values from the provided {@code com.io7m.jwheatsheaf.api.JWFileChooserEventType.JWFileListingFailedType} instance. * @param instance The instance from which to copy values * @return {@code this} builder for use in a chained invocation */ public final Builder from(JWFileChooserEventType.JWFileListingFailedType instance) { Objects.requireNonNull(instance, "instance"); from((Object) instance); return this; } private void from(Object object) { long bits = 0; if (object instanceof JWFileChooserEventType.JWFileChooserEventErrorType) { JWFileChooserEventType.JWFileChooserEventErrorType instance = (JWFileChooserEventType.JWFileChooserEventErrorType) object; if ((bits & 0x1L) == 0) { setException(instance.exception()); bits |= 0x1L; } if ((bits & 0x2L) == 0) { setPath(instance.path()); bits |= 0x2L; } } if (object instanceof JWFileChooserEventType.JWFileListingFailedType) { JWFileChooserEventType.JWFileListingFailedType instance = (JWFileChooserEventType.JWFileListingFailedType) object; if ((bits & 0x1L) == 0) { setException(instance.exception()); bits |= 0x1L; } if ((bits & 0x2L) == 0) { setPath(instance.path()); bits |= 0x2L; } } } /** * Initializes the value for the {@link JWFileChooserEventType.JWFileListingFailedType#path() path} attribute. * @param path The value for path * @return {@code this} builder for use in a chained invocation */ public final Builder setPath(Path path) { this.path = Objects.requireNonNull(path, "path"); initBits &= ~INIT_BIT_PATH; return this; } /** * Initializes the value for the {@link JWFileChooserEventType.JWFileListingFailedType#exception() exception} attribute. * @param exception The value for exception * @return {@code this} builder for use in a chained invocation */ public final Builder setException(Exception exception) { this.exception = Objects.requireNonNull(exception, "exception"); initBits &= ~INIT_BIT_EXCEPTION; return this; } /** * Builds a new {@link JWFileListingFailed JWFileListingFailed}. * @return An immutable instance of JWFileListingFailed * @throws java.lang.IllegalStateException if any required attributes are missing */ public JWFileListingFailed build() { if (initBits != 0) { throw new IllegalStateException(formatRequiredAttributesMessage()); } return new JWFileListingFailed(null, path, exception); } private String formatRequiredAttributesMessage() { List attributes = new ArrayList<>(); if ((initBits & INIT_BIT_PATH) != 0) attributes.add("path"); if ((initBits & INIT_BIT_EXCEPTION) != 0) attributes.add("exception"); return "Cannot build JWFileListingFailed, some of required attributes are not set " + attributes; } } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy