Class IntRange
java.lang.Object
org.jjazz.utilities.api.IntRange
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final IntRangeThe special shared instance for the empty range.final intfinal int -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionintclamp(int value) Clamps the value to fit in this range.booleancontains(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.getUnion(int x) Extend the current range to include x.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.iterator()Merge adjacent IntRanges from a list.static IntRangeCreate an IntRange from the first and last x position of the rectangle.static IntRangeCreate an IntRange from the first and last x position of the rectangle.intsize()Get the size of the range.stream()toString()Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
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
-
ofX
-
ofY
-
merge
-
isEmpty
public boolean isEmpty() -
stream
-
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
-
getUnion
Extend the current range to include x.If this range is empty, return the empty range.
- Parameters:
x-- Returns:
-
getIntersection
-
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
- Throws:
IllegalStateException- If range is empty
-
clamp
public int clamp(int value) Clamps the value to fit in this range.- Parameters:
value-- Returns:
-
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
-
equals
-
iterator
-