|
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.LongRange
public final class LongRange
Immutable encapsulation of a range of long integer values as expressed by a
starting Long and an ending Long.
Either the starting value or the ending value or both can be null.
If you need a value span with a smaller range, see IntegerRange.
If you need a value span that includes fractional information,
see DecimalRange.
The Long class itself and the utility
NumberTools have handy utilities for formatting and parsing
Long instances to and from more human-readable
Strings.
IntegerRange,
DecimalRange,
Long,
NumberTools,
Serialized Form| Field Summary | |
|---|---|
static LongRange |
BOTH_OPEN
This LongRange has both an undefined start and an undefined end. |
static Comparator<LongRange> |
HIGHEST_FIRST_COMPARATOR
Compares two ranges placing ranges that are considered "highest" first. |
static Comparator<LongRange> |
LOWEST_FIRST_COMPARATOR
Compares two ranges placing ranges that are considered "lowest" first. |
static LongRange |
MIN_TO_MAX_LONG
This LongRange runs from Long.MIN_VALUE
to Long.MAX_VALUE. |
static LongRange |
NEGATIVE
This LongRange covers all negative values with an undefined start and an end of "-1". |
static LongRange |
NON_NEGATIVE
This LongRange covers all non-negative values with a start of "0" and an undefined end. |
static LongRange |
NON_POSITIVE
This LongRange covers all non-positive values with an undefined start and an end of "0". |
static Long |
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 LongRange |
POSITIVE
This LongRange covers all positive values with a start of "1" and an undefined end. |
| Constructor Summary | |
|---|---|
LongRange(long start,
long end)
Creates a new instance with the specified start and end values. |
|
LongRange(Long start,
Long end)
Creates a new instance with the specified start and end values. |
|
LongRange(String start,
String end)
Creates a new instance with the specified start and end values. |
|
LongRange(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(LongRange otherRange)
Compares this instance to otherRange as defined by LOWEST_FIRST_COMPARATOR. |
boolean |
contains(long value)
Returns true if the specified long falls within this range (inclusive of both endpoints). |
boolean |
contains(Long value)
Returns true if the specified Long falls within this range (inclusive of both endpoints). |
static LongRange |
createWithOpenEnd(Long start)
Creates a new instance with an open end and the specified start value. |
static LongRange |
createWithOpenStart(Long end)
Creates a new instance with an open start and the specified end value. |
boolean |
equals(LongRange otherLong)
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. |
long |
forceIntoRange(long value)
Forces the specified long into this range. |
Long |
forceIntoRange(Long value)
Forces the specified Long into this range. |
Long |
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. |
Long |
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()
|
LongRange |
setEnd(long newEnd)
Returns a new instance with the specified newEnd value and this instance's start value. |
LongRange |
setEnd(Long newEnd)
Returns a new instance with the specified newEnd value and this instance's start value. |
LongRange |
setEnd(String newEnd)
Returns a new instance with the specified newEnd value and this instance's start value. |
LongRange |
setEnd(Value newEnd)
Returns a new instance with the specified newEnd value and this instance's start value. |
LongRange |
setStart(long newStart)
Returns a new instance with the specified newStart value and this instance's end value. |
LongRange |
setStart(Long newStart)
Returns a new instance with the specified newStart value and this instance's end value. |
LongRange |
setStart(String newStart)
Returns a new instance with the specified newStart value and this instance's end value. |
LongRange |
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 Long OPEN
public static final LongRange BOTH_OPEN
MIN_TO_MAX_LONG, this range has
an undefined start and an undefined end.
This is a shareable instance as all instances
of LongRange 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 LongRange has both an undefined start and
an undefined end.
public static final LongRange MIN_TO_MAX_LONG
Long.MIN_VALUE
to Long.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 LongRange 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 LongRange POSITIVE
LongRange are immutable.
NEGATIVE,
NON_NEGATIVE,
NON_POSITIVEpublic static final LongRange NON_NEGATIVE
LongRange are immutable.
POSITIVE,
NEGATIVE,
NON_POSITIVEpublic static final LongRange NON_POSITIVE
LongRange are immutable.
POSITIVE,
NEGATIVE,
NON_NEGATIVEpublic static final LongRange NEGATIVE
LongRange are immutable.
POSITIVE,
NON_NEGATIVE,
NON_POSITIVEpublic static final Comparator<LongRange> 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<LongRange> 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 LongRange(Long start,
Long 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.LongRange(Value, Value),
LongRange(String, String)
public LongRange(long start,
long end)
throws IllegalArgumentException
LongRange(Long, Long) 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.LongRange(Long, Long),
LongRange(Value, Value),
LongRange(String, String)
public LongRange(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 Long
(see NumberTools.parseLongLenient(String)).LongRange(Long, Long),
LongRange(long, long),
LongRange(Value, Value),
NumberTools.parseLongLenient(String)
public LongRange(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 Long (see Value.getLongNumberOrNull()).LongRange(Long, Long),
LongRange(long, long),
LongRange(String, String),
Value.getLongNumberOrNull()| Method Detail |
|---|
public static LongRange createWithOpenStart(Long end)
end - the end of the value range.public static LongRange createWithOpenEnd(Long start)
start - the start of the value range.
public LongRange setStart(Long 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.LongRange(Long, Long)
public LongRange setStart(long newStart)
throws IllegalArgumentException
newStart - the new start value for the new instance.
IllegalArgumentException - if the start value
is greater than the end value.LongRange(long, long)
public LongRange 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.LongRange(String, String)
public LongRange 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.LongRange(Value, Value)
public LongRange setEnd(Long newEnd)
throws IllegalArgumentException
newEnd - the new end value for the new instance or null.
IllegalArgumentException - if the start comes after the end.LongRange(Long, Long)
public LongRange setEnd(long newEnd)
throws IllegalArgumentException
newEnd - the new end value for the new instance.
IllegalArgumentException - if the start comes after the end.LongRange(long, long)
public LongRange 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.LongRange(String, String)
public LongRange 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.LongRange(Value, Value)public boolean hasDefinedStart()
getStart()public Long 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 Long getEnd()
OPEN
(null) is returned.
hasDefinedEnd()public String getEndString()
hasDefinedEnd(),
getEnd(),
getEndValue()public Value getEndValue()
hasDefinedEnd(),
getEnd(),
getEndString()public boolean contains(Long value)
public boolean contains(long value)
public Long forceIntoRange(Long value)
throws IllegalArgumentException
contains(Long)), 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 long forceIntoRange(long value)
contains(long)), 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(LongRange otherRange)
throws IllegalArgumentException
LOWEST_FIRST_COMPARATOR.
compareTo in interface Comparable<LongRange>IllegalArgumentException - if null is passed.public boolean equals(LongRange otherLong)
public boolean equals(Object obj)
equals in class Objectpublic int hashCode()
hashCode in class Objectpublic String toString()
toString in class Objectpublic 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 | |||||||||