Package org.atlanmod.commons.collect
Interface IntRange
-
@Immutable @ParametersAreNonnullByDefault public interface IntRangeA range (or "interval") defines the boundaries around a contiguous span of values of integer.
-
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description static IntRangeall()Creates a range that contains every value of typeC.static IntRangeand(IntRange r1, IntRange r2)Creates a range that contains all values enclosed by both ranges.static IntRangeatLeast(int lower)Creates a range that contains all values greater than or equal tolower.static IntRangeatMost(int upper)Creates a range that contains all values less than or equal toupper.static IntRangeclosed(int lower, int upper)Creates a range that contains all values greater than or equal tolowerand less than or equal toupper.static IntRangeclosedOpen(int lower, int upper)Creates a range that contains all values greater than or equal tolowerand strictly less thanupper.booleancontains(int value)Returnstrueifvalueis within the bounds of this range.default booleancontainsAll(Iterable<Integer> values)Returnstrueif every element in values is contained in this range.static IntRangeempty()Creates a range that does not contain any value.static IntRangegreaterThan(int lower)Creates a range that contains all values strictly greater thanlower.static IntRangelessThan(int upper)Creates a range that contains all values strictly less thanupper.static IntRangeopen(int lower, int upper)Creates a range that contains all values strictly greater thanlowerand strictly less thanupper.static IntRangeopenClosed(int lower, int upper)Creates a range that contains all values strictly greater thanlowerand less than or equal toupper.static IntRangeor(IntRange r1, IntRange r2)Creates a range that contains all values enclosed by at least one range.static IntRangesingleton(int value)Creates a range that contains only the givenvalue.static IntRangexor(IntRange r1, IntRange r2)Creates a range that contains all values enclosed by one range, but not another.
-
-
-
Method Detail
-
open
@Nonnull static IntRange open(int lower, int upper)
Creates a range that contains all values strictly greater thanlowerand strictly less thanupper.- Parameters:
lower- the lower bound of the range (exclusive)upper- the upper bound of the range (exclusive)- Returns:
- a new range
- Throws:
IllegalArgumentException- ifloweris greater thanupper
-
closed
@Nonnull static IntRange closed(int lower, int upper)
Creates a range that contains all values greater than or equal tolowerand less than or equal toupper.- Parameters:
lower- the lower bound of the range (inclusive)upper- the upper bound of the range (inclusive)- Returns:
- a new range
- Throws:
IllegalArgumentException- ifloweris greater thanupper
-
openClosed
@Nonnull static IntRange openClosed(int lower, int upper)
Creates a range that contains all values strictly greater thanlowerand less than or equal toupper.- Parameters:
lower- the lower bound of the range (exclusive)upper- the upper bound of the range (inclusive)- Returns:
- a new range
- Throws:
IllegalArgumentException- ifloweris greater thanupper
-
closedOpen
@Nonnull static IntRange closedOpen(int lower, int upper)
Creates a range that contains all values greater than or equal tolowerand strictly less thanupper.- Parameters:
lower- the lower bound of the range (inclusive)upper- the upper bound of the range (exclusive)- Returns:
- a new instance of range
- Throws:
IllegalArgumentException- ifloweris greater thanupper
-
singleton
@Nonnull static IntRange singleton(int value)
Creates a range that contains only the givenvalue. The returned range is closed on both ends.- Parameters:
value- the unique value of the range- Returns:
- a new range
- See Also:
closed(int, int)
-
atLeast
@Nonnull static IntRange atLeast(int lower)
Creates a range that contains all values greater than or equal tolower.- Parameters:
lower- the lower bound of the range (inclusive)- Returns:
- a new range
-
atMost
@Nonnull static IntRange atMost(int upper)
Creates a range that contains all values less than or equal toupper.- Parameters:
upper- the upper bound of the range (inclusive)- Returns:
- a new range
-
greaterThan
@Nonnull static IntRange greaterThan(int lower)
Creates a range that contains all values strictly greater thanlower.- Parameters:
lower- the lower bound of the range (exclusive)- Returns:
- a new range
-
lessThan
@Nonnull static IntRange lessThan(int upper)
Creates a range that contains all values strictly less thanupper.- Parameters:
upper- the upper bound of the range (exclusive)- Returns:
- a new range
-
all
@Nonnull static IntRange all()
Creates a range that contains every value of typeC.- Returns:
- a new range
-
empty
@Nonnull static IntRange empty()
Creates a range that does not contain any value.- Returns:
- a new range
-
and
@Nonnull static IntRange and(IntRange r1, IntRange r2)
Creates a range that contains all values enclosed by both ranges.The intersection exists if and only if the two ranges are connected.
- Parameters:
r1- the first ranger2- the second range- Returns:
- a new range
- Throws:
NullPointerException- if any argument isnull- See Also:
Boolean.logicalAnd(boolean, boolean)
-
or
@Nonnull static IntRange or(IntRange r1, IntRange r2)
Creates a range that contains all values enclosed by at least one range.- Parameters:
r1- the first ranger2- the second range- Returns:
- a new range
- Throws:
NullPointerException- if any argument isnull- See Also:
Boolean.logicalOr(boolean, boolean)
-
xor
@Nonnull static IntRange xor(IntRange r1, IntRange r2)
Creates a range that contains all values enclosed by one range, but not another.- Parameters:
r1- the first ranger2- the second range- Returns:
- a new range
- Throws:
NullPointerException- if any argument isnull- See Also:
Boolean.logicalXor(boolean, boolean)
-
contains
boolean contains(int value)
Returnstrueifvalueis within the bounds of this range.- Parameters:
value- the value to be tested for inclusion- Returns:
trueifvalueis within the bounds of this range
-
containsAll
default boolean containsAll(Iterable<Integer> values)
Returnstrueif every element in values is contained in this range.- Parameters:
values- the value to be tested for inclusion- Returns:
trueif every element in values is contained in this range- Throws:
NullPointerException- if any argument isnull- See Also:
contains(int)
-
-