T - @Immutable public final class Range<T extends Comparable<? super T>> extends Object implements Serializable, Immutable
Note: it's copied from Apache Commons Lang developed at The Apache Software Foundation (http://www.apache.org/), or under the Apache License 2.0. The methods copied from other products/frameworks may be modified in this class.
An immutable range of objects from a minimum to maximum point inclusive.
#ThreadSafe# if the objects and comparator are thread-safe
| Modifier and Type | Class and Description |
|---|---|
static class |
Range.BoundType
The Enum BoundType.
|
| Modifier and Type | Method and Description |
|---|---|
Range.BoundType |
boundType() |
static <T extends Comparable<? super T>> |
closed(T min,
T max) |
static <T extends Comparable<? super T>> |
closedOpen(T min,
T max) |
int |
compareTo(T element)
Checks where the specified element occurs relative to this range.
|
boolean |
contains(T element)
Checks whether the specified element occurs within this range.
|
boolean |
containsAll(Collection<? extends T> c) |
boolean |
containsRange(Range<T> other)
Checks whether this range contains all the elements of the specified range.
|
boolean |
equals(Object obj)
Compares this range to another object to test if they are equal.
|
int |
hashCode()
Gets a suitable hash code for the range.
|
u.Optional<Range<T>> |
intersection(Range<T> other)
Calculate the intersection of
this and an overlapping Range. |
boolean |
isAfter(T element)
Checks whether this range is after the specified element.
|
boolean |
isAfterRange(Range<T> other)
Checks whether this range is completely after the specified range.
|
boolean |
isBefore(T element)
Checks whether this range is before the specified element.
|
boolean |
isBeforeRange(Range<T> other)
Checks whether this range is completely before the specified range.
|
boolean |
isEmpty()
Checks if is empty.
|
boolean |
isEndedBy(T element)
Checks whether this range starts with the specified element.
|
boolean |
isOverlappedBy(Range<T> other)
Checks whether this range is overlapped by the specified range.
|
boolean |
isStartedBy(T element)
Checks whether this range starts with the specified element.
|
static <T extends Comparable<? super T>> |
just(T element)
Obtains a range using the specified element as both the minimum and maximum in this range.
|
T |
lowerEndpoint()
Gets the minimum value in this range.
|
static <T extends Comparable<? super T>> |
open(T min,
T max) |
static <T extends Comparable<? super T>> |
openClosed(T min,
T max) |
Range<T> |
span(Range<T> other)
Copied from Guava under Apache License v2.0
Returns the minimal range that encloses both this range and other. |
String |
toString() |
T |
upperEndpoint()
Gets the maximum value in this range.
|
public static <T extends Comparable<? super T>> Range<T> just(T element)
Obtains a range using the specified element as both the minimum and maximum in this range.
The range uses the natural ordering of the elements to determine where values lie in the range.
T - the type of the elements in this rangeelement - the value to use for this range, not nullIllegalArgumentException - if the element is nullpublic static <T extends Comparable<? super T>> Range<T> open(T min, T max)
T - min - max - IllegalArgumentException - if the 'min' or 'max' is null, or min > max.public static <T extends Comparable<? super T>> Range<T> openClosed(T min, T max)
T - min - max - IllegalArgumentException - if the 'min' or 'max' is null, or min > max.public static <T extends Comparable<? super T>> Range<T> closedOpen(T min, T max)
T - min - max - IllegalArgumentException - if the 'min' or 'max' is null, or min > max.public static <T extends Comparable<? super T>> Range<T> closed(T min, T max)
T - min - max - IllegalArgumentException - if the 'min' or 'max' is null, or min > max.public Range.BoundType boundType()
public T lowerEndpoint()
Gets the minimum value in this range.
public T upperEndpoint()
Gets the maximum value in this range.
public boolean contains(T element)
Checks whether the specified element occurs within this range.
element - the element to check for, null returns falsepublic boolean containsAll(Collection<? extends T> c)
c - public boolean isStartedBy(T element)
Checks whether this range starts with the specified element.
element - the element to check for, null returns falsepublic boolean isEndedBy(T element)
Checks whether this range starts with the specified element.
element - the element to check for, null returns falsepublic boolean isAfter(T element)
Checks whether this range is after the specified element.
element - the element to check for, null returns falsepublic boolean isBefore(T element)
Checks whether this range is before the specified element.
element - the element to check for, null returns falsepublic int compareTo(T element)
Checks where the specified element occurs relative to this range.
Returns -1 if this range is before the specified element,
1 if the this range is after the specified element, otherwise 0 if the specified element is contained in this range.
element - the element to check for, not nullpublic boolean containsRange(Range<T> other)
Checks whether this range contains all the elements of the specified range.
other - the range to check, null returns falseRuntimeException - if ranges cannot be comparedpublic boolean isAfterRange(Range<T> other)
Checks whether this range is completely after the specified range.
other - the range to check, null returns falseRuntimeException - if ranges cannot be comparedpublic boolean isBeforeRange(Range<T> other)
Checks whether this range is completely before the specified range.
other - the range to check, null returns falseRuntimeException - if ranges cannot be comparedpublic boolean isOverlappedBy(Range<T> other)
Checks whether this range is overlapped by the specified range.
Two ranges overlap if there is at least one element in common.
other - the range to test, null returns falsefalseRuntimeException - if ranges cannot be comparedpublic u.Optional<Range<T>> intersection(Range<T> other)
this and an overlapping Range.other - overlapping Rangethis and other, this if equal, or Optional.empty() if they're not overlapped.public Range<T> span(Range<T> other)
other. For example, the span of [1..3] and (5..7) is [1..7).
If the input ranges are connected, the returned range can also be called their union. If they are not, note that the span might contain values that are not contained in either input range.
Like intersection, this operation is commutative, associative
and idempotent. Unlike it, it is always well-defined for any two input ranges.
other - public boolean isEmpty()
public boolean equals(Object obj)
Compares this range to another object to test if they are equal.
.To be equal, the minimum and maximum values must be equal, which ignores any differences in the comparator.
public int hashCode()
Gets a suitable hash code for the range.
Copyright © 2021. All rights reserved.