java.lang.Object
net.luis.utils.util.Range
Represents a range of values between a minimum and maximum value (inclusive).
-
Field Summary
Fields -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotected
Range
(double min, double max) Constructs a new range with the specified minimum and maximum value. -
Method Summary
Modifier and TypeMethodDescriptionboolean
@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
getMax()
Returns the maximum value of the range.double
getMin()
Returns the minimum value of the range.double
getRange()
Returns the range between the minimum and maximum value.
The range is calculated by subtracting the minimum value from the maximum value.int
hashCode()
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
Parses the specified string to a range.
The string must be in the format of[min..max]
.toString()
-
Field Details
-
EMPTY
A constant for an empty range.
The minimum and maximum value are both 0. -
min
private final double minThe minimum value of the range. -
max
private final double maxThe 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 rangemax
- The maximum value of the range- Throws:
IllegalArgumentException
- If the maximum value is less than the minimum value
-
-
Method Details
-
of
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
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 rangemax
- 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
Creates a new range with the specified minimum and maximum value.- Parameters:
min
- The minimum value of the rangemax
- 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
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
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
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
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
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
-
hashCode
public int hashCode() -
toString
-