SHARE
TWEET

Untitled

advictoriam Jan 31st, 2019 68 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /**
  2.    This class collects a number of values and counts the peaks and valleys.
  3. */
  4. public class DataSet
  5. {
  6.    private double lastValue;
  7.    private int wasCanidate;
  8.    private double precedingValue;
  9.    private int count;
  10.    public int peaks;
  11.    public int valleys;
  12.  
  13.    /**
  14.       Constructs a new data set with no data.
  15.    */
  16.    public DataSet()
  17.    {
  18.       lastValue = 0;
  19.       wasCanidate = 0;
  20.       precedingValue = 0;
  21.       count = 0;
  22.       peaks = 0;
  23.       valleys = 0;
  24.    }
  25.  
  26.    /**
  27.       Adds a value to this data set.
  28.       @param valueToAdd the value to add to this data set
  29.    */
  30.    public void add(double valueToAdd)
  31.    {      
  32.       if(count == 0){lastValue = valueToAdd; count++; return;}
  33.       else if(valueToAdd < lastValue && precedingValue < lastValue)
  34.       {
  35.          peaks++;
  36.          precedingValue = lastValue;
  37.          lastValue = valueToAdd;
  38.          count++;
  39.          return;
  40.       }
  41.       else if(valueToAdd > lastValue && precedingValue > lastValue)
  42.       {
  43.          valleys++;
  44.          precedingValue = lastValue;
  45.          lastValue = valueToAdd;
  46.          count++;
  47.          return;
  48.       }
  49.       precedingValue = lastValue;
  50.       lastValue = valueToAdd;
  51.    }
  52.  
  53.    /**
  54.       Gets the number of peaks in this data set.
  55.       @return the number of peaks in this data set
  56.    */
  57.    public int getPeakCount()
  58.    {
  59.       return peaks;
  60.    }
  61.  
  62.    /**
  63.       Gets the number of valleys in this data set.
  64.       @return the number of valleys in this data set
  65.    */
  66.    public int getValleyCount()
  67.    {
  68.       return valleys;
  69.    }
  70. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top