LongRange (Apache Commons Lang 3.20.0 API)
Description: declaration: package: org.apache.commons.lang3, class: LongRange

# Class LongRange

java.lang.Object
org.apache.commons.lang3.Range<Long>
org.apache.commons.lang3.NumberRange<Long>
org.apache.commons.lang3.LongRange

All Implemented Interfaces:
  `Serializable`

public final class LongRange extends NumberRange<Long>
Specializes `NumberRange` for `Long`s.

This class is not designed to interoperate with other NumberRanges

Since:
  3.13.0
See Also:
  - Serialized Form

- ## Method Summary

  Modifier and Type
  Method
  Description
  `long`
  `fit(long element)`
  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.
  `static LongRange`
  `of(long fromInclusive, long toInclusive)`
  Creates a closed range with the specified minimum and maximum values (both inclusive).
  `static LongRange`
  `of(Long fromInclusive, Long toInclusive)`
  Creates a closed range with the specified minimum and maximum values (both inclusive).
  `LongStream`
  `toLongStream()`
  Returns a sequential ordered `LongStream` from `Range.getMinimum()` (inclusive) to `Range.getMaximum()` (inclusive) by an incremental step of `1`.

  ### Methods inherited from class Range

  `between, between, contains, containsRange, elementCompareTo, equals, fit, getComparator, getMaximum, getMinimum, hashCode, intersectionWith, is, is, isAfter, isAfterRange, isBefore, isBeforeRange, isEndedBy, isNaturalOrdering, isOverlappedBy, isStartedBy, of, of, toString, toString`

  ### Methods inherited from class Object

  `clone, finalize, getClass, notify, notifyAll, wait, wait, wait`

- ## Method Details

  - ### of

    public static LongRange of(long fromInclusive, long toInclusive)
    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` - the first value that defines the edge of the range, inclusive.
      `toInclusive` - the second value that defines the edge of the range, inclusive.
    Returns:
      the range object, not null.

  - ### of

    public static LongRange of(Long fromInclusive, Long toInclusive)
    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` - the first value that defines the edge of the range, inclusive.
      `toInclusive` - the second value that defines the edge of the range, inclusive.
    Returns:
      the range object, not null.
    Throws:
      `IllegalArgumentException` - if either element is null.

  - ### fit

    public long fit(long element)
    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` - the element to test.
    Returns:
      the minimum, the element, or the maximum depending on the element's location relative to the range.
    Since:
      3.19.0

  - ### toLongStream

    public LongStream toLongStream()
    Returns a sequential ordered `LongStream` from `Range.getMinimum()` (inclusive) to `Range.getMaximum()` (inclusive) by an incremental step of `1`.
    Returns:
      a sequential `LongStream` for the range of `long` elements
    Since:
      3.18.0