|
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.DecimalRange
public final class DecimalRange
Immutable encapsulation of a range of decimal values as expressed by a
starting BigDecimal and an ending BigDecimal.
Either the starting value or the ending value or both can be null.
If you need a value span that does not need fractional information,
see IntegerRange.
The BigDecimal class itself and the utility
DecimalTools have handy utilities for formatting and parsing
BigDecimal instances to and from more human-readable
Strings.
DecimalTools,
BigDecimal,
IntegerRange,
Serialized Form| Field Summary | |
|---|---|
static DecimalRange |
BOTH_OPEN
This DecimalRange has both an undefined start and an undefined end. |
static Comparator<DecimalRange> |
HIGHEST_FIRST_COMPARATOR
Compares two ranges placing ranges that are considered "highest" first. |
static Comparator<DecimalRange> |
LOWEST_FIRST_COMPARATOR
Compares two ranges placing ranges that are considered "lowest" first. |
static DecimalRange |
NON_NEGATIVE
This DecimalRange covers all non-negative values with a start of "0.0" and an undefined end. |
static DecimalRange |
NON_POSITIVE
This DecimalRange covers all non-positive values with an undefined start and an end of "0.0". |
static BigDecimal |
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). |
| Constructor Summary | |
|---|---|
DecimalRange(BigDecimal start,
BigDecimal end)
Creates a new instance with the specified start and end values. |
|
DecimalRange(String start,
String end)
Creates a new instance with the specified start and end values. |
|
DecimalRange(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(DecimalRange otherRange)
Compares this instance to otherRange as defined by LOWEST_FIRST_COMPARATOR. |
boolean |
contains(BigDecimal value)
Returns true if the specified BigDecimal falls within this range (inclusive of both endpoints). |
static DecimalRange |
createWithOpenEnd(BigDecimal start)
Creates a new instance with an open end and the specified start value. |
static DecimalRange |
createWithOpenStart(BigDecimal end)
Creates a new instance with an open start and the specified end value. |
boolean |
equals(DecimalRange otherBigDecimal)
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. |
BigDecimal |
forceIntoRange(BigDecimal value)
Forces the specified BigDecimal into this range. |
BigDecimal |
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. |
BigDecimal |
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()
|
DecimalRange |
setEnd(BigDecimal newEnd)
Returns a new instance with the specified newEnd value and this instance's start value. |
DecimalRange |
setEnd(String newEnd)
Returns a new instance with the specified newEnd value and this instance's start value. |
DecimalRange |
setEnd(Value newEnd)
Returns a new instance with the specified newEnd value and this instance's start value. |
DecimalRange |
setStart(BigDecimal newStart)
Returns a new instance with the specified newStart value and this instance's end value. |
DecimalRange |
setStart(String newStart)
Returns a new instance with the specified newStart value and this instance's end value. |
DecimalRange |
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 BigDecimal OPEN
public static final DecimalRange BOTH_OPEN
DecimalRange 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 DecimalRange has both an undefined start and
and undefined end.
public static final DecimalRange NON_NEGATIVE
DecimalRange are immutable.
public static final DecimalRange NON_POSITIVE
DecimalRange are immutable.
public static final Comparator<DecimalRange> 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<DecimalRange> 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 DecimalRange(BigDecimal start,
BigDecimal 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.DecimalRange(Value, Value),
DecimalRange(String, String)
public DecimalRange(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 BigDecimal
(see DecimalTools.parseBigDecimal(String)).DecimalRange(BigDecimal, BigDecimal),
DecimalRange(Value, Value),
DecimalTools.parseBigDecimal(String)
public DecimalRange(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 BigDecimal (see Value.getBigDecimalOrNull()).DecimalRange(BigDecimal, BigDecimal),
DecimalRange(String, String),
Value.getBigDecimalOrNull()| Method Detail |
|---|
public static DecimalRange createWithOpenStart(BigDecimal end)
end - the end of the value range.public static DecimalRange createWithOpenEnd(BigDecimal start)
start - the start of the value range.
public DecimalRange setStart(BigDecimal 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.DecimalRange(BigDecimal, BigDecimal)
public DecimalRange 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.DecimalRange(String, String)
public DecimalRange 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.DecimalRange(Value, Value)
public DecimalRange setEnd(BigDecimal newEnd)
throws IllegalArgumentException
newEnd - the new end value for the new instance or null.
IllegalArgumentException - if the start comes after the end.DecimalRange(BigDecimal, BigDecimal)
public DecimalRange 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.DecimalRange(String, String)
public DecimalRange 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.DecimalRange(Value, Value)public boolean hasDefinedStart()
getStart()public BigDecimal 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 BigDecimal getEnd()
OPEN
(null) is returned.
hasDefinedEnd()public String getEndString()
hasDefinedEnd(),
getEnd(),
getEndValue()public Value getEndValue()
hasDefinedEnd(),
getEnd(),
getEndString()public boolean contains(BigDecimal value)
public BigDecimal forceIntoRange(BigDecimal value)
throws IllegalArgumentException
contains(BigDecimal)), 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 compareTo(DecimalRange otherRange)
throws IllegalArgumentException
LOWEST_FIRST_COMPARATOR.
compareTo in interface Comparable<DecimalRange>IllegalArgumentException - if null is passed.public boolean equals(DecimalRange otherBigDecimal)
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 | |||||||||