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
FieldsModifier and TypeFieldDescriptionstatic final IntRangeThe special shared instance for the empty range.final intfinal int -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbooleancontains(int x) Check if value is within the range.booleanCheck if specified range is contained in this range.booleanfloatThe 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.inthashCode()booleanTest if r is adjacent to this range, e.g. [4;6] and [7;12] are adjacent.booleanisEmpty()booleanCheck if specified range intersects with this range.intsize()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
-