Class DiscreteDomain<C extends Comparable>
- java.lang.Object
-
- com.google.common.collect.DiscreteDomain<C>
-
@GwtCompatible public abstract class DiscreteDomain<C extends Comparable> extends Object
A descriptor for a discreteComparabledomain such as allIntegerinstances. 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
- Author:
- Kevin Bourrillion
-
-
Constructor Summary
Constructors Modifier Constructor Description protectedDiscreteDomain()Constructor for use by subclasses.
-
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 longdistance(C start, C end)Returns 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.CmaxValue()Returns the maximum value of typeC, if it has one.CminValue()Returns the minimum value of typeC, if it has one.abstract @Nullable Cnext(C value)Returns the unique least value of typeCthat is greater thanvalue, ornullif none exists.abstract @Nullable Cprevious(C value)Returns the unique greatest value of typeCthat is less thanvalue, ornullif none exists.
-
-
-
Constructor Detail
-
DiscreteDomain
protected DiscreteDomain()
Constructor for use by subclasses.
-
-
Method Detail
-
integers
public static DiscreteDomain<Integer> 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
public static DiscreteDomain<Long> 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
public static DiscreteDomain<BigInteger> 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
public abstract @Nullable C next(C value)
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
public abstract @Nullable C previous(C value)
Returns the unique greatest value of typeCthat is less thanvalue, ornullif none exists. Inverse operation tonext(C).- Parameters:
value- any value of typeC- Returns:
- the greatest value less than
value, ornullifvalueisminValue()
-
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 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
@CanIgnoreReturnValue 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
@CanIgnoreReturnValue 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
-
-