|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectmaspack.util.RangeBase
maspack.util.NumericInterval
public abstract class NumericInterval
A Range object which inspects a number to make sure it lies within a prescibed interval.
Field Summary |
---|
Fields inherited from interface maspack.util.Range |
---|
IllegalValue |
Constructor Summary | |
---|---|
NumericInterval()
|
Method Summary | |
---|---|
boolean |
canClipToRange(double num)
Returns true if it is possible to clip a number to this range. |
double |
clipToRange(double num)
Clips a number to lie within the interval specified by this NumericRange. |
NumericInterval |
clone()
|
boolean |
contains(NumericInterval rng)
Returns true if the NumericRange r is a subset of this range. |
boolean |
equals(NumericInterval rng)
Returns true if a specified NumericRange is equivalent in value to this one. |
boolean |
equals(java.lang.Object obj)
Returns true if a specified object is a NumericRange equivalent in value to this one. |
double |
getLowerBound()
Returns the lower bound for the interval of this NumericRange. |
double |
getRange()
Returns the upper bound minus the lower bound of this NumericRange |
double |
getUpperBound()
Returns the upper bound for the interval of this NumericRange. |
void |
intersect(Range r)
Intersects the set of valid values of this Range with those of another. |
boolean |
isBounded()
Returns true if this range is bounded; i.e., neither the upper nor the lower bounds are infinite. |
boolean |
isClosed()
Returns true if this interval is closed, which is true if both the lower and upper bounds are closed. |
boolean |
isEmpty()
Returns true if this range is empty - i.e., if there are no valid values. |
boolean |
isLowerBoundClosed()
Returns true if the lower bound for the interval of this NumericRange is closed. |
boolean |
isTypeCompatible(java.lang.Object obj)
Returns true if a specified object is an instance of Number. |
boolean |
isUpperBoundClosed()
Returns true if the upper bound for the interval of this NumericRange is closed. |
boolean |
isValid(java.lang.Object obj,
StringHolder errMsg)
Returns true if the specified object is valid for this Range, and false otherwise. |
double |
makeValid(double val)
|
java.lang.Object |
makeValid(java.lang.Object obj)
Projects an object to lie within the range allowed by this Range, if possible. |
void |
merge(NumericInterval range)
Merges this NumericRange with another, updating the bounds for this range to enclose both values. |
void |
parse(java.lang.String str)
Sets the value of this NumericRange from a string. |
java.lang.Object |
validate(java.lang.Number value,
boolean clip,
StringHolder errMsg)
Validates a numeric object by checking that it lies within this range interval. |
java.lang.Object |
validate(Vector vec,
boolean clip,
StringHolder errMsg)
Validates a vector by checking that its elements lie within this range interval. |
boolean |
withinRange(double num)
Returns true if the specified number lies within the interval specified by this NumericRange. |
boolean |
withinRange(java.lang.Number num)
Returns true if the value of a specified Number object lies within the interval specified by this NumericRange. |
Methods inherited from class maspack.util.RangeBase |
---|
isWritable, scan, setError, write |
Methods inherited from class java.lang.Object |
---|
getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public NumericInterval()
Method Detail |
---|
public boolean isEmpty()
isEmpty
in interface Range
isEmpty
in class RangeBase
public boolean contains(NumericInterval rng)
rng
- Range to check
public void intersect(Range r)
RangeBase
Range.isEmpty()
should subsequently return true
.
intersect
in interface Range
intersect
in class RangeBase
r
- range to intersect with.public boolean isClosed()
public double getLowerBound()
public boolean isLowerBoundClosed()
public double getUpperBound()
public boolean isUpperBoundClosed()
public boolean isBounded()
public double getRange()
public boolean isValid(java.lang.Object obj, StringHolder errMsg)
RangeBase
errMsg
is not null
, then errMsg.value
should
be set to a message describing why the object is not valid.
isValid
in interface Range
isValid
in class RangeBase
obj
- Object to be testeserrMsg
- Optional handle for storing error message
public double makeValid(double val)
public java.lang.Object makeValid(java.lang.Object obj)
obj
is already within the range, then
obj
should be returned unchanged. Otherwise, if it can be
projected to the range, then a new (projected) object should be
returned. Otherwise, if it cannot be projected, Range.IllegalValue
should be returned.
In particular, projectToRange(obj) != obj
should
be a valid indication that the obj
is not within range.
makeValid
in interface Range
makeValid
in class RangeBase
obj
- object to be projected
null
.public boolean withinRange(java.lang.Number num)
num
- Number to be tested
public boolean withinRange(double num)
num
- number to be tested
public double clipToRange(double num)
num
- number to be clipped
public boolean canClipToRange(double num)
public boolean isTypeCompatible(java.lang.Object obj)
obj
- object to test
public void merge(NumericInterval range)
range
- range to merge with this onepublic boolean equals(java.lang.Object obj)
equals
in class java.lang.Object
obj
- object to compare with
public boolean equals(NumericInterval rng)
rng
- numeric range to compare with
rng
is equivalent to this NumericRangepublic void parse(java.lang.String str)
scan
.
str
- string specifying the value of this NumericRangepublic java.lang.Object validate(java.lang.Number value, boolean clip, StringHolder errMsg)
clip
is true
), or the special value
Range.IllegalValue
. In
the latter two cases, an error message will also be returned if the
variable errMsg
is non-null.
value
- numeric object to validateclip
- if true, clip the number to the range if possib;eerrMsg
- if non-null, is used to return an error message if the number is out of
range
public java.lang.Object validate(Vector vec, boolean clip, StringHolder errMsg)
clip
is true
), or the special value
Range.IllegalValue
. In
the latter two cases, an error message will also be returned if the
variable errMsg
is non-null.
vec
- vector to validateclip
- if true, clip the vector to the range if possibleerrMsg
- if non-null, is used to return an error message if one or more elements
are out of range
public NumericInterval clone()
clone
in interface Clonable
clone
in class RangeBase
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |