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:
 // 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

    Constructors
    Constructor Description
    Limits​(double l, double h)
    Limits (low, high)
    Limits​(double l, double h, double r)
    Limits(low, high, randomStepRange
  • Method Summary

    Modifier and Type Method Description
    double clip​(double val)  
    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
    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
    double getHigh()
    upper bound
    int getIntValue()
    return the current value of random walk
    double getLow()
    lower bound
    double getRange()
    returns range for a random step.
    double getValue()
    return the current value of random walk
    static void main​(java.lang.String[] args)
    Take a random walk
    double randomStep()
    Take one step in a random walk, adding a random value betwwen -range ..
    void setLimits​(double l, double h)
    set the bounds
    void setRange​(double r)
    set how high up or down the value can change with each random step
    void setValue​(double value)
    set current value of random walk
    java.lang.String toString()  
    boolean within​(double value)
    Returns true if val is between this.getLow() and this.getHigh(), inclusive
    static boolean within​(double val, double lo, double hi)
    Returns true if val is between lo and hi, inclusive
    boolean within​(int value)
    Returns true if val is between this.getLow() and this.getHigh(), inclusive
    static boolean within​(int val, int lo, int hi)
    Returns true if val is between lo and hi, inclusive

    Methods 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:
      toString in class java.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