com.io7m.jwheatsheaf.api.JWDirectoryCreationFailed Maven / Gradle / Ivy
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 create a directory.
*/
@SuppressWarnings({"all"})
public final class JWDirectoryCreationFailed
implements JWFileChooserEventType.JWDirectoryCreationFailedType {
private final Path path;
private final Exception exception;
private JWDirectoryCreationFailed(Path path, Exception exception) {
this.path = Objects.requireNonNull(path, "path");
this.exception = Objects.requireNonNull(exception, "exception");
}
private JWDirectoryCreationFailed(JWDirectoryCreationFailed original, Path path, Exception exception) {
this.path = path;
this.exception = exception;
}
/**
* @return The directory that could not be created
*/
@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.JWDirectoryCreationFailedType#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 JWDirectoryCreationFailed withPath(Path value) {
if (this.path == value) return this;
Path newValue = Objects.requireNonNull(value, "path");
return new JWDirectoryCreationFailed(this, newValue, this.exception);
}
/**
* Copy the current immutable object by setting a value for the {@link JWFileChooserEventType.JWDirectoryCreationFailedType#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 JWDirectoryCreationFailed withException(Exception value) {
if (this.exception == value) return this;
Exception newValue = Objects.requireNonNull(value, "exception");
return new JWDirectoryCreationFailed(this, this.path, newValue);
}
/**
* This instance is equal to all instances of {@code JWDirectoryCreationFailed} 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 JWDirectoryCreationFailed
&& equalTo((JWDirectoryCreationFailed) another);
}
private boolean equalTo(JWDirectoryCreationFailed 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 JWDirectoryCreationFailed} with attribute values.
* @return A string representation of the value
*/
@Override
public String toString() {
return "JWDirectoryCreationFailed{"
+ "path=" + path
+ ", exception=" + exception
+ "}";
}
/**
* Construct a new immutable {@code JWDirectoryCreationFailed} instance.
* @param path The value for the {@code path} attribute
* @param exception The value for the {@code exception} attribute
* @return An immutable JWDirectoryCreationFailed instance
*/
public static JWDirectoryCreationFailed of(Path path, Exception exception) {
return new JWDirectoryCreationFailed(path, exception);
}
/**
* Creates an immutable copy of a {@link JWFileChooserEventType.JWDirectoryCreationFailedType} 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 JWDirectoryCreationFailed instance
*/
public static JWDirectoryCreationFailed copyOf(JWFileChooserEventType.JWDirectoryCreationFailedType instance) {
if (instance instanceof JWDirectoryCreationFailed) {
return (JWDirectoryCreationFailed) instance;
}
return JWDirectoryCreationFailed.builder()
.from(instance)
.build();
}
/**
* Creates a builder for {@link JWDirectoryCreationFailed JWDirectoryCreationFailed}.
*
* JWDirectoryCreationFailed.builder()
* .setPath(java.nio.file.Path) // required {@link JWFileChooserEventType.JWDirectoryCreationFailedType#path() path}
* .setException(Exception) // required {@link JWFileChooserEventType.JWDirectoryCreationFailedType#exception() exception}
* .build();
*
* @return A new JWDirectoryCreationFailed builder
*/
public static JWDirectoryCreationFailed.Builder builder() {
return new JWDirectoryCreationFailed.Builder();
}
/**
* Builds instances of type {@link JWDirectoryCreationFailed JWDirectoryCreationFailed}.
* 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.JWDirectoryCreationFailedType} 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.JWDirectoryCreationFailedType 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.JWDirectoryCreationFailedType) {
JWFileChooserEventType.JWDirectoryCreationFailedType instance = (JWFileChooserEventType.JWDirectoryCreationFailedType) 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.JWDirectoryCreationFailedType#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.JWDirectoryCreationFailedType#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 JWDirectoryCreationFailed JWDirectoryCreationFailed}.
* @return An immutable instance of JWDirectoryCreationFailed
* @throws java.lang.IllegalStateException if any required attributes are missing
*/
public JWDirectoryCreationFailed build() {
if (initBits != 0) {
throw new IllegalStateException(formatRequiredAttributesMessage());
}
return new JWDirectoryCreationFailed(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 JWDirectoryCreationFailed, some of required attributes are not set " + attributes;
}
}
}