title: Moving average/total algorithm
body: <p>I need to keep track of the last 7 days work hours in a flat file reading loop. It's being used to measure 'fatigueability' of work rosters.</p>
  
  <p>Right now I have something that works, but it seems rather verbose and I'm not sure whether there's a pattern that's more succinct.</p>
  
  <p>Currently, I have a Java class with a static array to hold the last x days data, then as I read through the file, I chop off the first element and move the other 6 (for a week rolling total) back by one. The processing of this static array is done in its own method ie.</p>
  
  <pre><code>/**
   * Generic rolling average/total method. Keeps adding to an array of 
   * last 'x' seen.
   * @param d Datum point you want to add/track.
   * @param i Number of rolling periods to keep track of eg. 7 = last 7 days
   *          NOT USED AT MOMENT DURING TESTING
   * @param initFlag A flag to initialize static data set back to empty.
   * @return The rolling total for i periods.
   */
  private double rollingTotal(double d, boolean initFlag) {
      // Initialize running total array eg. for new Employyes
      if (initFlag) {
          runningTotal = null;
      }
      else {
          // move d+1 back to d eg. element 6 becomes element 5
          for (int x = 0; x&lt; 6 ; x++) {
              runningTotal[x] = runningTotal[x+1];
          }
          // Put current datum point at end of array.
          runningTotal[6]= d;
      }
      // Always return sum of array when this method is called.
      double myTotal = 0.0;
      for (int x = 0; x&lt;7; x++) {
          myTotal+= runningTotal[x];
      }
      System.err.print(Arrays.toString(runningTotal)+ '\n' );
      return myTotal;
  }
  </code></pre>
  
  <p>My question: is this a reasonable design approach, or is there something blindingly obvious and simple to do this task?
  Thanks guys</p>