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

edu.isi.nlp.strings.offsets.ImmutableOffsetGroup Maven / Gradle / Ivy

The newest version!
package edu.isi.nlp.strings.offsets;

import com.google.common.base.Optional;
import com.google.common.base.Preconditions;
import com.google.common.collect.Lists;
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 OffsetGroup}.
 * 

* Use the builder to create immutable instances: * {@code new OffsetGroup.Builder()}. */ @SuppressWarnings({"all"}) @ParametersAreNonnullByDefault @Generated({"Immutables.generator", "OffsetGroup"}) @Immutable final class ImmutableOffsetGroup extends OffsetGroup { private final Optional byteOffset; private final CharOffset charOffset; private final EDTOffset edtOffset; private final Optional asrTime; private ImmutableOffsetGroup( Optional byteOffset, CharOffset charOffset, EDTOffset edtOffset, Optional asrTime) { this.byteOffset = byteOffset; this.charOffset = charOffset; this.edtOffset = edtOffset; this.asrTime = asrTime; } /** * @return The value of the {@code byteOffset} attribute */ @Override public Optional byteOffset() { return byteOffset; } /** * @return The value of the {@code charOffset} attribute */ @Override public CharOffset charOffset() { return charOffset; } /** * @return The value of the {@code edtOffset} attribute */ @Override public EDTOffset edtOffset() { return edtOffset; } /** * @return The value of the {@code asrTime} attribute */ @Override public Optional asrTime() { return asrTime; } /** * Copy the current immutable object by setting a present value for the optional {@link OffsetGroup#byteOffset() byteOffset} attribute. * @param value The value for byteOffset * @return A modified copy of {@code this} object */ public final ImmutableOffsetGroup withByteOffset(ByteOffset value) { Optional newValue = Optional.of(value); if (this.byteOffset.isPresent() && this.byteOffset.get() == value) return this; return new ImmutableOffsetGroup(newValue, this.charOffset, this.edtOffset, this.asrTime); } /** * Copy the current immutable object by setting an optional value for the {@link OffsetGroup#byteOffset() byteOffset} 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 byteOffset * @return A modified copy of {@code this} object */ public final ImmutableOffsetGroup withByteOffset(Optional optional) { Optional value = Preconditions.checkNotNull(optional, "byteOffset"); if (!this.byteOffset.isPresent() && !value.isPresent()) return this; if (this.byteOffset.isPresent() && value.isPresent() && this.byteOffset.get() == value.get()) return this; return new ImmutableOffsetGroup(value, this.charOffset, this.edtOffset, this.asrTime); } /** * Copy the current immutable object by setting a value for the {@link OffsetGroup#charOffset() charOffset} 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 charOffset * @return A modified copy of the {@code this} object */ public final ImmutableOffsetGroup withCharOffset(CharOffset value) { if (this.charOffset == value) return this; CharOffset newValue = Preconditions.checkNotNull(value, "charOffset"); return new ImmutableOffsetGroup(this.byteOffset, newValue, this.edtOffset, this.asrTime); } /** * Copy the current immutable object by setting a value for the {@link OffsetGroup#edtOffset() edtOffset} 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 edtOffset * @return A modified copy of the {@code this} object */ public final ImmutableOffsetGroup withEdtOffset(EDTOffset value) { if (this.edtOffset == value) return this; EDTOffset newValue = Preconditions.checkNotNull(value, "edtOffset"); return new ImmutableOffsetGroup(this.byteOffset, this.charOffset, newValue, this.asrTime); } /** * Copy the current immutable object by setting a present value for the optional {@link OffsetGroup#asrTime() asrTime} attribute. * @param value The value for asrTime * @return A modified copy of {@code this} object */ public final ImmutableOffsetGroup withAsrTime(ASRTime value) { Optional newValue = Optional.of(value); if (this.asrTime.isPresent() && this.asrTime.get() == value) return this; return new ImmutableOffsetGroup(this.byteOffset, this.charOffset, this.edtOffset, newValue); } /** * Copy the current immutable object by setting an optional value for the {@link OffsetGroup#asrTime() asrTime} 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 asrTime * @return A modified copy of {@code this} object */ public final ImmutableOffsetGroup withAsrTime(Optional optional) { Optional value = Preconditions.checkNotNull(optional, "asrTime"); if (!this.asrTime.isPresent() && !value.isPresent()) return this; if (this.asrTime.isPresent() && value.isPresent() && this.asrTime.get() == value.get()) return this; return new ImmutableOffsetGroup(this.byteOffset, this.charOffset, this.edtOffset, value); } /** * This instance is equal to all instances of {@code ImmutableOffsetGroup} 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 ImmutableOffsetGroup && equalTo((ImmutableOffsetGroup) another); } private boolean equalTo(ImmutableOffsetGroup another) { return byteOffset.equals(another.byteOffset) && charOffset.equals(another.charOffset) && edtOffset.equals(another.edtOffset) && asrTime.equals(another.asrTime); } /** * Computes a hash code from attributes: {@code byteOffset}, {@code charOffset}, {@code edtOffset}, {@code asrTime}. * @return hashCode value */ @Override public int hashCode() { int h = 31; h = h * 17 + byteOffset.hashCode(); h = h * 17 + charOffset.hashCode(); h = h * 17 + edtOffset.hashCode(); h = h * 17 + asrTime.hashCode(); return h; } /** * Creates an immutable copy of a {@link OffsetGroup} 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 OffsetGroup instance */ public static OffsetGroup copyOf(OffsetGroup instance) { if (instance instanceof ImmutableOffsetGroup) { return (ImmutableOffsetGroup) instance; } return new OffsetGroup.Builder() .from(instance) .build(); } /** * Builds instances of type {@link OffsetGroup OffsetGroup}. * 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_CHAR_OFFSET = 0x1L; private static final long INIT_BIT_EDT_OFFSET = 0x2L; private long initBits = 0x3L; private Optional byteOffset = Optional.absent(); private @Nullable CharOffset charOffset; private @Nullable EDTOffset edtOffset; private Optional asrTime = Optional.absent(); /** * Creates a builder for {@link OffsetGroup OffsetGroup} instances. */ Builder() { if (!(this instanceof OffsetGroup.Builder)) { throw new UnsupportedOperationException("Use: new OffsetGroup.Builder()"); } } /** * Fill a builder with attribute values from the provided {@code OffsetGroup} 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 OffsetGroup.Builder from(OffsetGroup instance) { Preconditions.checkNotNull(instance, "instance"); Optional byteOffsetOptional = instance.byteOffset(); if (byteOffsetOptional.isPresent()) { byteOffset(byteOffsetOptional); } charOffset(instance.charOffset()); edtOffset(instance.edtOffset()); Optional asrTimeOptional = instance.asrTime(); if (asrTimeOptional.isPresent()) { asrTime(asrTimeOptional); } return (OffsetGroup.Builder) this; } /** * Initializes the optional value {@link OffsetGroup#byteOffset() byteOffset} to byteOffset. * @param byteOffset The value for byteOffset * @return {@code this} builder for chained invocation */ public final OffsetGroup.Builder byteOffset(ByteOffset byteOffset) { this.byteOffset = Optional.of(byteOffset); return (OffsetGroup.Builder) this; } /** * Initializes the optional value {@link OffsetGroup#byteOffset() byteOffset} to byteOffset. * @param byteOffset The value for byteOffset * @return {@code this} builder for use in a chained invocation */ public final OffsetGroup.Builder byteOffset(Optional byteOffset) { this.byteOffset = Preconditions.checkNotNull(byteOffset, "byteOffset"); return (OffsetGroup.Builder) this; } /** * Initializes the value for the {@link OffsetGroup#charOffset() charOffset} attribute. * @param charOffset The value for charOffset * @return {@code this} builder for use in a chained invocation */ public final OffsetGroup.Builder charOffset(CharOffset charOffset) { this.charOffset = Preconditions.checkNotNull(charOffset, "charOffset"); initBits &= ~INIT_BIT_CHAR_OFFSET; return (OffsetGroup.Builder) this; } /** * Initializes the value for the {@link OffsetGroup#edtOffset() edtOffset} attribute. * @param edtOffset The value for edtOffset * @return {@code this} builder for use in a chained invocation */ public final OffsetGroup.Builder edtOffset(EDTOffset edtOffset) { this.edtOffset = Preconditions.checkNotNull(edtOffset, "edtOffset"); initBits &= ~INIT_BIT_EDT_OFFSET; return (OffsetGroup.Builder) this; } /** * Initializes the optional value {@link OffsetGroup#asrTime() asrTime} to asrTime. * @param asrTime The value for asrTime * @return {@code this} builder for chained invocation */ public final OffsetGroup.Builder asrTime(ASRTime asrTime) { this.asrTime = Optional.of(asrTime); return (OffsetGroup.Builder) this; } /** * Initializes the optional value {@link OffsetGroup#asrTime() asrTime} to asrTime. * @param asrTime The value for asrTime * @return {@code this} builder for use in a chained invocation */ public final OffsetGroup.Builder asrTime(Optional asrTime) { this.asrTime = Preconditions.checkNotNull(asrTime, "asrTime"); return (OffsetGroup.Builder) this; } /** * Builds a new {@link OffsetGroup OffsetGroup}. * @return An immutable instance of OffsetGroup * @throws java.lang.IllegalStateException if any required attributes are missing */ public OffsetGroup build() { if (initBits != 0) { throw new IllegalStateException(formatRequiredAttributesMessage()); } return new ImmutableOffsetGroup(byteOffset, charOffset, edtOffset, asrTime); } private String formatRequiredAttributesMessage() { List attributes = Lists.newArrayList(); if ((initBits & INIT_BIT_CHAR_OFFSET) != 0) attributes.add("charOffset"); if ((initBits & INIT_BIT_EDT_OFFSET) != 0) attributes.add("edtOffset"); return "Cannot build OffsetGroup, some of required attributes are not set " + attributes; } } }





© 2015 - 2025 Weber Informatics LLC | Privacy Policy