Advertisement
advictoriam

Untitled

Jan 31st, 2019
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.65 KB | None | 0 0
  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. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement