Top Description Inners Fields Constructors Methods
com.google.common.collect

public abstract Class DiscreteDomain<C extends java.lang.Comparable<T>>

extends Object
Class Inheritance
Known Direct Subclasses
com.google.common.collect.DiscreteDomain.IntegerDomain, com.google.common.collect.DiscreteDomain.LongDomain, com.google.common.collect.DiscreteDomain.BigIntegerDomain
Annotations
@GwtCompatible
@ElementTypesAreNonnullByDefault
Static Imports
com.google.common.base.Preconditions.checkArgument, com.google.common.collect.CollectPreconditions.checkNonnegative

A descriptor for a discrete Comparable domain such as all Integer instances. A discrete domain is one that supports the three basic operations: next, previous and distance, 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.

Author
Kevin Bourrillion
Since
10.0

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class
private static class
private static class

Field Summary

Modifier and TypeField and Description
pack-priv final boolean

Constructor Summary

AccessConstructor and Description
protected
DiscreteDomain()

Constructor for use by subclasses.

private
DiscreteDomain(boolean supportsFastOffset)

Private constructor for built-in DiscreteDomains supporting fast offset.

Method Summary

Modifier and TypeMethod and Description
public static DiscreteDomain<BigInteger>
bigIntegers()

Returns the discrete domain for values of type BigInteger.

public abstract long

Returns:

the distance as described above, or Long#MIN_VALUE or Long#MAX_VALUE if the distance is too small or too large, respectively.
distance
(C start, C end)

Returns a signed value indicating how many nested invocations of next (if positive) or previous (if negative) are needed to reach end starting from start.

public static DiscreteDomain<Integer>
integers()

Returns the discrete domain for values of type Integer.

public static DiscreteDomain<Long>
longs()

Returns the discrete domain for values of type Long.

public C

Returns:

the maximum value of type C; never null
maxValue
()

Returns the maximum value of type C, if it has one.

public C

Returns:

the minimum value of type C; never null
minValue
()

Returns the minimum value of type C, if it has one.

public abstract C

Returns:

the least value greater than value, or null if value is maxValue()
next
(C
any value of type C
value
)

Returns the unique least value of type C that is greater than value, or null if none exists.

pack-priv C
offset(C origin, long distance)

Returns, conceptually, "origin + distance", or equivalently, the result of calling next on origin distance times.

public abstract C

Returns:

the greatest value less than value, or null if value is minValue()
previous
(C
any value of type C
value
)

Returns the unique greatest value of type C that is less than value, or null if none exists.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

supportsFastOffsetback to summary
pack-priv final boolean supportsFastOffset

Constructor Detail

DiscreteDomainback to summary
protected DiscreteDomain()

Constructor for use by subclasses.

DiscreteDomainback to summary
private DiscreteDomain(boolean supportsFastOffset)

Private constructor for built-in DiscreteDomains supporting fast offset.

Method Detail

bigIntegersback to summary
public static DiscreteDomain<BigInteger> bigIntegers()

Returns the discrete domain for values of type BigInteger.

This method always returns the same object. That object is serializable; deserializing it results in the same object too.

Since
15.0
distanceback to summary
public abstract long distance(C start, C end)

Returns a signed value indicating how many nested invocations of next (if positive) or previous (if negative) are needed to reach end starting from start. For example, if end = next(next(next(start))), then distance(start, end) == 3 and distance(end, start) == -3. As well, distance(a, a) is always zero.

Note that this function is necessarily well-defined for any discrete type.

Returns:long

the distance as described above, or Long#MIN_VALUE or Long#MAX_VALUE if the distance is too small or too large, respectively.

integersback to summary
public static DiscreteDomain<Integer> integers()

Returns the discrete domain for values of type Integer.

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())
longsback to summary
public static DiscreteDomain<Long> longs()

Returns the discrete domain for values of type Long.

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())
maxValueback to summary
public C maxValue()

Returns the maximum value of type C, if it has one. The maximum value is the unique value for which Comparable#compareTo(Object) never returns a negative value for any input of type C.

The default implementation throws NoSuchElementException.

Returns:C

the maximum value of type C; never null

Annotations
@CanIgnoreReturnValue
Exceptions
NoSuchElementException:
if the type has no (practical) maximum value; for example, java.math.BigInteger
minValueback to summary
public C minValue()

Returns the minimum value of type C, if it has one. The minimum value is the unique value for which Comparable#compareTo(Object) never returns a positive value for any input of type C.

The default implementation throws NoSuchElementException.

Returns:C

the minimum value of type C; never null

Annotations
@CanIgnoreReturnValue
Exceptions
NoSuchElementException:
if the type has no (practical) minimum value; for example, java.math.BigInteger
nextback to summary
public abstract C next(C value)

Returns the unique least value of type C that is greater than value, or null if none exists. Inverse operation to previous.

Parameters
value:C

any value of type C

Returns:C

the least value greater than value, or null if value is maxValue()

Annotations
@CheckForNull
offsetback to summary
pack-priv C offset(C origin, long distance)

Returns, conceptually, "origin + distance", or equivalently, the result of calling next on origin distance times.

previousback to summary
public abstract C previous(C value)

Returns the unique greatest value of type C that is less than value, or null if none exists. Inverse operation to next.

Parameters
value:C

any value of type C

Returns:C

the greatest value less than value, or null if value is minValue()

Annotations
@CheckForNull
com.google.common.collect back to summary

private final Class DiscreteDomain.BigIntegerDomain

extends DiscreteDomain<BigInteger>
implements Serializable
Class Inheritance
All Implemented Interfaces
java.io.Serializable

Field Summary

Modifier and TypeField and Description
private static final DiscreteDomain.BigIntegerDomain
private static final BigInteger
private static final BigInteger
private static final long
Inherited from com.google.common.collect.DiscreteDomain:
supportsFastOffset

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
public long
distance(BigInteger start, BigInteger end)

Implements abstract com.google.common.collect.DiscreteDomain.distance.

Returns a signed value indicating how many nested invocations of next (if positive) or previous (if negative) are needed to reach end starting from start.
public BigInteger
next(BigInteger
any value of type C
value
)

Implements abstract com.google.common.collect.DiscreteDomain.next.

Returns the unique least value of type C that is greater than value, or null if none exists.
pack-priv BigInteger
offset(BigInteger origin, long distance)

Overrides com.google.common.collect.DiscreteDomain.offset.

Returns, conceptually, "origin + distance", or equivalently, the result of calling next on origin distance times.
public BigInteger
previous(BigInteger
any value of type C
value
)

Implements abstract com.google.common.collect.DiscreteDomain.previous.

Returns the unique greatest value of type C that is less than value, or null if none exists.
private Object
public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.
Inherited from com.google.common.collect.DiscreteDomain:
bigIntegersintegerslongsmaxValueminValue

Field Detail

INSTANCEback to summary
private static final DiscreteDomain.BigIntegerDomain INSTANCE
MAX_LONGback to summary
private static final BigInteger MAX_LONG
MIN_LONGback to summary
private static final BigInteger MIN_LONG
serialVersionUIDback to summary
private static final long serialVersionUID

Constructor Detail

BigIntegerDomainback to summary
pack-priv BigIntegerDomain()

Method Detail

distanceback to summary
public long distance(BigInteger start, BigInteger end)

Implements abstract com.google.common.collect.DiscreteDomain.distance.

Doc from com.google.common.collect.DiscreteDomain.distance.

Returns a signed value indicating how many nested invocations of next (if positive) or previous (if negative) are needed to reach end starting from start. For example, if end = next(next(next(start))), then distance(start, end) == 3 and distance(end, start) == -3. As well, distance(a, a) is always zero.

Note that this function is necessarily well-defined for any discrete type.

Returns:long

the distance as described above, or Long#MIN_VALUE or Long#MAX_VALUE if the distance is too small or too large, respectively.

Annotations
@Override
nextback to summary
public BigInteger next(BigInteger value)

Implements abstract com.google.common.collect.DiscreteDomain.next.

Doc from com.google.common.collect.DiscreteDomain.next.

Returns the unique least value of type C that is greater than value, or null if none exists. Inverse operation to previous.

Parameters
value:BigInteger

any value of type C

Returns:BigInteger

the least value greater than value, or null if value is maxValue()

Annotations
@Override
offsetback to summary
pack-priv BigInteger offset(BigInteger origin, long distance)

Overrides com.google.common.collect.DiscreteDomain.offset.

Doc from com.google.common.collect.DiscreteDomain.offset.

Returns, conceptually, "origin + distance", or equivalently, the result of calling next on origin distance times.

Annotations
@Override
previousback to summary
public BigInteger previous(BigInteger value)

Implements abstract com.google.common.collect.DiscreteDomain.previous.

Doc from com.google.common.collect.DiscreteDomain.previous.

Returns the unique greatest value of type C that is less than value, or null if none exists. Inverse operation to next.

Parameters
value:BigInteger

any value of type C

Returns:BigInteger

the greatest value less than value, or null if value is minValue()

Annotations
@Override
readResolveback to summary
private Object readResolve()
toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object.

Returns:String

a string representation of the object.

Annotations
@Override
com.google.common.collect back to summary

private final Class DiscreteDomain.IntegerDomain

extends DiscreteDomain<Integer>
implements Serializable
Class Inheritance
All Implemented Interfaces
java.io.Serializable

Field Summary

Modifier and TypeField and Description
private static final DiscreteDomain.IntegerDomain
private static final long
Inherited from com.google.common.collect.DiscreteDomain:
supportsFastOffset

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
public long
distance(Integer start, Integer end)

Implements abstract com.google.common.collect.DiscreteDomain.distance.

Returns a signed value indicating how many nested invocations of next (if positive) or previous (if negative) are needed to reach end starting from start.
public Integer
maxValue()

Overrides com.google.common.collect.DiscreteDomain.maxValue.

Returns the maximum value of type C, if it has one.
public Integer
minValue()

Overrides com.google.common.collect.DiscreteDomain.minValue.

Returns the minimum value of type C, if it has one.
public Integer
next(Integer
any value of type C
value
)

Implements abstract com.google.common.collect.DiscreteDomain.next.

Returns the unique least value of type C that is greater than value, or null if none exists.
pack-priv Integer
offset(Integer origin, long distance)

Overrides com.google.common.collect.DiscreteDomain.offset.

Returns, conceptually, "origin + distance", or equivalently, the result of calling next on origin distance times.
public Integer
previous(Integer
any value of type C
value
)

Implements abstract com.google.common.collect.DiscreteDomain.previous.

Returns the unique greatest value of type C that is less than value, or null if none exists.
private Object
public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.
Inherited from com.google.common.collect.DiscreteDomain:
bigIntegersintegerslongs

Field Detail

INSTANCEback to summary
private static final DiscreteDomain.IntegerDomain INSTANCE
serialVersionUIDback to summary
private static final long serialVersionUID

Constructor Detail

IntegerDomainback to summary
pack-priv IntegerDomain()

Method Detail

distanceback to summary
public long distance(Integer start, Integer end)

Implements abstract com.google.common.collect.DiscreteDomain.distance.

Doc from com.google.common.collect.DiscreteDomain.distance.

Returns a signed value indicating how many nested invocations of next (if positive) or previous (if negative) are needed to reach end starting from start. For example, if end = next(next(next(start))), then distance(start, end) == 3 and distance(end, start) == -3. As well, distance(a, a) is always zero.

Note that this function is necessarily well-defined for any discrete type.

Returns:long

the distance as described above, or Long#MIN_VALUE or Long#MAX_VALUE if the distance is too small or too large, respectively.

Annotations
@Override
maxValueback to summary
public Integer maxValue()

Overrides com.google.common.collect.DiscreteDomain.maxValue.

Doc from com.google.common.collect.DiscreteDomain.maxValue.

Returns the maximum value of type C, if it has one. The maximum value is the unique value for which Comparable#compareTo(Object) never returns a negative value for any input of type C.

The default implementation throws NoSuchElementException.

Returns:Integer

the maximum value of type C; never null

Annotations
@Override
minValueback to summary
public Integer minValue()

Overrides com.google.common.collect.DiscreteDomain.minValue.

Doc from com.google.common.collect.DiscreteDomain.minValue.

Returns the minimum value of type C, if it has one. The minimum value is the unique value for which Comparable#compareTo(Object) never returns a positive value for any input of type C.

The default implementation throws NoSuchElementException.

Returns:Integer

the minimum value of type C; never null

Annotations
@Override
nextback to summary
public Integer next(Integer value)

Implements abstract com.google.common.collect.DiscreteDomain.next.

Doc from com.google.common.collect.DiscreteDomain.next.

Returns the unique least value of type C that is greater than value, or null if none exists. Inverse operation to previous.

Parameters
value:Integer

any value of type C

Returns:Integer

the least value greater than value, or null if value is maxValue()

Annotations
@Override
@CheckForNull
offsetback to summary
pack-priv Integer offset(Integer origin, long distance)

Overrides com.google.common.collect.DiscreteDomain.offset.

Doc from com.google.common.collect.DiscreteDomain.offset.

Returns, conceptually, "origin + distance", or equivalently, the result of calling next on origin distance times.

Annotations
@Override
previousback to summary
public Integer previous(Integer value)

Implements abstract com.google.common.collect.DiscreteDomain.previous.

Doc from com.google.common.collect.DiscreteDomain.previous.

Returns the unique greatest value of type C that is less than value, or null if none exists. Inverse operation to next.

Parameters
value:Integer

any value of type C

Returns:Integer

the greatest value less than value, or null if value is minValue()

Annotations
@Override
@CheckForNull
readResolveback to summary
private Object readResolve()
toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object.

Returns:String

a string representation of the object.

Annotations
@Override
com.google.common.collect back to summary

private final Class DiscreteDomain.LongDomain

extends DiscreteDomain<Long>
implements Serializable
Class Inheritance
All Implemented Interfaces
java.io.Serializable

Field Summary

Modifier and TypeField and Description
private static final DiscreteDomain.LongDomain
private static final long
Inherited from com.google.common.collect.DiscreteDomain:
supportsFastOffset

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
public long
distance(Long start, Long end)

Implements abstract com.google.common.collect.DiscreteDomain.distance.

Returns a signed value indicating how many nested invocations of next (if positive) or previous (if negative) are needed to reach end starting from start.
public Long
maxValue()

Overrides com.google.common.collect.DiscreteDomain.maxValue.

Returns the maximum value of type C, if it has one.
public Long
minValue()

Overrides com.google.common.collect.DiscreteDomain.minValue.

Returns the minimum value of type C, if it has one.
public Long
next(Long
any value of type C
value
)

Implements abstract com.google.common.collect.DiscreteDomain.next.

Returns the unique least value of type C that is greater than value, or null if none exists.
pack-priv Long
offset(Long origin, long distance)

Overrides com.google.common.collect.DiscreteDomain.offset.

Returns, conceptually, "origin + distance", or equivalently, the result of calling next on origin distance times.
public Long
previous(Long
any value of type C
value
)

Implements abstract com.google.common.collect.DiscreteDomain.previous.

Returns the unique greatest value of type C that is less than value, or null if none exists.
private Object
public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.
Inherited from com.google.common.collect.DiscreteDomain:
bigIntegersintegerslongs

Field Detail

INSTANCEback to summary
private static final DiscreteDomain.LongDomain INSTANCE
serialVersionUIDback to summary
private static final long serialVersionUID

Constructor Detail

LongDomainback to summary
pack-priv LongDomain()

Method Detail

distanceback to summary
public long distance(Long start, Long end)

Implements abstract com.google.common.collect.DiscreteDomain.distance.

Doc from com.google.common.collect.DiscreteDomain.distance.

Returns a signed value indicating how many nested invocations of next (if positive) or previous (if negative) are needed to reach end starting from start. For example, if end = next(next(next(start))), then distance(start, end) == 3 and distance(end, start) == -3. As well, distance(a, a) is always zero.

Note that this function is necessarily well-defined for any discrete type.

Returns:long

the distance as described above, or Long#MIN_VALUE or Long#MAX_VALUE if the distance is too small or too large, respectively.

Annotations
@Override
maxValueback to summary
public Long maxValue()

Overrides com.google.common.collect.DiscreteDomain.maxValue.

Doc from com.google.common.collect.DiscreteDomain.maxValue.

Returns the maximum value of type C, if it has one. The maximum value is the unique value for which Comparable#compareTo(Object) never returns a negative value for any input of type C.

The default implementation throws NoSuchElementException.

Returns:Long

the maximum value of type C; never null

Annotations
@Override
minValueback to summary
public Long minValue()

Overrides com.google.common.collect.DiscreteDomain.minValue.

Doc from com.google.common.collect.DiscreteDomain.minValue.

Returns the minimum value of type C, if it has one. The minimum value is the unique value for which Comparable#compareTo(Object) never returns a positive value for any input of type C.

The default implementation throws NoSuchElementException.

Returns:Long

the minimum value of type C; never null

Annotations
@Override
nextback to summary
public Long next(Long value)

Implements abstract com.google.common.collect.DiscreteDomain.next.

Doc from com.google.common.collect.DiscreteDomain.next.

Returns the unique least value of type C that is greater than value, or null if none exists. Inverse operation to previous.

Parameters
value:Long

any value of type C

Returns:Long

the least value greater than value, or null if value is maxValue()

Annotations
@Override
@CheckForNull
offsetback to summary
pack-priv Long offset(Long origin, long distance)

Overrides com.google.common.collect.DiscreteDomain.offset.

Doc from com.google.common.collect.DiscreteDomain.offset.

Returns, conceptually, "origin + distance", or equivalently, the result of calling next on origin distance times.

Annotations
@Override
previousback to summary
public Long previous(Long value)

Implements abstract com.google.common.collect.DiscreteDomain.previous.

Doc from com.google.common.collect.DiscreteDomain.previous.

Returns the unique greatest value of type C that is less than value, or null if none exists. Inverse operation to next.

Parameters
value:Long

any value of type C

Returns:Long

the greatest value less than value, or null if value is minValue()

Annotations
@Override
@CheckForNull
readResolveback to summary
private Object readResolve()
toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object.

Returns:String

a string representation of the object.

Annotations
@Override