maspack.util
Interface Range

All Superinterfaces:
Clonable, java.lang.Cloneable, Scannable
All Known Implementing Classes:
DoubleInterval, EnumRange, FormatRange, IntegerInterval, NameRange, NumericInterval, NumericIntervalRange, RangeBase

public interface Range
extends Scannable, Clonable

An object representing the set of valid values that an object can have.


Field Summary
static java.lang.Class IllegalValue
          Special object to indicate an illegal value,
 
Method Summary
 void intersect(Range r)
          Intersects the set of valid values of this Range with those of another.
 boolean isEmpty()
          Returns true if this range is empty - i.e., if there are no valid values.
 boolean isValid(java.lang.Object obj, StringHolder errMsg)
          Returns true if the specified object is valid for this Range, and false otherwise.
 java.lang.Object makeValid(java.lang.Object obj)
          Projects an object to lie within the range allowed by this Range, if possible.
 
Methods inherited from interface maspack.util.Scannable
isWritable, scan, write
 
Methods inherited from interface maspack.util.Clonable
clone
 

Field Detail

IllegalValue

static final java.lang.Class IllegalValue
Special object to indicate an illegal value,

Method Detail

isValid

boolean isValid(java.lang.Object obj,
                StringHolder errMsg)
Returns true if the specified object is valid for this Range, and false otherwise. If the object is not valid, and errMsg is not null, then errMsg.value should be set to a message describing why the object is not valid.

Parameters:
obj - Object to be testes
errMsg - Optional handle for storing error message
Returns:
true if the object is valid

makeValid

java.lang.Object makeValid(java.lang.Object obj)
Projects an object to lie within the range allowed by this Range, if possible. If 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, IllegalValue should be returned.

In particular, projectToRange(obj) != obj should be a valid indication that the obj is not within range.

Parameters:
obj - object to be projected
Returns:
original obj if within range, or a projected object, or null.

isEmpty

boolean isEmpty()
Returns true if this range is empty - i.e., if there are no valid values. This will typically result from the intersection of two non-overlapping ranges.

Returns:
true if this range has no valid values.

intersect

void intersect(Range r)
Intersects the set of valid values of this Range with those of another. If the resulting intersection is null, then isEmpty() should subsequently return true.

Parameters:
r - range to intersect with.