/** * <p> Determine if the given value is included in this range. </p> * * @param value The given value * * @return {@code true} iff {@code value >= this.getLower() && * value <= this.getUpper()} . */ default boolean includesValue( final int value) { return (value >= this.lower()) && (value <= this.upper()); }
/** * <p>Retrieve the number of values in the range {@code [lower, upper]}. That * is, {@code (upper - lower) + 1}.<p> * * @return The number of values in the range */ @Value.Derived default int interval() { return (this.upper() - this.lower()) + 1; }
/** * Fill a builder with attribute values from the provided {@code RangeInclusiveIType} 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(RangeInclusiveIType instance) { Objects.requireNonNull(instance, "instance"); setLower(instance.lower()); setUpper(instance.upper()); return this; }
/** * <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 RangeInclusiveI other) { Objects.requireNonNull(other, "Other range"); return (this.lower() >= other.lower()) && (this.upper() <= other.upper()); }
/** * Check preconditions for the type. */ @Value.Check default void checkPreconditions() { RangeCheck.checkLessEqualInteger( this.lower(), "lower", this.upper(), "upper"); } }