org.datavec.dataframe.util.collections.IntegerDomain Maven / Gradle / Ivy
Show all versions of datavec-dataframe Show documentation
package org.datavec.dataframe.util.collections;
/**
* A descriptor for a discrete {@code Comparable} domain such as all
* {@link Integer} instances. A discrete domain is one that supports the three basic
* operations: {@link #next}, {@link #previous} and {@link #distance}, according
* to their specifications. The methods {@link #minValue} and {@link #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
* {@code IntegerDomain}.
*
* @author Kevin Bourrillion
* @since 10.0
*/
final class IntegerDomain {
private static final IntegerDomain INSTANCE = new IntegerDomain();
/**
* Returns the discrete domain for values of type {@code Integer}.
*
* @since 14.0 (since 10.0 as {@code DiscreteDomains.integers()})
*/
public static IntegerDomain integers() {
return INSTANCE;
}
public Integer next(Integer value) {
int i = value;
return (i == Integer.MAX_VALUE) ? null : i + 1;
}
public Integer previous(Integer value) {
int i = value;
return (i == Integer.MIN_VALUE) ? null : i - 1;
}
public long distance(Integer start, Integer end) {
return (long) end - start;
}
public Integer minValue() {
return Integer.MIN_VALUE;
}
public Integer maxValue() {
return Integer.MAX_VALUE;
}
private Object readResolve() {
return INSTANCE;
}
@Override
public String toString() {
return "IntegerDomain.integers()";
}
}