Package com.softsynth.jmsl
Class Limits
java.lang.Object
com.softsynth.jmsl.Limits
- All Implemented Interfaces:
java.io.Serializable
- Direct Known Subclasses:
DimAttributes
public class Limits
extends java.lang.Object
implements java.io.Serializable
Handy class for handling ranges between a low and a high value.
Limits have a low and high value, and clip method.
Random walk is implemented here as well.
Example:
Limits have a low and high value, and clip method.
Random walk is implemented here as well.
Example:
// take a random walk of 400 steps
Limits randomWalk = new Limits(10, 50, 1); // low, high, range
for (int i=0; i<400; i++) {
System.out.print((int)randomWalk.getValue() + " ");
randomWalk.randomStep();
}
- Author:
- Phil Burk and Nick Didkovsky
- See Also:
- Serialized Form
-
Constructor Summary
-
Method Summary
Modifier and Type Method Description doubleclip(double val)static doubleclipTo(double val, double lo, double hi)return value clipped to specified range - static version, don't need an instance of Limits() to use thisstatic intclipTo(int val, int lo, int hi)return value clipped to specified range - static version, don't need an instance of Limits() to use thisdoublegetHigh()upper boundintgetIntValue()return the current value of random walkdoublegetLow()lower bounddoublegetRange()returns range for a random step.doublegetValue()return the current value of random walkstatic voidmain(java.lang.String[] args)Take a random walkdoublerandomStep()Take one step in a random walk, adding a random value betwwen -range ..voidsetLimits(double l, double h)set the boundsvoidsetRange(double r)set how high up or down the value can change with each random stepvoidsetValue(double value)set current value of random walkjava.lang.StringtoString()booleanwithin(double value)Returns true if val is between this.getLow() and this.getHigh(), inclusivestatic booleanwithin(double val, double lo, double hi)Returns true if val is between lo and hi, inclusivebooleanwithin(int value)Returns true if val is between this.getLow() and this.getHigh(), inclusivestatic booleanwithin(int val, int lo, int hi)Returns true if val is between lo and hi, inclusiveMethods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Constructor Details
-
Limits
public Limits(double l, double h)Limits (low, high) -
Limits
public Limits(double l, double h, double r)Limits(low, high, randomStepRange
-
-
Method Details
-
randomStep
public double randomStep()Take one step in a random walk, adding a random value betwwen -range .. +range, inclusive- Returns:
- new value after taking step
-
getValue
public double getValue()return the current value of random walk -
getIntValue
public int getIntValue()return the current value of random walk -
setValue
public void setValue(double value)set current value of random walk -
getRange
public double getRange()returns range for a random step. Ex. a range of 2 means every random step can add a value between -2 .. +2 inclusive to current value -
setRange
public void setRange(double r)set how high up or down the value can change with each random step -
getLow
public double getLow()lower bound -
getHigh
public double getHigh()upper bound -
setLimits
public void setLimits(double l, double h)set the bounds -
toString
public java.lang.String toString()- Overrides:
toStringin classjava.lang.Object
-
clip
public double clip(double val)- Returns:
- argument clipped to internally stored range. See also setLimits()
-
clipTo
public static double clipTo(double val, double lo, double hi)return value clipped to specified range - static version, don't need an instance of Limits() to use this -
clipTo
public static int clipTo(int val, int lo, int hi)return value clipped to specified range - static version, don't need an instance of Limits() to use this -
within
public static boolean within(double val, double lo, double hi)Returns true if val is between lo and hi, inclusive -
within
public static boolean within(int val, int lo, int hi)Returns true if val is between lo and hi, inclusive -
within
public boolean within(double value)Returns true if val is between this.getLow() and this.getHigh(), inclusive -
within
public boolean within(int value)Returns true if val is between this.getLow() and this.getHigh(), inclusive -
main
public static void main(java.lang.String[] args)Take a random walk
-