com.amx.duet.tools.math
Class Range

java.lang.Object
  extended bycom.amx.duet.tools.math.Range

public class Range
extends java.lang.Object

A utility class to handle ranges used within Duet modules. These ranges can be especially useful when adjusting values between the panel and the device.

Since:
AMXTools 2.0.20
Version:
1.0.4

Constructor Summary
Range(double minValue, double maxValue, double increment)
          Constructs and initializes the Range class.
Range(double minValue, double maxValue, double increment, double currentValue)
          Constructs and initializes the Range class.
 
Method Summary
 double getCurrentValue()
          Returns the current value of the rnage.
 double getIncrement()
          Returns the value of the increment used to determin discrete values within the range.
 double getMaxValue()
          Returns the maximum value of the range.
 double getMinValue()
          Returns the minimum value of the Range.
 int getPosition()
          Returns the discrete position of the currentValue of the range.
 int getPosition(double value)
          Returns the discrete position of the range that most closely matches the value.
 double getScaledValue(Range sourceRange)
          Returns the value of this range based on the scaled position of the sourceRange.
 double getValue(int step)
          Returns the value of the discrete position of this range.
 double getValueForOffset(int offset)
          Returns the value of the discrete position of the current value plus the offset.
 int numberOfSteps()
          Returns the number of discrete values contained within this range.
 int scale(Range sourceRange)
          Returns the position the value of the sourceRange would have within this range.
 void setCurrentValue(double value)
          Sets the current value of the range.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Range

public Range(double minValue,
             double maxValue,
             double increment,
             double currentValue)
Constructs and initializes the Range class. This will determine the minimum and maximum values of the range, as well as the increment used within the range. The current value of the range is also set. These values will be used when setting the value based on a level input, and when processing the value sent from the device to set the level feedback.

Example usage:

 Range panelRange  = new Range( 0, 255, 1);
 Range volumeRange = new Range( -95.5, 31.5, .5);
  ...
       
 public void setVolume(int level)
 {
    panelRange.setCurrentValue( level );
    double deviceVolume = volumeRange.getScaledValue(panelRange);
    // If your device only needs an integer value, you can cast 
    // the deviceVolume returned from getScaled value as shown below:
    // int deviceVolume = (int) volumeRange.getScaledValue(panelRange);
    enQueue( setVolumeCommand(deviceVolume) );
 }
    
 private void parseResponse(ByteBuffer data)
 {
    ...
    // Handling Volume response
    String volumeValue = data.toString().substring(volumeStart,volumeEnd);
    double deviceVolume = Double.parseDouble(volumeValue);
    // If your device only needs an integer value, you can cast 
    // the deviceVolume returned from getScaled value as shown below:
    // int deviceVolume = Integer.parseInt(volumeValue);

    volumeRange.setCurrentValue( deviceVolume );
    int panelVolume = panelRange.scale( volumeRange );
    updateVolume( panelVolume );
 }
 

Parameters:
minValue - The minimum value of the range.
maxValue - The maximum value of the range.
increment - The increment between each discrete value of the range.
currentValue - The current value of range.

Range

public Range(double minValue,
             double maxValue,
             double increment)
Constructs and initializes the Range class. This will determine the minimum and maximum values of the range, as well as the increment used within the range. These values will be used when setting the value based on a level input, and when processing the value sent from the device to set the level feedback. The current Value is set to the minimum value of the range.

Parameters:
minValue - The minimum value of the range.
maxValue - The maximum value of the range.
increment - The increment between each discrete value of the range.
See Also:
Range(double,double,double,double)
Method Detail

getCurrentValue

public double getCurrentValue()
Returns the current value of the rnage.

Returns:
Returns the currentValue.

getIncrement

public double getIncrement()
Returns the value of the increment used to determin discrete values within the range.

Returns:
Returns the _increment.

getMaxValue

public double getMaxValue()
Returns the maximum value of the range.

Returns:
Returns the maxValue.

getMinValue

public double getMinValue()
Returns the minimum value of the Range.

Returns:
Returns the minValue.

getPosition

public int getPosition()
Returns the discrete position of the currentValue of the range.

Returns:
The discrete position that most closely matches the currentValue.
See Also:
getPosition(double)

getPosition

public int getPosition(double value)
Returns the discrete position of the range that most closely matches the value. If the value is outside the minimum or maximum values of the range, a warning message is displayed. Also, if the value is not a discrete value of the range, a warning message is displayed.

Parameters:
value - The value you want to evaluate the position of.
Returns:
The discrete position that most closely matches the value.

getScaledValue

public double getScaledValue(Range sourceRange)
Returns the value of this range based on the scaled position of the sourceRange.

Parameters:
sourceRange - The range you want to evaluate the discrete position of the value.
Returns:
The value within this range that most closely matches the position of the value within sourceRange.
See Also:
getValue(int), scale(Range)

getValue

public double getValue(int step)
Returns the value of the discrete position of this range. If the position requested is less than zero, then the minimum value is returned. If the position is greater than the number of steps, then the maximum value of the range is calculated.

Parameters:
step - The discrete position of this range.
Returns:
The value of the position within the range.

getValueForOffset

public double getValueForOffset(int offset)
Returns the value of the discrete position of the current value plus the offset. The offset can be positive or negative.

Example usage:

 public void adjustVolume(int offset)
 {
    double deviceVolume = volumeRange.getValueForOffset( offset );
    enQueue( setVolumeCommand(deviceVolume) );
 }
 
Review getValue(int) for more information....

Parameters:
offset - The number of discrete units to adjust.
Returns:
The value for this range adjusted by the offset.

numberOfSteps

public int numberOfSteps()
Returns the number of discrete values contained within this range. If the range is not evenly divisible by the increment of the range, a warning message is displayed.

Returns:
The number of discrete values within the range.

scale

public int scale(Range sourceRange)
Returns the position the value of the sourceRange would have within this range. If a loss of percision will occur, a warning message is displayed.

Parameters:
sourceRange - The range you want to evaluate the discrete position of the value.
Returns:
The discrete position of this range that most closely matches the value contained in the sourceRange.

setCurrentValue

public void setCurrentValue(double value)
Sets the current value of the range. If the value is not one of the discrete values defined by the range, a warning messages is displayed.

Parameters:
value - The currentValue to set.


Copyright © 2008 AMX LLC. All Rights Reserved.