SHARE
TWEET

Untitled

advictoriam Jan 31st, 2019 66 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. public class SpinningDiskDevice
  2. {
  3.    private int lastInput;
  4.    private int segmentLength;
  5.  
  6.    /**
  7.       Constructs a spinning disk device.
  8.    */
  9.    public SpinningDiskDevice()
  10.    {
  11.       lastInput = 0;
  12.       segmentLength = 0;
  13.    }
  14.  
  15.    /**
  16.       Processes a new input
  17.       @param input 0 or 1
  18.    */
  19.    public void add(int input)
  20.    {
  21.       if(input == lastInput)
  22.       {
  23.          segmentLength++;
  24.       }
  25.       else
  26.       {
  27.          lastInput = input;
  28.          segmentLength = 1;
  29.       }
  30.    }
  31.  
  32.    /**
  33.       Gets the length of the current segment.
  34.    */
  35.    public int getSegmentLength()
  36.    {
  37.       return segmentLength;
  38.    }
  39. }
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