Package com.google.common.collect
Class DiscreteDomain.IntegerDomain
- java.lang.Object
-
- com.google.common.collect.DiscreteDomain<java.lang.Integer>
-
- com.google.common.collect.DiscreteDomain.IntegerDomain
-
- All Implemented Interfaces:
java.io.Serializable
- Enclosing class:
- DiscreteDomain<C extends java.lang.Comparable>
private static final class DiscreteDomain.IntegerDomain extends DiscreteDomain<java.lang.Integer> implements java.io.Serializable
-
-
Field Summary
Fields Modifier and Type Field Description private static DiscreteDomain.IntegerDomain
INSTANCE
private static long
serialVersionUID
-
Constructor Summary
Constructors Modifier Constructor Description private
IntegerDomain()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description long
distance(java.lang.Integer start, java.lang.Integer end)
Returns a signed value indicating how many nested invocations ofDiscreteDomain.next(C)
(if positive) orDiscreteDomain.previous(C)
(if negative) are needed to reachend
starting fromstart
.java.lang.Integer
maxValue()
Returns the maximum value of typeC
, if it has one.java.lang.Integer
minValue()
Returns the minimum value of typeC
, if it has one.java.lang.Integer
next(java.lang.Integer value)
Returns the unique least value of typeC
that is greater thanvalue
, ornull
if none exists.java.lang.Integer
previous(java.lang.Integer value)
Returns the unique greatest value of typeC
that is less thanvalue
, ornull
if none exists.private java.lang.Object
readResolve()
java.lang.String
toString()
-
Methods inherited from class com.google.common.collect.DiscreteDomain
bigIntegers, integers, longs
-
-
-
-
Field Detail
-
INSTANCE
private static final DiscreteDomain.IntegerDomain INSTANCE
-
serialVersionUID
private static final long serialVersionUID
- See Also:
- Constant Field Values
-
-
Method Detail
-
next
public java.lang.Integer next(java.lang.Integer value)
Description copied from class:DiscreteDomain
Returns the unique least value of typeC
that is greater thanvalue
, ornull
if none exists. Inverse operation toDiscreteDomain.previous(C)
.- Specified by:
next
in classDiscreteDomain<java.lang.Integer>
- Parameters:
value
- any value of typeC
- Returns:
- the least value greater than
value
, ornull
ifvalue
ismaxValue()
-
previous
public java.lang.Integer previous(java.lang.Integer value)
Description copied from class:DiscreteDomain
Returns the unique greatest value of typeC
that is less thanvalue
, ornull
if none exists. Inverse operation toDiscreteDomain.next(C)
.- Specified by:
previous
in classDiscreteDomain<java.lang.Integer>
- Parameters:
value
- any value of typeC
- Returns:
- the greatest value less than
value
, ornull
ifvalue
isminValue()
-
distance
public long distance(java.lang.Integer start, java.lang.Integer end)
Description copied from class:DiscreteDomain
Returns a signed value indicating how many nested invocations ofDiscreteDomain.next(C)
(if positive) orDiscreteDomain.previous(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.
- Specified by:
distance
in classDiscreteDomain<java.lang.Integer>
- 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 java.lang.Integer minValue()
Description copied from class:DiscreteDomain
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
.- Overrides:
minValue
in classDiscreteDomain<java.lang.Integer>
- Returns:
- the minimum value of type
C
; never null
-
maxValue
public java.lang.Integer maxValue()
Description copied from class:DiscreteDomain
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
.- Overrides:
maxValue
in classDiscreteDomain<java.lang.Integer>
- Returns:
- the maximum value of type
C
; never null
-
readResolve
private java.lang.Object readResolve()
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
-