Class DiscreteDomain<C extends Comparable>
Comparable domain such as all Integer
instances. A discrete domain is one that supports the three basic operations: next(C),
previous(C) and distance(C, C), according to their specifications. The methods minValue() and maxValue() 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
- Author:
- Kevin Bourrillion
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic DiscreteDomain<BigInteger> Returns the discrete domain for values of typeBigInteger.abstract longReturns a signed value indicating how many nested invocations ofnext(C)(if positive) orprevious(C)(if negative) are needed to reachendstarting 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.maxValue()Returns the maximum value of typeC, if it has one.minValue()Returns the minimum value of typeC, if it has one.Returns the unique least value of typeCthat is greater thanvalue, ornullif none exists.Returns the unique greatest value of typeCthat is less thanvalue, ornullif none exists.
-
Constructor Details
-
DiscreteDomain
protected DiscreteDomain()Constructor for use by subclasses.
-
-
Method Details
-
integers
Returns the discrete domain for values of typeInteger.This method always returns the same object. That object is serializable; deserializing it results in the same object too.
- Since:
- 14.0 (since 10.0 as
DiscreteDomains.integers())
-
longs
Returns the discrete domain for values of typeLong.This method always returns the same object. That object is serializable; deserializing it results in the same object too.
- Since:
- 14.0 (since 10.0 as
DiscreteDomains.longs())
-
bigIntegers
Returns the discrete domain for values of typeBigInteger.This method always returns the same object. That object is serializable; deserializing it results in the same object too.
- Since:
- 15.0
-
next
Returns the unique least value of typeCthat is greater thanvalue, ornullif none exists. Inverse operation toprevious(C).- Parameters:
value- any value of typeC- Returns:
- the least value greater than
value, ornullifvalueismaxValue()
-
previous
-
distance
Returns a signed value indicating how many nested invocations ofnext(C)(if positive) orprevious(C)(if negative) are needed to reachendstarting fromstart. For example, ifend = next(next(next(start))), thendistance(start, end) == 3anddistance(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_VALUEorLong.MAX_VALUEif the distance is too small or too large, respectively.
-
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
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
-