Package org.atlanmod.commons.collect
Interface Range<C extends Comparable<C>>
-
- Type Parameters:
C- the type of this range
- Functional Interface:
- This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.
@Immutable @ParametersAreNonnullByDefault @FunctionalInterface public interface Range<C extends Comparable<C>>
A range (or "interval") defines the boundaries around a contiguous span of values of someComparabletype.
-
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description static <C extends Comparable<C>>
Range<C>all()Creates a range that contains every value of typeC.static <C extends Comparable<C>>
Range<C>and(Range<C> r1, Range<C> r2)Creates a range that contains all values enclosed by both ranges.static <C extends Comparable<C>>
Range<C>atLeast(C lower)Creates a range that contains all values greater than or equal tolower.static <C extends Comparable<C>>
Range<C>atMost(C upper)Creates a range that contains all values less than or equal toupper.static <C extends Comparable<C>>
Range<C>closed(C lower, C upper)Creates a range that contains all values greater than or equal tolowerand less than or equal toupper.static <C extends Comparable<C>>
Range<C>closedOpen(C lower, C upper)Creates a range that contains all values greater than or equal tolowerand strictly less thanupper.booleancontains(C value)Returnstrueifvalueis within the bounds of this range.default booleancontainsAll(Iterable<? extends C> values)Returnstrueif every element in values is contained in this range.static <C extends Comparable<C>>
Range<C>empty()Creates a range that does not contain any value.static <C extends Comparable<C>>
Range<C>greaterThan(C lower)Creates a range that contains all values strictly greater thanlower.static <C extends Comparable<C>>
Range<C>lessThan(C upper)Creates a range that contains all values strictly less thanupper.static <C extends Comparable<C>>
Range<C>open(C lower, C upper)Creates a range that contains all values strictly greater thanlowerand strictly less thanupper.static <C extends Comparable<C>>
Range<C>openClosed(C lower, C upper)Creates a range that contains all values strictly greater thanlowerand less than or equal toupper.static <C extends Comparable<C>>
Range<C>or(Range<C> r1, Range<C> r2)Creates a range that contains all values enclosed by at least one range.static <C extends Comparable<C>>
Range<C>singleton(C value)Creates a range that contains only the givenvalue.static <C extends Comparable<C>>
Range<C>xor(Range<C> r1, Range<C> r2)Creates a range that contains all values enclosed by one range, but not another.
-
-
-
Method Detail
-
open
@Nonnull static <C extends Comparable<C>> Range<C> open(C lower, C upper)
Creates a range that contains all values strictly greater thanlowerand strictly less thanupper.- Type Parameters:
C- the type of the range- Parameters:
lower- the lower bound of the range (exclusive)upper- the upper bound of the range (exclusive)- Returns:
- a new range
- Throws:
NullPointerException- if any argument isnullIllegalArgumentException- ifloweris greater thanupper
-
closed
@Nonnull static <C extends Comparable<C>> Range<C> closed(C lower, C upper)
Creates a range that contains all values greater than or equal tolowerand less than or equal toupper.- Type Parameters:
C- the type of the range- Parameters:
lower- the lower bound of the range (inclusive)upper- the upper bound of the range (inclusive)- Returns:
- a new range
- Throws:
NullPointerException- if any argument isnullIllegalArgumentException- ifloweris greater thanupper
-
openClosed
@Nonnull static <C extends Comparable<C>> Range<C> openClosed(C lower, C upper)
Creates a range that contains all values strictly greater thanlowerand less than or equal toupper.- Type Parameters:
C- the type of the range- Parameters:
lower- the lower bound of the range (exclusive)upper- the upper bound of the range (inclusive)- Returns:
- a new range
- Throws:
NullPointerException- if any argument isnullIllegalArgumentException- ifloweris greater thanupper
-
closedOpen
@Nonnull static <C extends Comparable<C>> Range<C> closedOpen(C lower, C upper)
Creates a range that contains all values greater than or equal tolowerand strictly less thanupper.- Type Parameters:
C- the type of the range- Parameters:
lower- the lower bound of the range (inclusive)upper- the upper bound of the range (exclusive)- Returns:
- a new instance of range
- Throws:
NullPointerException- if any argument isnullIllegalArgumentException- ifloweris greater thanupper
-
singleton
@Nonnull static <C extends Comparable<C>> Range<C> singleton(C value)
Creates a range that contains only the givenvalue. The returned range is closed on both ends.- Type Parameters:
C- the type of the range- Parameters:
value- the unique value of the range- Returns:
- a new range
- Throws:
NullPointerException- if any argument isnull- See Also:
closed(Comparable, Comparable)
-
atLeast
@Nonnull static <C extends Comparable<C>> Range<C> atLeast(C lower)
Creates a range that contains all values greater than or equal tolower.- Type Parameters:
C- the type of the range- Parameters:
lower- the lower bound of the range (inclusive)- Returns:
- a new range
- Throws:
NullPointerException- if any argument isnull
-
atMost
@Nonnull static <C extends Comparable<C>> Range<C> atMost(C upper)
Creates a range that contains all values less than or equal toupper.- Type Parameters:
C- the type of the range- Parameters:
upper- the upper bound of the range (inclusive)- Returns:
- a new range
- Throws:
NullPointerException- if any argument isnull
-
greaterThan
@Nonnull static <C extends Comparable<C>> Range<C> greaterThan(C lower)
Creates a range that contains all values strictly greater thanlower.- Type Parameters:
C- the type of the range- Parameters:
lower- the lower bound of the range (exclusive)- Returns:
- a new range
- Throws:
NullPointerException- if any argument isnull
-
lessThan
@Nonnull static <C extends Comparable<C>> Range<C> lessThan(C upper)
Creates a range that contains all values strictly less thanupper.- Type Parameters:
C- the type of the range- Parameters:
upper- the upper bound of the range (exclusive)- Returns:
- a new range
- Throws:
NullPointerException- if any argument isnull
-
all
@Nonnull static <C extends Comparable<C>> Range<C> all()
Creates a range that contains every value of typeC.- Type Parameters:
C- the type of the range- Returns:
- a new range
-
empty
@Nonnull static <C extends Comparable<C>> Range<C> empty()
Creates a range that does not contain any value.- Type Parameters:
C- the type of the range- Returns:
- a new range
-
and
@Nonnull static <C extends Comparable<C>> Range<C> and(Range<C> r1, Range<C> r2)
Creates a range that contains all values enclosed by both ranges.The intersection exists if and only if the two ranges are connected.
- Type Parameters:
C- the type of the range- 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 <C extends Comparable<C>> Range<C> or(Range<C> r1, Range<C> r2)
Creates a range that contains all values enclosed by at least one range.- Type Parameters:
C- the type of the 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 <C extends Comparable<C>> Range<C> xor(Range<C> r1, Range<C> r2)
Creates a range that contains all values enclosed by one range, but not another.- Type Parameters:
C- the type of the range- 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(C 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- Throws:
NullPointerException- if any argument isnull
-
containsAll
default boolean containsAll(Iterable<? extends C> 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(Comparable)
-
-