Code example for Queue

Methods: add, remove, size

0
 
  /* 
   * Updating sensor cache, replacing oldest values. 
   */ 
  private void addToSensorCache(Queue<Float> cache, float value) {
    if (cache.size() >= SENSOR_CACHE_SIZE) {
      cache.remove();
    } 
    cache.add(value);
  } 
 
  /* 
   * Indicates whether there was a sudden, unusual movement. 
   */ 
  // TODO: maybe this can be improved 
  //       see http://www.utdallas.edu/~rxb023100/pubs/Accelerometer_WBSN.pdf  
  private boolean isShaking(Queue<Float> cache, float currentValue) {
    float average = 0;
    for (float value : cache) {
      average += value;
    }