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

edu.isi.nlp.files.ImmutableStuffToSubtract 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.ImmutableMap;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Lists;
import edu.isi.nlp.symbols.Symbol;
import java.io.File;
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;

/**
 * Immutable implementation of {@link StuffToSubtract}.
 * 

* Use the builder to create immutable instances: * {@code new StuffToSubtract.Builder()}. */ @SuppressWarnings({"all"}) @ParametersAreNonnullByDefault @Generated({"Immutables.generator", "StuffToSubtract"}) @Immutable final class ImmutableStuffToSubtract extends StuffToSubtract { private final File path; private final ImmutableSet docIDs; private final Optional> docIDsToFileMap; private ImmutableStuffToSubtract( File path, ImmutableSet docIDs, Optional> docIDsToFileMap) { this.path = path; this.docIDs = docIDs; this.docIDsToFileMap = docIDsToFileMap; } /** * @return The value of the {@code path} attribute */ @Override public File path() { return path; } /** * @return The value of the {@code docIDs} attribute */ @Override public ImmutableSet docIDs() { return docIDs; } /** * @return The value of the {@code docIDsToFileMap} attribute */ @Override public Optional> docIDsToFileMap() { return docIDsToFileMap; } /** * Copy the current immutable object by setting a value for the {@link StuffToSubtract#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 ImmutableStuffToSubtract withPath(File value) { if (this.path == value) return this; File newValue = Preconditions.checkNotNull(value, "path"); return new ImmutableStuffToSubtract(newValue, this.docIDs, this.docIDsToFileMap); } /** * Copy the current immutable object with elements that replace the content of {@link StuffToSubtract#docIDs() docIDs}. * @param elements The elements to set * @return A modified copy of {@code this} object */ public final ImmutableStuffToSubtract withDocIDs(Symbol... elements) { ImmutableSet newValue = ImmutableSet.copyOf(elements); return new ImmutableStuffToSubtract(this.path, newValue, this.docIDsToFileMap); } /** * Copy the current immutable object with elements that replace the content of {@link StuffToSubtract#docIDs() docIDs}. * A shallow reference equality check is used to prevent copying of the same value by returning {@code this}. * @param elements An iterable of docIDs elements to set * @return A modified copy of {@code this} object */ public final ImmutableStuffToSubtract withDocIDs(Iterable elements) { if (this.docIDs == elements) return this; ImmutableSet newValue = ImmutableSet.copyOf(elements); return new ImmutableStuffToSubtract(this.path, newValue, this.docIDsToFileMap); } /** * Copy the current immutable object by setting a present value for the optional {@link StuffToSubtract#docIDsToFileMap() docIDsToFileMap} attribute. * @param value The value for docIDsToFileMap * @return A modified copy of {@code this} object */ public final ImmutableStuffToSubtract withDocIDsToFileMap(ImmutableMap value) { Optional> newValue = Optional.of(value); if (this.docIDsToFileMap.isPresent() && this.docIDsToFileMap.get() == value) return this; return new ImmutableStuffToSubtract(this.path, this.docIDs, newValue); } /** * Copy the current immutable object by setting an optional value for the {@link StuffToSubtract#docIDsToFileMap() docIDsToFileMap} attribute. * A shallow reference equality check on the optional value is used to prevent copying of the same value by returning {@code this}. * @param optional A value for docIDsToFileMap * @return A modified copy of {@code this} object */ public final ImmutableStuffToSubtract withDocIDsToFileMap(Optional> optional) { Optional> value = Preconditions.checkNotNull(optional, "docIDsToFileMap"); if (!this.docIDsToFileMap.isPresent() && !value.isPresent()) return this; if (this.docIDsToFileMap.isPresent() && value.isPresent() && this.docIDsToFileMap.get() == value.get()) return this; return new ImmutableStuffToSubtract(this.path, this.docIDs, value); } /** * This instance is equal to all instances of {@code ImmutableStuffToSubtract} 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 ImmutableStuffToSubtract && equalTo((ImmutableStuffToSubtract) another); } private boolean equalTo(ImmutableStuffToSubtract another) { return path.equals(another.path) && docIDs.equals(another.docIDs) && docIDsToFileMap.equals(another.docIDsToFileMap); } /** * Computes a hash code from attributes: {@code path}, {@code docIDs}, {@code docIDsToFileMap}. * @return hashCode value */ @Override public int hashCode() { int h = 31; h = h * 17 + path.hashCode(); h = h * 17 + docIDs.hashCode(); h = h * 17 + docIDsToFileMap.hashCode(); return h; } /** * Prints the immutable value {@code StuffToSubtract} with attribute values. * @return A string representation of the value */ @Override public String toString() { return MoreObjects.toStringHelper("StuffToSubtract") .omitNullValues() .add("path", path) .add("docIDs", docIDs) .add("docIDsToFileMap", docIDsToFileMap.orNull()) .toString(); } /** * Creates an immutable copy of a {@link StuffToSubtract} 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 StuffToSubtract instance */ public static StuffToSubtract copyOf(StuffToSubtract instance) { if (instance instanceof ImmutableStuffToSubtract) { return (ImmutableStuffToSubtract) instance; } return new StuffToSubtract.Builder() .from(instance) .build(); } /** * Builds instances of type {@link StuffToSubtract StuffToSubtract}. * 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 static class Builder { private static final long INIT_BIT_PATH = 0x1L; private long initBits = 0x1L; private @Nullable File path; private ImmutableSet.Builder docIDs = ImmutableSet.builder(); private Optional> docIDsToFileMap = Optional.absent(); /** * Creates a builder for {@link StuffToSubtract StuffToSubtract} instances. */ Builder() { if (!(this instanceof StuffToSubtract.Builder)) { throw new UnsupportedOperationException("Use: new StuffToSubtract.Builder()"); } } /** * Fill a builder with attribute values from the provided {@code StuffToSubtract} 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 StuffToSubtract.Builder from(StuffToSubtract instance) { Preconditions.checkNotNull(instance, "instance"); path(instance.path()); addAllDocIDs(instance.docIDs()); Optional> docIDsToFileMapOptional = instance.docIDsToFileMap(); if (docIDsToFileMapOptional.isPresent()) { docIDsToFileMap(docIDsToFileMapOptional); } return (StuffToSubtract.Builder) this; } /** * Initializes the value for the {@link StuffToSubtract#path() path} attribute. * @param path The value for path * @return {@code this} builder for use in a chained invocation */ public final StuffToSubtract.Builder path(File path) { this.path = Preconditions.checkNotNull(path, "path"); initBits &= ~INIT_BIT_PATH; return (StuffToSubtract.Builder) this; } /** * Adds one element to {@link StuffToSubtract#docIDs() docIDs} set. * @param element A docIDs element * @return {@code this} builder for use in a chained invocation */ public final StuffToSubtract.Builder addDocIDs(Symbol element) { this.docIDs.add(element); return (StuffToSubtract.Builder) this; } /** * Adds elements to {@link StuffToSubtract#docIDs() docIDs} set. * @param elements An array of docIDs elements * @return {@code this} builder for use in a chained invocation */ public final StuffToSubtract.Builder addDocIDs(Symbol... elements) { this.docIDs.add(elements); return (StuffToSubtract.Builder) this; } /** * Sets or replaces all elements for {@link StuffToSubtract#docIDs() docIDs} set. * @param elements An iterable of docIDs elements * @return {@code this} builder for use in a chained invocation */ public final StuffToSubtract.Builder docIDs(Iterable elements) { this.docIDs = ImmutableSet.builder(); return addAllDocIDs(elements); } /** * Adds elements to {@link StuffToSubtract#docIDs() docIDs} set. * @param elements An iterable of docIDs elements * @return {@code this} builder for use in a chained invocation */ public final StuffToSubtract.Builder addAllDocIDs(Iterable elements) { this.docIDs.addAll(elements); return (StuffToSubtract.Builder) this; } /** * Initializes the optional value {@link StuffToSubtract#docIDsToFileMap() docIDsToFileMap} to docIDsToFileMap. * @param docIDsToFileMap The value for docIDsToFileMap * @return {@code this} builder for chained invocation */ public final StuffToSubtract.Builder docIDsToFileMap(ImmutableMap docIDsToFileMap) { this.docIDsToFileMap = Optional.of(docIDsToFileMap); return (StuffToSubtract.Builder) this; } /** * Initializes the optional value {@link StuffToSubtract#docIDsToFileMap() docIDsToFileMap} to docIDsToFileMap. * @param docIDsToFileMap The value for docIDsToFileMap * @return {@code this} builder for use in a chained invocation */ public final StuffToSubtract.Builder docIDsToFileMap(Optional> docIDsToFileMap) { this.docIDsToFileMap = Preconditions.checkNotNull(docIDsToFileMap, "docIDsToFileMap"); return (StuffToSubtract.Builder) this; } /** * Builds a new {@link StuffToSubtract StuffToSubtract}. * @return An immutable instance of StuffToSubtract * @throws java.lang.IllegalStateException if any required attributes are missing */ public StuffToSubtract build() { if (initBits != 0) { throw new IllegalStateException(formatRequiredAttributesMessage()); } return new ImmutableStuffToSubtract(path, docIDs.build(), docIDsToFileMap); } private String formatRequiredAttributesMessage() { List attributes = Lists.newArrayList(); if ((initBits & INIT_BIT_PATH) != 0) attributes.add("path"); return "Cannot build StuffToSubtract, some of required attributes are not set " + attributes; } } }





© 2015 - 2025 Weber Informatics LLC | Privacy Policy