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

pl.poznan.put.torsion.ImmutableTorsionAngleValue Maven / Gradle / Ivy

package pl.poznan.put.torsion;

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import javax.annotation.Nullable;
import javax.annotation.ParametersAreNonnullByDefault;
import javax.annotation.concurrent.Immutable;
import javax.annotation.concurrent.NotThreadSafe;
import org.immutables.value.Generated;
import pl.poznan.put.circular.Angle;

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

* Use the builder to create immutable instances: * {@code ImmutableTorsionAngleValue.builder()}. * Use the static factory method to create immutable instances: * {@code ImmutableTorsionAngleValue.of()}. */ @Generated(from = "TorsionAngleValue", generator = "Immutables") @SuppressWarnings({"all"}) @ParametersAreNonnullByDefault @javax.annotation.processing.Generated("org.immutables.processor.ProxyProcessor") @Immutable public final class ImmutableTorsionAngleValue extends TorsionAngleValue { private final TorsionAngleType angleType; private final Angle value; private ImmutableTorsionAngleValue(TorsionAngleType angleType, Angle value) { this.angleType = Objects.requireNonNull(angleType, "angleType"); this.value = Objects.requireNonNull(value, "value"); } private ImmutableTorsionAngleValue( ImmutableTorsionAngleValue original, TorsionAngleType angleType, Angle value) { this.angleType = angleType; this.value = value; } /** *@return The type of this torsion angle. */ @Override public TorsionAngleType angleType() { return angleType; } /** *@return The value of this torsion angle. */ @Override public Angle value() { return value; } /** * Copy the current immutable object by setting a value for the {@link TorsionAngleValue#angleType() angleType} 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 angleType * @return A modified copy of the {@code this} object */ public final ImmutableTorsionAngleValue withAngleType(TorsionAngleType value) { if (this.angleType == value) return this; TorsionAngleType newValue = Objects.requireNonNull(value, "angleType"); return new ImmutableTorsionAngleValue(this, newValue, this.value); } /** * Copy the current immutable object by setting a value for the {@link TorsionAngleValue#value() value} 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 value * @return A modified copy of the {@code this} object */ public final ImmutableTorsionAngleValue withValue(Angle value) { if (this.value == value) return this; Angle newValue = Objects.requireNonNull(value, "value"); return new ImmutableTorsionAngleValue(this, this.angleType, newValue); } /** * This instance is equal to all instances of {@code ImmutableTorsionAngleValue} 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 ImmutableTorsionAngleValue && equalTo((ImmutableTorsionAngleValue) another); } private boolean equalTo(ImmutableTorsionAngleValue another) { return angleType.equals(another.angleType) && value.equals(another.value); } /** * Computes a hash code from attributes: {@code angleType}, {@code value}. * @return hashCode value */ @Override public int hashCode() { int h = 5381; h += (h << 5) + angleType.hashCode(); h += (h << 5) + value.hashCode(); return h; } /** * Prints the immutable value {@code TorsionAngleValue} with attribute values. * @return A string representation of the value */ @Override public String toString() { return "TorsionAngleValue{" + "angleType=" + angleType + ", value=" + value + "}"; } /** * Construct a new immutable {@code TorsionAngleValue} instance. * @param angleType The value for the {@code angleType} attribute * @param value The value for the {@code value} attribute * @return An immutable TorsionAngleValue instance */ public static ImmutableTorsionAngleValue of(TorsionAngleType angleType, Angle value) { return new ImmutableTorsionAngleValue(angleType, value); } /** * Creates an immutable copy of a {@link TorsionAngleValue} 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 TorsionAngleValue instance */ public static ImmutableTorsionAngleValue copyOf(TorsionAngleValue instance) { if (instance instanceof ImmutableTorsionAngleValue) { return (ImmutableTorsionAngleValue) instance; } return ImmutableTorsionAngleValue.builder() .from(instance) .build(); } /** * Creates a builder for {@link ImmutableTorsionAngleValue ImmutableTorsionAngleValue}. *

   * ImmutableTorsionAngleValue.builder()
   *    .angleType(pl.poznan.put.torsion.TorsionAngleType) // required {@link TorsionAngleValue#angleType() angleType}
   *    .value(pl.poznan.put.circular.Angle) // required {@link TorsionAngleValue#value() value}
   *    .build();
   * 
* @return A new ImmutableTorsionAngleValue builder */ public static ImmutableTorsionAngleValue.Builder builder() { return new ImmutableTorsionAngleValue.Builder(); } /** * Builds instances of type {@link ImmutableTorsionAngleValue ImmutableTorsionAngleValue}. * 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. */ @Generated(from = "TorsionAngleValue", generator = "Immutables") @NotThreadSafe public static final class Builder { private static final long INIT_BIT_ANGLE_TYPE = 0x1L; private static final long INIT_BIT_VALUE = 0x2L; private long initBits = 0x3L; private @Nullable TorsionAngleType angleType; private @Nullable Angle value; private Builder() { } /** * Fill a builder with attribute values from the provided {@code TorsionAngleValue} 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 Builder from(TorsionAngleValue instance) { Objects.requireNonNull(instance, "instance"); angleType(instance.angleType()); value(instance.value()); return this; } /** * Initializes the value for the {@link TorsionAngleValue#angleType() angleType} attribute. * @param angleType The value for angleType * @return {@code this} builder for use in a chained invocation */ public final Builder angleType(TorsionAngleType angleType) { this.angleType = Objects.requireNonNull(angleType, "angleType"); initBits &= ~INIT_BIT_ANGLE_TYPE; return this; } /** * Initializes the value for the {@link TorsionAngleValue#value() value} attribute. * @param value The value for value * @return {@code this} builder for use in a chained invocation */ public final Builder value(Angle value) { this.value = Objects.requireNonNull(value, "value"); initBits &= ~INIT_BIT_VALUE; return this; } /** * Builds a new {@link ImmutableTorsionAngleValue ImmutableTorsionAngleValue}. * @return An immutable instance of TorsionAngleValue * @throws java.lang.IllegalStateException if any required attributes are missing */ public ImmutableTorsionAngleValue build() { if (initBits != 0) { throw new IllegalStateException(formatRequiredAttributesMessage()); } return new ImmutableTorsionAngleValue(null, angleType, value); } private String formatRequiredAttributesMessage() { List attributes = new ArrayList<>(); if ((initBits & INIT_BIT_ANGLE_TYPE) != 0) attributes.add("angleType"); if ((initBits & INIT_BIT_VALUE) != 0) attributes.add("value"); return "Cannot build TorsionAngleValue, some of required attributes are not set " + attributes; } } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy