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

edu.isi.nlp.files.ImmutableFileUtils Maven / Gradle / Ivy

The newest version!
package edu.isi.nlp.files;

import com.google.common.base.MoreObjects;
import com.google.common.base.Optional;
import com.google.common.base.Preconditions;
import com.google.common.collect.Lists;
import com.google.common.primitives.Booleans;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
import javax.annotation.Generated;
import javax.annotation.Nullable;
import javax.annotation.ParametersAreNonnullByDefault;
import javax.annotation.concurrent.Immutable;
import javax.annotation.concurrent.NotThreadSafe;
import org.slf4j.Logger;

/**
 * {@code ImmutableFileUtils} contains immutable implementation classes generated from
 * abstract value types defined as nested inside {@link FileUtils}.
 * @see ImmutableFileUtils.BackupRequest
 */
@SuppressWarnings({"all"})
@ParametersAreNonnullByDefault
@Generated({"Immutables.generator", "FileUtils"})
public final class ImmutableFileUtils {
  private ImmutableFileUtils() {}

  /**
   * Immutable implementation of {@link FileUtils.BackupRequest}.
   * 

* Use the builder to create immutable instances: * {@code new FileUtils.BackupRequest.Builder()}. */ @Immutable public static final class BackupRequest extends FileUtils.BackupRequest { private final File fileToBackup; private final Optional nameOfThingToBackup; private final Logger logger; private final String extension; private final boolean deleteOriginal; private BackupRequest(ImmutableFileUtils.BackupRequest.Builder builder) { this.fileToBackup = builder.fileToBackup; this.nameOfThingToBackup = builder.nameOfThingToBackup; if (builder.logger != null) { initShim.logger(builder.logger); } if (builder.extension != null) { initShim.extension(builder.extension); } if (builder.deleteOriginalIsSet()) { initShim.deleteOriginal(builder.deleteOriginal); } this.logger = initShim.logger(); this.extension = initShim.extension(); this.deleteOriginal = initShim.deleteOriginal(); this.initShim = null; } private BackupRequest( File fileToBackup, Optional nameOfThingToBackup, Logger logger, String extension, boolean deleteOriginal) { this.fileToBackup = fileToBackup; this.nameOfThingToBackup = nameOfThingToBackup; this.logger = logger; this.extension = extension; this.deleteOriginal = deleteOriginal; this.initShim = null; } private static final int STAGE_INITIALIZING = -1; private static final int STAGE_UNINITIALIZED = 0; private static final int STAGE_INITIALIZED = 1; private transient volatile InitShim initShim = new InitShim(); private final class InitShim { private Logger logger; private int loggerStage; Logger logger() { if (loggerStage == STAGE_INITIALIZING) throw new IllegalStateException(formatInitCycleMessage()); if (loggerStage == STAGE_UNINITIALIZED) { loggerStage = STAGE_INITIALIZING; this.logger = Preconditions.checkNotNull(BackupRequest.super.logger(), "logger"); loggerStage = STAGE_INITIALIZED; } return this.logger; } void logger(Logger logger) { this.logger = logger; loggerStage = STAGE_INITIALIZED; } private String extension; private int extensionStage; String extension() { if (extensionStage == STAGE_INITIALIZING) throw new IllegalStateException(formatInitCycleMessage()); if (extensionStage == STAGE_UNINITIALIZED) { extensionStage = STAGE_INITIALIZING; this.extension = Preconditions.checkNotNull(BackupRequest.super.extension(), "extension"); extensionStage = STAGE_INITIALIZED; } return this.extension; } void extension(String extension) { this.extension = extension; extensionStage = STAGE_INITIALIZED; } private boolean deleteOriginal; private int deleteOriginalStage; boolean deleteOriginal() { if (deleteOriginalStage == STAGE_INITIALIZING) throw new IllegalStateException(formatInitCycleMessage()); if (deleteOriginalStage == STAGE_UNINITIALIZED) { deleteOriginalStage = STAGE_INITIALIZING; this.deleteOriginal = BackupRequest.super.deleteOriginal(); deleteOriginalStage = STAGE_INITIALIZED; } return this.deleteOriginal; } void deleteOriginal(boolean deleteOriginal) { this.deleteOriginal = deleteOriginal; deleteOriginalStage = STAGE_INITIALIZED; } private String formatInitCycleMessage() { ArrayList attributes = Lists.newArrayList(); if (loggerStage == STAGE_INITIALIZING) attributes.add("logger"); if (extensionStage == STAGE_INITIALIZING) attributes.add("extension"); if (deleteOriginalStage == STAGE_INITIALIZING) attributes.add("deleteOriginal"); return "Cannot build BackupRequest, attribute initializers form cycle" + attributes; } } /** * @return The value of the {@code fileToBackup} attribute */ @Override public File fileToBackup() { return fileToBackup; } /** * The name of the type of object being backed up (e.g. "geonames database"). If this is * provided, a message is logged. */ @Override public Optional nameOfThingToBackup() { return nameOfThingToBackup; } /** * The logger to write a log message to. If not specified, defaults to the logger of {@link * FileUtils} */ @Override public Logger logger() { InitShim shim = this.initShim; return shim != null ? shim.logger() : this.logger; } /** * The extension to append to the backup file. A "." is automatically inserted. Defaults to * "bak" */ @Override public String extension() { InitShim shim = this.initShim; return shim != null ? shim.extension() : this.extension; } /** *Whether to delete the file being backed up. */ @Override public boolean deleteOriginal() { InitShim shim = this.initShim; return shim != null ? shim.deleteOriginal() : this.deleteOriginal; } /** * Copy the current immutable object by setting a value for the {@link FileUtils.BackupRequest#fileToBackup() fileToBackup} 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 fileToBackup * @return A modified copy of the {@code this} object */ public final ImmutableFileUtils.BackupRequest withFileToBackup(File value) { if (this.fileToBackup == value) return this; File newValue = Preconditions.checkNotNull(value, "fileToBackup"); return validate(new ImmutableFileUtils.BackupRequest(newValue, this.nameOfThingToBackup, this.logger, this.extension, this.deleteOriginal)); } /** * Copy the current immutable object by setting a present value for the optional {@link FileUtils.BackupRequest#nameOfThingToBackup() nameOfThingToBackup} attribute. * @param value The value for nameOfThingToBackup * @return A modified copy of {@code this} object */ public final ImmutableFileUtils.BackupRequest withNameOfThingToBackup(String value) { Optional newValue = Optional.of(value); if (this.nameOfThingToBackup.equals(newValue)) return this; return validate(new ImmutableFileUtils.BackupRequest(this.fileToBackup, newValue, this.logger, this.extension, this.deleteOriginal)); } /** * Copy the current immutable object by setting an optional value for the {@link FileUtils.BackupRequest#nameOfThingToBackup() nameOfThingToBackup} attribute. * An equality check is used to prevent copying of the same value by returning {@code this}. * @param optional A value for nameOfThingToBackup * @return A modified copy of {@code this} object */ public final ImmutableFileUtils.BackupRequest withNameOfThingToBackup(Optional optional) { Optional value = Preconditions.checkNotNull(optional, "nameOfThingToBackup"); if (this.nameOfThingToBackup.equals(value)) return this; return validate(new ImmutableFileUtils.BackupRequest(this.fileToBackup, value, this.logger, this.extension, this.deleteOriginal)); } /** * Copy the current immutable object by setting a value for the {@link FileUtils.BackupRequest#logger() logger} 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 logger * @return A modified copy of the {@code this} object */ public final ImmutableFileUtils.BackupRequest withLogger(Logger value) { if (this.logger == value) return this; Logger newValue = Preconditions.checkNotNull(value, "logger"); return validate(new ImmutableFileUtils.BackupRequest(this.fileToBackup, this.nameOfThingToBackup, newValue, this.extension, this.deleteOriginal)); } /** * Copy the current immutable object by setting a value for the {@link FileUtils.BackupRequest#extension() extension} attribute. * An equals check used to prevent copying of the same value by returning {@code this}. * @param value A new value for extension * @return A modified copy of the {@code this} object */ public final ImmutableFileUtils.BackupRequest withExtension(String value) { if (this.extension.equals(value)) return this; String newValue = Preconditions.checkNotNull(value, "extension"); return validate(new ImmutableFileUtils.BackupRequest(this.fileToBackup, this.nameOfThingToBackup, this.logger, newValue, this.deleteOriginal)); } /** * Copy the current immutable object by setting a value for the {@link FileUtils.BackupRequest#deleteOriginal() deleteOriginal} attribute. * A value equality check is used to prevent copying of the same value by returning {@code this}. * @param value A new value for deleteOriginal * @return A modified copy of the {@code this} object */ public final ImmutableFileUtils.BackupRequest withDeleteOriginal(boolean value) { if (this.deleteOriginal == value) return this; return validate(new ImmutableFileUtils.BackupRequest(this.fileToBackup, this.nameOfThingToBackup, this.logger, this.extension, value)); } /** * This instance is equal to all instances of {@code BackupRequest} that have equal attribute values. * @return {@code true} if {@code this} is equal to {@code another} instance */ @Override public boolean equals(@Nullable Object another) { if (this == another) return true; return another instanceof ImmutableFileUtils.BackupRequest && equalTo((ImmutableFileUtils.BackupRequest) another); } private boolean equalTo(ImmutableFileUtils.BackupRequest another) { return fileToBackup.equals(another.fileToBackup) && nameOfThingToBackup.equals(another.nameOfThingToBackup) && logger.equals(another.logger) && extension.equals(another.extension) && deleteOriginal == another.deleteOriginal; } /** * Computes a hash code from attributes: {@code fileToBackup}, {@code nameOfThingToBackup}, {@code logger}, {@code extension}, {@code deleteOriginal}. * @return hashCode value */ @Override public int hashCode() { int h = 31; h = h * 17 + fileToBackup.hashCode(); h = h * 17 + nameOfThingToBackup.hashCode(); h = h * 17 + logger.hashCode(); h = h * 17 + extension.hashCode(); h = h * 17 + Booleans.hashCode(deleteOriginal); return h; } /** * Prints the immutable value {@code BackupRequest} with attribute values. * @return A string representation of the value */ @Override public String toString() { return MoreObjects.toStringHelper("BackupRequest") .omitNullValues() .add("fileToBackup", fileToBackup) .add("nameOfThingToBackup", nameOfThingToBackup.orNull()) .add("logger", logger) .add("extension", extension) .add("deleteOriginal", deleteOriginal) .toString(); } private static BackupRequest validate(ImmutableFileUtils.BackupRequest instance) { instance.check(); return instance; } /** * Creates an immutable copy of a {@link FileUtils.BackupRequest} 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 BackupRequest instance */ public static ImmutableFileUtils.BackupRequest copyOf(FileUtils.BackupRequest instance) { if (instance instanceof ImmutableFileUtils.BackupRequest) { return (ImmutableFileUtils.BackupRequest) instance; } return new FileUtils.BackupRequest.Builder() .from(instance) .build(); } /** * Builds instances of type {@link ImmutableFileUtils.BackupRequest BackupRequest}. * 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. */ @NotThreadSafe public static class Builder { private static final long INIT_BIT_FILE_TO_BACKUP = 0x1L; private static final long OPT_BIT_DELETE_ORIGINAL = 0x1L; private long initBits = 0x1L; private long optBits; private @Nullable File fileToBackup; private Optional nameOfThingToBackup = Optional.absent(); private @Nullable Logger logger; private @Nullable String extension; private boolean deleteOriginal; /** * Creates a builder for {@link ImmutableFileUtils.BackupRequest BackupRequest} instances. */ public Builder() { if (!(this instanceof FileUtils.BackupRequest.Builder)) { throw new UnsupportedOperationException("Use: new FileUtils.BackupRequest.Builder()"); } } /** * Fill a builder with attribute values from the provided {@code BackupRequest} 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 FileUtils.BackupRequest.Builder from(FileUtils.BackupRequest instance) { Preconditions.checkNotNull(instance, "instance"); fileToBackup(instance.fileToBackup()); Optional nameOfThingToBackupOptional = instance.nameOfThingToBackup(); if (nameOfThingToBackupOptional.isPresent()) { nameOfThingToBackup(nameOfThingToBackupOptional); } logger(instance.logger()); extension(instance.extension()); deleteOriginal(instance.deleteOriginal()); return (FileUtils.BackupRequest.Builder) this; } /** * Initializes the value for the {@link FileUtils.BackupRequest#fileToBackup() fileToBackup} attribute. * @param fileToBackup The value for fileToBackup * @return {@code this} builder for use in a chained invocation */ public final FileUtils.BackupRequest.Builder fileToBackup(File fileToBackup) { this.fileToBackup = Preconditions.checkNotNull(fileToBackup, "fileToBackup"); initBits &= ~INIT_BIT_FILE_TO_BACKUP; return (FileUtils.BackupRequest.Builder) this; } /** * Initializes the optional value {@link FileUtils.BackupRequest#nameOfThingToBackup() nameOfThingToBackup} to nameOfThingToBackup. * @param nameOfThingToBackup The value for nameOfThingToBackup * @return {@code this} builder for chained invocation */ public final FileUtils.BackupRequest.Builder nameOfThingToBackup(String nameOfThingToBackup) { this.nameOfThingToBackup = Optional.of(nameOfThingToBackup); return (FileUtils.BackupRequest.Builder) this; } /** * Initializes the optional value {@link FileUtils.BackupRequest#nameOfThingToBackup() nameOfThingToBackup} to nameOfThingToBackup. * @param nameOfThingToBackup The value for nameOfThingToBackup * @return {@code this} builder for use in a chained invocation */ public final FileUtils.BackupRequest.Builder nameOfThingToBackup(Optional nameOfThingToBackup) { this.nameOfThingToBackup = Preconditions.checkNotNull(nameOfThingToBackup, "nameOfThingToBackup"); return (FileUtils.BackupRequest.Builder) this; } /** * Initializes the value for the {@link FileUtils.BackupRequest#logger() logger} attribute. *

If not set, this attribute will have a default value as returned by the initializer of {@link FileUtils.BackupRequest#logger() logger}. * @param logger The value for logger * @return {@code this} builder for use in a chained invocation */ public final FileUtils.BackupRequest.Builder logger(Logger logger) { this.logger = Preconditions.checkNotNull(logger, "logger"); return (FileUtils.BackupRequest.Builder) this; } /** * Initializes the value for the {@link FileUtils.BackupRequest#extension() extension} attribute. *

If not set, this attribute will have a default value as returned by the initializer of {@link FileUtils.BackupRequest#extension() extension}. * @param extension The value for extension * @return {@code this} builder for use in a chained invocation */ public final FileUtils.BackupRequest.Builder extension(String extension) { this.extension = Preconditions.checkNotNull(extension, "extension"); return (FileUtils.BackupRequest.Builder) this; } /** * Initializes the value for the {@link FileUtils.BackupRequest#deleteOriginal() deleteOriginal} attribute. *

If not set, this attribute will have a default value as returned by the initializer of {@link FileUtils.BackupRequest#deleteOriginal() deleteOriginal}. * @param deleteOriginal The value for deleteOriginal * @return {@code this} builder for use in a chained invocation */ public final FileUtils.BackupRequest.Builder deleteOriginal(boolean deleteOriginal) { this.deleteOriginal = deleteOriginal; optBits |= OPT_BIT_DELETE_ORIGINAL; return (FileUtils.BackupRequest.Builder) this; } /** * Builds a new {@link ImmutableFileUtils.BackupRequest BackupRequest}. * @return An immutable instance of BackupRequest * @throws java.lang.IllegalStateException if any required attributes are missing */ public ImmutableFileUtils.BackupRequest build() { if (initBits != 0) { throw new IllegalStateException(formatRequiredAttributesMessage()); } return ImmutableFileUtils.BackupRequest.validate(new ImmutableFileUtils.BackupRequest(this)); } private boolean deleteOriginalIsSet() { return (optBits & OPT_BIT_DELETE_ORIGINAL) != 0; } private String formatRequiredAttributesMessage() { List attributes = Lists.newArrayList(); if ((initBits & INIT_BIT_FILE_TO_BACKUP) != 0) attributes.add("fileToBackup"); return "Cannot build BackupRequest, some of required attributes are not set " + attributes; } } } }





© 2015 - 2025 Weber Informatics LLC | Privacy Policy