Package com.google.common.collect
Class DiscreteDomain<C extends Comparable>
- java.lang.Object
-
- com.google.common.collect.DiscreteDomain<C>
-
@GwtCompatible @Beta public abstract class DiscreteDomain<C extends Comparable> extends Object
A descriptor for a discreteComparable
domain such as allInteger
instances. A discrete domain is one that supports the three basic operations:next(C)
,previous(C)
anddistance(C, C)
, according to their specifications. The methodsminValue()
andmaxValue()
should also be overridden for bounded types.A discrete domain always represents the entire set of values of its type; it cannot represent partial domains such as "prime integers" or "strings of length 5."
See the Guava User Guide section on
DiscreteDomain
.- Since:
- 10.0
-
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description static DiscreteDomain<BigInteger>
bigIntegers()
Returns the discrete domain for values of typeBigInteger
.abstract long
distance(C start, C end)
Returns a signed value indicating how many nested invocations ofnext(C)
(if positive) orprevious(C)
(if negative) are needed to reachend
starting fromstart
.static DiscreteDomain<Integer>
integers()
Returns the discrete domain for values of typeInteger
.static DiscreteDomain<Long>
longs()
Returns the discrete domain for values of typeLong
.C
maxValue()
Returns the maximum value of typeC
, if it has one.C
minValue()
Returns the minimum value of typeC
, if it has one.abstract C
next(C value)
Returns the unique least value of typeC
that is greater thanvalue
, ornull
if none exists.abstract C
previous(C value)
Returns the unique greatest value of typeC
that is less thanvalue
, ornull
if none exists.
-
-
-
Method Detail
-
integers
public static DiscreteDomain<Integer> integers()
Returns the discrete domain for values of typeInteger
.- Since:
- 14.0 (since 10.0 as
DiscreteDomains.integers()
)
-
longs
public static DiscreteDomain<Long> longs()
Returns the discrete domain for values of typeLong
.- Since:
- 14.0 (since 10.0 as
DiscreteDomains.longs()
)
-
bigIntegers
public static DiscreteDomain<BigInteger> bigIntegers()
Returns the discrete domain for values of typeBigInteger
.- Since:
- 15.0
-
next
public abstract C next(C value)
Returns the unique least value of typeC
that is greater thanvalue
, ornull
if none exists. Inverse operation toprevious(C)
.- Parameters:
value
- any value of typeC
- Returns:
- the least value greater than
value
, ornull
ifvalue
ismaxValue()
-
previous
public abstract C previous(C value)
Returns the unique greatest value of typeC
that is less thanvalue
, ornull
if none exists. Inverse operation tonext(C)
.- Parameters:
value
- any value of typeC
- Returns:
- the greatest value less than
value
, ornull
ifvalue
isminValue()
-
distance
public abstract long distance(C start, C end)
Returns a signed value indicating how many nested invocations ofnext(C)
(if positive) orprevious(C)
(if negative) are needed to reachend
starting fromstart
. For example, ifend = next(next(next(start)))
, thendistance(start, end) == 3
anddistance(end, start) == -3
. As well,distance(a, a)
is always zero.Note that this function is necessarily well-defined for any discrete type.
- Returns:
- the distance as described above, or
Long.MIN_VALUE
orLong.MAX_VALUE
if the distance is too small or too large, respectively.
-
minValue
public C minValue()
Returns the minimum value of typeC
, if it has one. The minimum value is the unique value for whichComparable.compareTo(Object)
never returns a positive value for any input of typeC
.The default implementation throws
NoSuchElementException
.- Returns:
- the minimum value of type
C
; never null - Throws:
NoSuchElementException
- if the type has no (practical) minimum value; for example,BigInteger
-
maxValue
public C maxValue()
Returns the maximum value of typeC
, if it has one. The maximum value is the unique value for whichComparable.compareTo(Object)
never returns a negative value for any input of typeC
.The default implementation throws
NoSuchElementException
.- Returns:
- the maximum value of type
C
; never null - Throws:
NoSuchElementException
- if the type has no (practical) maximum value; for example,BigInteger
-
-