uavsim.datatypes
Class Interval<_UNIT_ extends I_Unitable<_UNIT_>>

java.lang.Object
  extended by uavsim.datatypes.Interval<_UNIT_>
Type Parameters:
_UNIT_ - - the datatype

public class Interval<_UNIT_ extends I_Unitable<_UNIT_>>
extends java.lang.Object

Defines an interval for any I_Unitable datatype.

Author:
Dan Tappan [29.06.11]

Nested Class Summary
 class Interval.Iterator
          Defines an iterator over the interval.
 
Field Summary
private  _UNIT_ _end
          the end value
private  boolean _isInclusive
          whether the end value is included in the iteration
private  _UNIT_ _start
          the start value
private  _UNIT_ _step
          the step value, if defined; otherwise null
 
Constructor Summary
Interval(_UNIT_ start, _UNIT_ end, _UNIT_ step)
          Creates an interval with a predefined step, meaning any iterator applied to it can use this value or supply one itself.
Interval(_UNIT_ start, _UNIT_ end, _UNIT_ step, boolean isInclusive)
          Creates an interval with a predefined step, meaning any iterator applied to it can use this value or supply one itself.
Interval(_UNIT_ start, _UNIT_ end)
          Creates an interval with no step, meaning any iterator applied to it must supply the step itself.
Interval(_UNIT_ start, _UNIT_ end, boolean isInclusive)
          Creates an interval with no step, meaning any iterator applied to it must supply the step itself.
 
Method Summary
 _UNIT_ clamp(_UNIT_ value)
          Determines whether a value is off the end of the interval.
 ArcMathematical convertToArcMathematical()
          Converts this interval to a arc defined by mathematical angles.
 Interval<_UNIT_> flip()
          Exchanges the start and end values of the interval.
 _UNIT_ getEnd()
          Gets the end value.
 Interval.Iterator getIteratorInstance(_UNIT_ step, boolean isInclusiveRange)
          Generates an iterator with an explicit step, which overrides any provided to the interval.
 Interval.Iterator getIteratorInstance(boolean isInclusiveRange)
          Generates an iterator with the explicit step provided to the interval.
 _UNIT_ getRange()
          Returns the range of the interval as the end minus the start.
 Scaler getScaler(_UNIT_ value)
          Generates a scaler on the interval [0,1] for a value on this interval.
 Scaler getScalerInverse(_UNIT_ value)
          Generates a scaler on the interval [1,0] for a value on this interval.
 _UNIT_ getStart()
          Gets the start value.
 _UNIT_ getStep()
          Gets the step value, if one was was provided; otherwise, this method is illegal.
 double getSubdivisionCount(_UNIT_ divisor)
          Calculates the number of subdivisions in the interval.
 boolean hasStep()
          Returns whether a step value was provided.
 boolean isInclusive()
          Returns whether the end value is considered part of the interval.
 boolean isOffRangeEnd(_UNIT_ value)
          Determines whether a value is off the end of the interval.
 boolean isOffRangeStart(_UNIT_ value)
          Determines whether a value is off the start of the interval.
 boolean isWithinRange(_UNIT_ value)
          Determines whether a value is inclusively on the interval.
 double scale(Scaler scaler)
          Calculates the value on the interval corresponding to a scaler percentage.
 java.lang.String toString()
          
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

_end

private final _UNIT_ extends I_Unitable<_UNIT_> _end
the end value


_isInclusive

private final boolean _isInclusive
whether the end value is included in the iteration


_start

private final _UNIT_ extends I_Unitable<_UNIT_> _start
the start value


_step

private final _UNIT_ extends I_Unitable<_UNIT_> _step
the step value, if defined; otherwise null

Constructor Detail

Interval

public Interval(_UNIT_ start,
                _UNIT_ end,
                _UNIT_ step)
Creates an interval with a predefined step, meaning any iterator applied to it can use this value or supply one itself. The start value may be greater than the end value.

Parameters:
start - - the start value
end - - the end value
step - - the step value, which is included in the iteration

Interval

public Interval(_UNIT_ start,
                _UNIT_ end,
                _UNIT_ step,
                boolean isInclusive)
Creates an interval with a predefined step, meaning any iterator applied to it can use this value or supply one itself. The start value may be greater than the end value.

Parameters:
start - - the start value
end - - the end value
step - - the step value
isInclusive - - whether the end value is included in the iteration

Interval

public Interval(_UNIT_ start,
                _UNIT_ end)
Creates an interval with no step, meaning any iterator applied to it must supply the step itself. The start value may be greater than the end value.

Parameters:
start - - the start value
end - - the end value, which is included in the iteration

Interval

public Interval(_UNIT_ start,
                _UNIT_ end,
                boolean isInclusive)
Creates an interval with no step, meaning any iterator applied to it must supply the step itself. The start value may be greater than the end value.

Parameters:
start - - the start value
end - - the end value
isInclusive - - whether the end value is included in the iteration
Method Detail

clamp

public _UNIT_ clamp(_UNIT_ value)
Determines whether a value is off the end of the interval. xxx does this work for [+1,-1]? zzz

Parameters:
value - - the value
Returns:
the result

convertToArcMathematical

public ArcMathematical convertToArcMathematical()
Converts this interval to a arc defined by mathematical angles. No sanity checking is performed.

Returns:
the arc

flip

public Interval<_UNIT_> flip()
Exchanges the start and end values of the interval. This is not legal if a step was provided because it may not be possible to negate its datatype [zzz??? why not?].

Returns:
the new interval

getEnd

public _UNIT_ getEnd()
Gets the end value.

Returns:
the value

getIteratorInstance

public Interval.Iterator getIteratorInstance(_UNIT_ step,
                                             boolean isInclusiveRange)
Generates an iterator with an explicit step, which overrides any provided to the interval.

Parameters:
step - - the step valuje
isInclusiveRange - - whether to include the end of the interval in the iteration
Returns:
the iterator

getIteratorInstance

public Interval.Iterator getIteratorInstance(boolean isInclusiveRange)
Generates an iterator with the explicit step provided to the interval.

Parameters:
isInclusiveRange - - whether to include the end of the interval in the iteration
Returns:
the iterator

getRange

public _UNIT_ getRange()
Returns the range of the interval as the end minus the start. This may produce a value out of range for some datatypes. For example, a Deviation over the interval [-1,+1], which is completely valid, produces a range of 2, which is not on this interval and therefore an error.

Returns:
the range

getScaler

public Scaler getScaler(_UNIT_ value)
Generates a scaler on the interval [0,1] for a value on this interval. This may not work on certain kinds of datatypes like those in reverse order or with circular wrap-around.

Parameters:
value - - the value
Returns:
the scaler

getScalerInverse

public Scaler getScalerInverse(_UNIT_ value)
Generates a scaler on the interval [1,0] for a value on this interval. This may not work on certain kinds of datatypes like those in reverse order or with circular wrap-around.

Parameters:
value - - the value
Returns:
the scaler

getStart

public _UNIT_ getStart()
Gets the start value.

Returns:
the value

getStep

public _UNIT_ getStep()
Gets the step value, if one was was provided; otherwise, this method is illegal.

Returns:
the value

getSubdivisionCount

public double getSubdivisionCount(_UNIT_ divisor)
Calculates the number of subdivisions in the interval.

Parameters:
divisor - - the divisor
Returns:
the fraction count

hasStep

public boolean hasStep()
Returns whether a step value was provided.

Returns:
the state

isInclusive

public boolean isInclusive()
Returns whether the end value is considered part of the interval.

Returns:
the state

isOffRangeEnd

public boolean isOffRangeEnd(_UNIT_ value)
Determines whether a value is off the end of the interval. xxx does this work for [+1,-1]?

Parameters:
value - - the value
Returns:
the result

isOffRangeStart

public boolean isOffRangeStart(_UNIT_ value)
Determines whether a value is off the start of the interval. xxx does this work for [+1,-1]?

Parameters:
value - - the value
Returns:
the result

isWithinRange

public boolean isWithinRange(_UNIT_ value)
Determines whether a value is inclusively on the interval. xxx does this work for [+1,-1]?

Parameters:
value - - the value
Returns:
the result

scale

public double scale(Scaler scaler)
Calculates the value on the interval corresponding to a scaler percentage.

Parameters:
scaler - - the scaler
Returns:
the value

toString

public java.lang.String toString()

Overrides:
toString in class java.lang.Object