Top Description Fields Constructors Methods
org.apache.commons.lang3

public final Class IntegerRange

extends NumberRange<Integer>
Class Inheritance
Imports
java.util.stream.IntStream

Specializes NumberRange for Integers.

This class is not designed to interoperate with other NumberRanges

Since
3.13.0

Field Summary

Modifier and TypeField and Description
private static final long

Constructor Summary

AccessConstructor and Description
private
IntegerRange(final Integer
the first element, not null
number1
,
final Integer
the second element, not null
number2
)

Creates a new instance.

Method Summary

Modifier and TypeMethod and Description
public int

Returns:

the minimum, the element, or the maximum depending on the element's location relative to the range.
fit
(final int
the element to test.
element
)

Overrides org.apache.commons.lang3.Range.fit.

Fits the given value into this range by returning the given value or, if out of bounds, the range minimum if below, or the range maximum if above.

public static IntegerRange

Returns:

the range object, not null.
of
(final int
the first value that defines the edge of the range, inclusive.
fromInclusive
,
final int
the second value that defines the edge of the range, inclusive.
toInclusive
)

Hides org.apache.commons.lang3.Range.of.

Creates a closed range with the specified minimum and maximum values (both inclusive).

public static IntegerRange

Returns:

the range object, not null.
of
(final Integer
the first value that defines the edge of the range, inclusive.
fromInclusive
,
final Integer
the second value that defines the edge of the range, inclusive.
toInclusive
)

Hides org.apache.commons.lang3.Range.of.

Creates a closed range with the specified minimum and maximum values (both inclusive).

public IntStream

Returns:

a sequential IntStream for the range of int elements
toIntStream
()

Returns a sequential ordered IntStream from getMinimum() (inclusive) to getMaximum() (inclusive) by an incremental step of 1.

Field Detail

serialVersionUIDback to summary
private static final long serialVersionUID

Hides org.apache.commons.lang3.NumberRange.serialVersionUID.

Constructor Detail

IntegerRangeback to summary
private IntegerRange(final Integer number1, final Integer number2)

Creates a new instance.

Parameters
number1:Integer

the first element, not null

number2:Integer

the second element, not null

Exceptions
NullPointerException:
  • when element1 is null.
  • when element2 is null.

Method Detail

fitback to summary
public int fit(final int element)

Overrides org.apache.commons.lang3.Range.fit.

Fits the given value into this range by returning the given value or, if out of bounds, the range minimum if below, or the range maximum if above.

IntegerRange range = IntegerRange.of(16, 64);
range.fit(-9) -->  16
range.fit(0)  -->  16
range.fit(15) -->  16
range.fit(16) -->  16
range.fit(17) -->  17
...
range.fit(63) -->  63
range.fit(64) -->  64
range.fit(99) -->  64
Parameters
element:int

the element to test.

Returns:int

the minimum, the element, or the maximum depending on the element's location relative to the range.

Since
3.19.0
ofback to summary
public static IntegerRange of(final int fromInclusive, final int toInclusive)

Hides org.apache.commons.lang3.Range.of.

Creates a closed range with the specified minimum and maximum values (both inclusive).

The range uses the natural ordering of the elements to determine where values lie in the range.

The arguments may be passed in the order (min,max) or (max,min). The getMinimum and getMaximum methods will return the correct values.

Parameters
fromInclusive:int

the first value that defines the edge of the range, inclusive.

toInclusive:int

the second value that defines the edge of the range, inclusive.

Returns:IntegerRange

the range object, not null.

ofback to summary
public static IntegerRange of(final Integer fromInclusive, final Integer toInclusive)

Hides org.apache.commons.lang3.Range.of.

Creates a closed range with the specified minimum and maximum values (both inclusive).

The range uses the natural ordering of the elements to determine where values lie in the range.

The arguments may be passed in the order (min,max) or (max,min). The getMinimum and getMaximum methods will return the correct values.

Parameters
fromInclusive:Integer

the first value that defines the edge of the range, inclusive.

toInclusive:Integer

the second value that defines the edge of the range, inclusive.

Returns:IntegerRange

the range object, not null.

Exceptions
IllegalArgumentException:
if either element is null.
toIntStreamback to summary
public IntStream toIntStream()

Returns a sequential ordered IntStream from getMinimum() (inclusive) to getMaximum() (inclusive) by an incremental step of 1.

Returns:IntStream

a sequential IntStream for the range of int elements

Since
3.18.0