|
ProgramixGenericLib v5.0.1 | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.programix.math.IntegerRange
public final class IntegerRange
Immutable encapsulation of a range of integer values as expressed by a
starting Integer
and an ending Integer
.
If you need a value span with a larger range, see LongRange
.
Either the starting value or the ending value or both can be null.
If you need a value span that includes fractional information,
see DecimalRange
.
The Integer
class itself and the utility
NumberTools
have handy utilities for formatting and parsing
Integer instances to and from more human-readable
Strings.
LongRange
,
DecimalRange
,
Integer
,
NumberTools
,
Serialized FormField Summary | |
---|---|
static IntegerRange |
BOTH_OPEN
This IntegerRange has both an undefined start and an undefined end. |
static Comparator<IntegerRange> |
HIGHEST_FIRST_COMPARATOR
Compares two ranges placing ranges that are considered "highest" first. |
static Comparator<IntegerRange> |
LOWEST_FIRST_COMPARATOR
Compares two ranges placing ranges that are considered "lowest" first. |
static IntegerRange |
MIN_TO_MAX_INT
This IntegerRange runs from Integer.MIN_VALUE
to Integer.MAX_VALUE . |
static IntegerRange |
NEGATIVE
This IntegerRange covers all negative values with an undefined start and an end of "-1". |
static IntegerRange |
NON_NEGATIVE
This IntegerRange covers all non-negative values with a start of "0" and an undefined end. |
static IntegerRange |
NON_POSITIVE
This IntegerRange covers all non-positive values with an undefined start and an end of "0". |
static Integer |
OPEN
This constant can be used to specify that either the start or end of of the range is "open" (that is, it is not defined and can be considered to stretch out to infinity). |
static IntegerRange |
POSITIVE
This IntegerRange covers all positive values with a start of "1" and an undefined end. |
Constructor Summary | |
---|---|
IntegerRange(Integer start,
Integer end)
Creates a new instance with the specified start and end values. |
|
IntegerRange(int start,
int end)
Creates a new instance with the specified start and end values. |
|
IntegerRange(String start,
String end)
Creates a new instance with the specified start and end values. |
|
IntegerRange(Value start,
Value end)
Creates a new instance with the specified start and end values. |
Method Summary | |
---|---|
Object |
clone()
Simply returns a reference to this instance. |
int |
compareTo(IntegerRange otherRange)
Compares this instance to otherRange as defined by LOWEST_FIRST_COMPARATOR . |
boolean |
contains(int value)
Returns true if the specified int falls within this range (inclusive of both endpoints). |
boolean |
contains(Integer value)
Returns true if the specified Integer falls within this range (inclusive of both endpoints). |
static IntegerRange |
createWithOpenEnd(Integer start)
Creates a new instance with an open end and the specified start value. |
static IntegerRange |
createWithOpenStart(Integer end)
Creates a new instance with an open start and the specified end value. |
boolean |
equals(IntegerRange otherInteger)
Returns true if this instance's start and end values exactly match the start and end values of the passed instance. |
boolean |
equals(Object obj)
Returns true if this instance's start and end values exactly match the start and end values of the passed instance. |
int |
forceIntoRange(int value)
Forces the specified int into this range. |
Integer |
forceIntoRange(Integer value)
Forces the specified Integer into this range. |
Integer |
getEnd()
Returns the end of this range. |
String |
getEndString()
Returns the end of this range as a String. |
Value |
getEndValue()
Returns the end of this range as a Value. |
Integer |
getStart()
Returns the start of this range. |
String |
getStartString()
Returns the start of this range as a String. |
Value |
getStartValue()
Returns the start of this range as a Value. |
boolean |
hasDefinedEnd()
Returns true if this range has a defined end value. |
boolean |
hasDefinedStart()
Returns true if this range has a defined start value. |
int |
hashCode()
|
IntegerRange |
setEnd(int newEnd)
Returns a new instance with the specified newEnd value and this instance's start value. |
IntegerRange |
setEnd(Integer newEnd)
Returns a new instance with the specified newEnd value and this instance's start value. |
IntegerRange |
setEnd(String newEnd)
Returns a new instance with the specified newEnd value and this instance's start value. |
IntegerRange |
setEnd(Value newEnd)
Returns a new instance with the specified newEnd value and this instance's start value. |
IntegerRange |
setStart(int newStart)
Returns a new instance with the specified newStart value and this instance's end value. |
IntegerRange |
setStart(Integer newStart)
Returns a new instance with the specified newStart value and this instance's end value. |
IntegerRange |
setStart(String newStart)
Returns a new instance with the specified newStart value and this instance's end value. |
IntegerRange |
setStart(Value newStart)
Returns a new instance with the specified newStart value and this instance's end value. |
String |
toString()
|
Methods inherited from class java.lang.Object |
---|
finalize, getClass, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
public static final Integer OPEN
public static final IntegerRange BOTH_OPEN
MIN_TO_MAX_INT
, this range has
an undefined start and an undefined end.
This is a shareable instance as all instances
of IntegerRange
are immutable. In addition, there is no
need to create any other instances that have both ends open
(although is it permissible to create those instances).
This IntegerRange has both an undefined start and
an undefined end.
MIN_TO_MAX_INT
public static final IntegerRange MIN_TO_MAX_INT
Integer.MIN_VALUE
to Integer.MAX_VALUE
.
Although similar to BOTH_OPEN
, this range has
a defined start and a defined end.
This is a shareable instance as all instances
of IntegerRange
are immutable. In addition, there is no
need to create any other instances that cover this full range
(although is it permissible to create those instances).
public static final IntegerRange POSITIVE
IntegerRange
are immutable.
NEGATIVE
,
NON_NEGATIVE
,
NON_POSITIVE
public static final IntegerRange NON_NEGATIVE
IntegerRange
are immutable.
POSITIVE
,
NEGATIVE
,
NON_POSITIVE
public static final IntegerRange NON_POSITIVE
IntegerRange
are immutable.
POSITIVE
,
NEGATIVE
,
NON_NEGATIVE
public static final IntegerRange NEGATIVE
IntegerRange
are immutable.
POSITIVE
,
NON_NEGATIVE
,
NON_POSITIVE
public static final Comparator<IntegerRange> LOWEST_FIRST_COMPARATOR
Comparator
:
Also see HIGHEST_FIRST_COMPARATOR
as it is not simply
the reverse of this comparator.
For additional permutations, see NullFirstComparator
,
NullLastComparator
, and ReverseComparator
.
public static final Comparator<IntegerRange> HIGHEST_FIRST_COMPARATOR
Comparator
:
Also see LOWEST_FIRST_COMPARATOR
as it is not simply
the reverse of this comparator.
For additional permutations, see NullFirstComparator
,
NullLastComparator
, and ReverseComparator
.
Constructor Detail |
---|
public IntegerRange(Integer start, Integer end) throws IllegalArgumentException
OPEN
(or null)
can be used to indicate that one end or the other is open-ended.
Both the start and the end can be open, and if
you prefer, there is a shared, immutable instance that can be
used instead: BOTH_OPEN
.
start
- the beginning of the value range. Use OPEN
or null to indicate that the range is open-ended and has
no starting value (negative infinity).end
- the ending of the value range. Use OPEN
or null to indicate that the range is open-ended and has
no ending value (positive infinity).
IllegalArgumentException
- if the start value
is greater than the end value.IntegerRange(Value, Value)
,
IntegerRange(String, String)
public IntegerRange(int start, int end) throws IllegalArgumentException
IntegerRange(Integer, Integer)
if
open ends are needed.
start
- the beginning of the value range.end
- the ending of the value range.
IllegalArgumentException
- if the start value
is greater than the end value.IntegerRange(Integer, Integer)
,
IntegerRange(Value, Value)
,
IntegerRange(String, String)
public IntegerRange(String start, String end) throws IllegalArgumentException
empty
string
to indicate that one end or the other (or both) is open-ended.
start
- the beginning of the value range.
Use null or an empty
string
to indicate that the range is open-ended and has no starting value.end
- the ending of the value range.
Use null or an empty
string
to indicate that the range is open-ended and has no end value.
IllegalArgumentException
- if the start value
is greater than the end value.
Or, if one of the String's is not empty and can not be parsed
as a Integer
(see NumberTools.parseIntLenient(String)
).IntegerRange(Integer, Integer)
,
IntegerRange(int, int)
,
IntegerRange(Value, Value)
,
NumberTools.parseIntLenient(String)
public IntegerRange(Value start, Value end) throws IllegalArgumentException
Value
who's isEmpty()
method returns true to indicate that one end or the other
(or both) is open-ended.
start
- the beginning of the value range.
Use null or an empty
Value
to indicate that the range is open-ended and has no starting value.end
- the ending of the value range.
Use null or an empty
Value
to indicate that the range is open-ended and has no ending value.
IllegalArgumentException
- if the start value
is greater than the end value.
Or, if one of the Value's is not empty and can not be parsed
as a Integer (see Value.getIntegerNumberOrNull()
).IntegerRange(Integer, Integer)
,
IntegerRange(int, int)
,
IntegerRange(String, String)
,
Value.getIntegerNumberOrNull()
Method Detail |
---|
public static IntegerRange createWithOpenStart(Integer end)
end
- the end of the value range.public static IntegerRange createWithOpenEnd(Integer start)
start
- the start of the value range.public IntegerRange setStart(Integer newStart) throws IllegalArgumentException
newStart
- the new start value for the new instance or null.
IllegalArgumentException
- if the start value
is greater than the end value.IntegerRange(Integer, Integer)
public IntegerRange setStart(int newStart) throws IllegalArgumentException
newStart
- the new start value for the new instance.
IllegalArgumentException
- if the start value
is greater than the end value.IntegerRange(int, int)
public IntegerRange setStart(String newStart) throws IllegalArgumentException
newStart
- the new start value for the new instance or null
(or empty).
IllegalArgumentException
- if the start comes after the end
or if newStart is not empty and can't be parsed.IntegerRange(String, String)
public IntegerRange setStart(Value newStart) throws IllegalArgumentException
newStart
- the new start value for the new instance or null.
IllegalArgumentException
- if the start comes after the end
or if newStart is not empty and can't be parsed.IntegerRange(Value, Value)
public IntegerRange setEnd(Integer newEnd) throws IllegalArgumentException
newEnd
- the new end value for the new instance or null.
IllegalArgumentException
- if the start comes after the end.IntegerRange(Integer, Integer)
public IntegerRange setEnd(int newEnd) throws IllegalArgumentException
newEnd
- the new end value for the new instance.
IllegalArgumentException
- if the start comes after the end.IntegerRange(int, int)
public IntegerRange setEnd(String newEnd) throws IllegalArgumentException
newEnd
- the new end value for the new instance or null.
IllegalArgumentException
- if the start comes after the end
or if the end is not empty and can't be parsed.IntegerRange(String, String)
public IntegerRange setEnd(Value newEnd) throws IllegalArgumentException
newEnd
- the new end value for the new instance or null.
IllegalArgumentException
- if the start comes after the end
or if the end is not empty and can't be parsed.IntegerRange(Value, Value)
public boolean hasDefinedStart()
getStart()
public Integer getStart()
OPEN
(null) is returned.
hasDefinedStart()
,
getStartString()
,
getStartValue()
public String getStartString()
hasDefinedStart()
,
getStart()
,
getStartValue()
public Value getStartValue()
hasDefinedStart()
,
getStart()
,
getStartString()
public boolean hasDefinedEnd()
getEnd()
public Integer getEnd()
OPEN
(null) is returned.
hasDefinedEnd()
public String getEndString()
hasDefinedEnd()
,
getEnd()
,
getEndValue()
public Value getEndValue()
hasDefinedEnd()
,
getEnd()
,
getEndString()
public boolean contains(Integer value)
public boolean contains(int value)
public Integer forceIntoRange(Integer value) throws IllegalArgumentException
contains(Integer)
), then the passed value
is simply returned (no forcing is necessary).
If the range has a defined start and the specified value
is less than the start, then the start is returned.
If the range has a defined end and the specified value
is greater than the end, then the end is returned.
value
- the value to force into this range.
IllegalArgumentException
- if the specified value is null.public int forceIntoRange(int value)
contains(int)
), then the passed value
is simply returned (no forcing is necessary).
If the range has a defined start and the specified value
is less than the start, then the start is returned.
If the range has a defined end and the specified value
is greater than the end, then the end is returned.
value
- the value to force into this range.
public int compareTo(IntegerRange otherRange) throws IllegalArgumentException
LOWEST_FIRST_COMPARATOR
.
compareTo
in interface Comparable<IntegerRange>
IllegalArgumentException
- if null is passed.public boolean equals(IntegerRange otherInteger)
public boolean equals(Object obj)
equals
in class Object
public int hashCode()
hashCode
in class Object
public String toString()
toString
in class Object
public Object clone()
clone
in class Object
|
ProgramixGenericLib v5.0.1 | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |