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

public final Class LongRange

extends NumberRange<Long>
Class Inheritance
Imports
java.util.stream.LongStream

Specializes NumberRange for Longs.

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
LongRange(final Long
the first element, not null
number1
,
final Long
the second element, not null
number2
)

Creates a new instance.

Method Summary

Modifier and TypeMethod and Description
public long

Returns:

the minimum, the element, or the maximum depending on the element's location relative to the range.
fit
(final long
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 LongRange

Returns:

the range object, not null.
of
(final long
the first value that defines the edge of the range, inclusive.
fromInclusive
,
final long
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 LongRange

Returns:

the range object, not null.
of
(final Long
the first value that defines the edge of the range, inclusive.
fromInclusive
,
final Long
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 LongStream

Returns:

a sequential LongStream for the range of long elements
toLongStream
()

Returns a sequential ordered LongStream 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

LongRangeback to summary
private LongRange(final Long number1, final Long number2)

Creates a new instance.

Parameters
number1:Long

the first element, not null

number2:Long

the second element, not null

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

Method Detail

fitback to summary
public long fit(final long 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.

LongRange range = LongRange.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:long

the element to test.

Returns:long

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 LongRange of(final long fromInclusive, final long 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:long

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

toInclusive:long

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

Returns:LongRange

the range object, not null.

ofback to summary
public static LongRange of(final Long fromInclusive, final Long 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:Long

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

toInclusive:Long

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

Returns:LongRange

the range object, not null.

Exceptions
IllegalArgumentException:
if either element is null.
toLongStreamback to summary
public LongStream toLongStream()

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

Returns:LongStream

a sequential LongStream for the range of long elements

Since
3.18.0