Class Range

java.lang.Object
net.luis.utils.util.Range

public class Range extends Object
Represents a range of values between a minimum and maximum value (inclusive).
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final Range
    A constant for an empty range.
    The minimum and maximum value are both 0.
    private final double
    The maximum value of the range.
    private final double
    The minimum value of the range.
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    protected
    Range(double min, double max)
    Constructs a new range with the specified minimum and maximum value.
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
     
    @NotNull Range
    expand(double value)
    Expands the range by the specified value.
    @NotNull Range
    expandMax(double value)
    Expands the maximum value of the range by the absolute of specified value.
    @NotNull Range
    expandMin(double value)
    Expands the minimum value of the range by the absolute of specified value.
    The resulting range is maybe empty if the given value is negative.
    double
    Returns the maximum value of the range.
    double
    Returns the minimum value of the range.
    double
    Returns the range between the minimum and maximum value.
    The range is calculated by subtracting the minimum value from the maximum value.
    int
     
    boolean
    isInRange(double value)
    Checks if the specified value is within the range of this range.
    @NotNull Range
    move(double value)
    Moves the range by the specified value.
    The minimum and maximum value are both increased by the specified value.
    static @NotNull Range
    of(char min, char max)
    Creates a new range with the specified minimum and maximum value.
    The characters are converted to their respective double values.
    static @NotNull Range
    of(double max)
    Creates a new range with the specified maximum value.
    The minimum value is set to 0.
    static @NotNull Range
    of(double min, double max)
    Creates a new range with the specified minimum and maximum value.
    static @NotNull Range
    parse(@Nullable String str)
    Parses the specified string to a range.
    The string must be in the format of [min..max].
     

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait
  • Field Details

    • EMPTY

      public static final Range EMPTY
      A constant for an empty range.
      The minimum and maximum value are both 0.
    • min

      private final double min
      The minimum value of the range.
    • max

      private final double max
      The maximum value of the range.
  • Constructor Details

    • Range

      protected Range(double min, double max)
      Constructs a new range with the specified minimum and maximum value.
      Parameters:
      min - The minimum value of the range
      max - The maximum value of the range
      Throws:
      IllegalArgumentException - If the maximum value is less than the minimum value
  • Method Details

    • of

      @NotNull public static @NotNull Range of(double max)
      Creates a new range with the specified maximum value.
      The minimum value is set to 0.
      Parameters:
      max - The maximum value of the range
      Returns:
      The created range or an empty range if the maximum value is less than 0
      See Also:
    • of

      @NotNull public static @NotNull Range of(char min, char max)
      Creates a new range with the specified minimum and maximum value.
      The characters are converted to their respective double values.
      Parameters:
      min - The minimum value of the range
      max - The maximum value of the range
      Returns:
      The created range or an empty range if the maximum value is less than the minimum value
      See Also:
    • of

      @NotNull public static @NotNull Range of(double min, double max)
      Creates a new range with the specified minimum and maximum value.
      Parameters:
      min - The minimum value of the range
      max - The maximum value of the range
      Returns:
      The created range or an empty range if the maximum value is less than the minimum value
      See Also:
    • parse

      @NotNull public static @NotNull Range parse(@Nullable @Nullable String str)
      Parses the specified string to a range.
      The string must be in the format of [min..max].
      Parameters:
      str - The string to parse
      Returns:
      The parsed range, or an empty range if the string is invalid
    • getMin

      public double getMin()
      Returns the minimum value of the range.
      Returns:
      The minimum
    • getMax

      public double getMax()
      Returns the maximum value of the range.
      Returns:
      The maximum
    • getRange

      public double getRange()
      Returns the range between the minimum and maximum value.
      The range is calculated by subtracting the minimum value from the maximum value.
      Returns:
      The range
    • move

      @NotNull public @NotNull Range move(double value)
      Moves the range by the specified value.
      The minimum and maximum value are both increased by the specified value.
      Parameters:
      value - The value to move the range by
      Returns:
      The moved range
    • expand

      @NotNull public @NotNull Range expand(double value)
      Expands the range by the specified value.

      The minimum value is decreased by the absolute of the specified value
      and the maximum value is increased by the absolute of specified value.

      Parameters:
      value - The value to expand the range by
      Returns:
      The expanded range
    • expandMax

      @NotNull public @NotNull Range expandMax(double value)
      Expands the maximum value of the range by the absolute of specified value.
      Parameters:
      value - The value to expand the maximum value by
      Returns:
      The expanded range
    • expandMin

      @NotNull public @NotNull Range expandMin(double value)
      Expands the minimum value of the range by the absolute of specified value.
      The resulting range is maybe empty if the given value is negative.
      Parameters:
      value - The value to expand the minimum value by
      Returns:
      The expanded range
    • isInRange

      public boolean isInRange(double value)
      Checks if the specified value is within the range of this range.
      Parameters:
      value - The value to check
      Returns:
      True if the value is within the range, otherwise false
      See Also:
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object