Package org.jjazz.utilities.api
Class IntRange
java.lang.Object
org.jjazz.utilities.api.IntRange
A basic integer (zero or positive) interval.
This is an immutable class.
-
Field Summary
Modifier and TypeFieldDescriptionstatic final IntRange
The special shared instance for the empty range.final int
final int
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionboolean
contains
(int x) Check if value is within the range.boolean
Check if specified range is contained in this range.boolean
float
The center of the range.getTransformed
(int offset) getTransformed
(int fromOffset, int toOffset) Get a new range with bounds modified.Get a new range made from the lowest and highest bounds from this object and r.int
hashCode()
boolean
Test if r is adjacent to this range, e.g. [4;6] and [7;12] are adjacent.boolean
isEmpty()
boolean
Check if specified range intersects with this range.int
size()
Get the size of the range.toString()
-
Field Details
-
EMPTY_RANGE
The special shared instance for the empty range. -
from
public final int from -
to
public final int to
-
-
Constructor Details
-
IntRange
public IntRange(int from, int to) A range representing [from; to].- Parameters:
from
- Must be >= 0to
- Must be >= from
-
-
Method Details
-
isEmpty
public boolean isEmpty() -
size
public int size()Get the size of the range.- Returns:
- (to - from + 1), or 0 for the EMPTY_RANGE.
-
contains
public boolean contains(int x) Check if value is within the range.- Parameters:
x
-- Returns:
-
contains
Check if specified range is contained in this range.- Parameters:
r
-- Returns:
-
isAdjacent
Test if r is adjacent to this range, e.g. [4;6] and [7;12] are adjacent.If ranges intersect, there are not adjacent. If one of the range is empty, return false.
- Parameters:
r
-- Returns:
-
getUnion
Get a new range made from the lowest and highest bounds from this object and r.If one of the range is empty, return the empty range.
- Parameters:
r
-- Returns:
-
getIntersection
- Parameters:
r
-- Returns:
- Can return the EMPTY_RANGE if no intersection.
-
isIntersecting
Check if specified range intersects with this range.Note: [2;4] and [4;7] intersects.
- Parameters:
r
-- Returns:
-
getCenter
public float getCenter()The center of the range.- Returns:
- (to-from)/2 + from
-
getTransformed
Get a new range with bounds modified.If this object is the the empty range, just return the empty range.
- Parameters:
fromOffset
-toOffset
-- Returns:
-
getTransformed
-
toString
-
hashCode
public int hashCode() -
equals
-