/** * Construct a new immutable {@code RangeInclusiveD} instance. * @param lower The value for the {@code lower} attribute * @param upper The value for the {@code upper} attribute * @return An immutable RangeInclusiveD instance */ public static RangeInclusiveD of(double lower, double upper) { return validate(new RangeInclusiveD(lower, upper)); }
private static RangeInclusiveD validate(RangeInclusiveD instance) { instance.checkPreconditions(); return instance; }
/** * This instance is equal to all instances of {@code RangeInclusiveD} 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 RangeInclusiveD && equalTo((RangeInclusiveD) another); }
/** * <p> Determine if the given range is included in this range. </p> * * @param other The given range * * @return {@code true} iff {@code this.getLower() >= other.getLower() * && this.getUpper() <= other.getUpper()} . */ default boolean isIncludedIn( final RangeInclusiveD other) { Objects.requireNonNull(other, "Other range"); return (this.lower() >= (double) other.lower()) && (this.upper() <= (double) other.upper()); }
/** * Builds a new {@link RangeInclusiveD RangeInclusiveD}. * @return An immutable instance of RangeInclusiveD * @throws java.lang.IllegalStateException if any required attributes are missing */ public RangeInclusiveD build() { if (initBits != 0) { throw new IllegalStateException(formatRequiredAttributesMessage()); } return RangeInclusiveD.validate(new RangeInclusiveD(lower, upper)); }
/** * Creates an immutable copy of a {@link RangeInclusiveDType} 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 RangeInclusiveD instance */ public static RangeInclusiveD copyOf(RangeInclusiveDType instance) { if (instance instanceof RangeInclusiveD) { return (RangeInclusiveD) instance; } return RangeInclusiveD.builder() .from(instance) .build(); }
/** * Copy the current immutable object by setting a value for the {@link RangeInclusiveDType#lower() lower} attribute. * A value strict bits equality used to prevent copying of the same value by returning {@code this}. * @param value A new value for lower * @return A modified copy of the {@code this} object */ public final RangeInclusiveD withLower(double value) { if (Double.doubleToLongBits(this.lower) == Double.doubleToLongBits(value)) return this; return validate(new RangeInclusiveD(value, this.upper)); }
/** * Copy the current immutable object by setting a value for the {@link RangeInclusiveDType#upper() upper} attribute. * A value strict bits equality used to prevent copying of the same value by returning {@code this}. * @param value A new value for upper * @return A modified copy of the {@code this} object */ public final RangeInclusiveD withUpper(double value) { if (Double.doubleToLongBits(this.upper) == Double.doubleToLongBits(value)) return this; return validate(new RangeInclusiveD(this.lower, value)); }