Package org.jjazz.utilities.api
Class LongRange
java.lang.Object
org.jjazz.utilities.api.LongRange
A basic long integer (zero or positive) interval.
This is an immutable class.
-
Field Summary
Modifier and TypeFieldDescriptionstatic final LongRange
The special shared instance for the empty range.final long
final long
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionboolean
contains
(long x) Check if value is within the range.boolean
Check if specified range is contained in this range.boolean
getTransformed
(long offset) Get a new range with bounds modified by adding offset.getTransformed
(long fromOffset, long toOffset) Get a new range with bounds modified by adding fromOffset and toOffset.int
hashCode()
boolean
Check if specified range intersects with this range.boolean
isEmpty()
long
size()
Get the size of the range.toString()
-
Field Details
-
EMPTY_LONG_RANGE
The special shared instance for the empty range. -
from
public final long from -
to
public final long to
-
-
Constructor Details
-
LongRange
public LongRange(long from, long to) A range representing [from; to].- Parameters:
from
- Must be >= 0to
- Must be >= from
-
-
Method Details
-
isEmpty
public boolean isEmpty() -
size
public long size()Get the size of the range.- Returns:
- (to - from + 1), or 0 for the EMPTY_LONG_RANGE.
-
contains
public boolean contains(long x) Check if value is within the range.- Parameters:
x
-- Returns:
-
contains
Check if specified range is contained in this range.- Parameters:
r
-- Returns:
-
getIntersectRange
- Parameters:
r
-- Returns:
- Return the EMPTY_LONG_RANGE if no intersection.
-
intersects
Check if specified range intersects with this range.Note: [2;4] and [4;7] intersects.
- Parameters:
r
-- Returns:
-
getTransformed
Get a new range with bounds modified by adding fromOffset and toOffset.If this object is the the empty range, just return the empty range.
- Parameters:
fromOffset
-toOffset
-- Returns:
-
getTransformed
Get a new range with bounds modified by adding offset.If this object is the the empty range, just return the empty range.
- Parameters:
offset
-- Returns:
-
toString
-
equals
-
hashCode
public int hashCode()
-