Android Open Source - android-accelerometer-gps Circular Buffer






From Project

Back to project page android-accelerometer-gps.

License

The source code is released under:

MIT License

If you think the Android project android-accelerometer-gps listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.szlosek.whenmoving;
/*from  www.  j  a  va2s  . co  m*/

// From: http://www.cs.utsa.edu/~wagner/CS2213/queue/queue.html
public class CircularBuffer {
  private int qMaxSize;// max queue size
  private int fp = 0;  // front pointer
  private int rp = 0;  // rear pointer
  private int qs = 0;  // size of queue
  private Object[] q;    // actual queue

  public CircularBuffer(int size) {
    qMaxSize = size;
    fp = -1;
    rp = 0;
    qs = 0;
    q = new Object[qMaxSize];
  }

  public Object delete() {
    if (!emptyq()) {
      qs--;
      fp = (fp + 1)%qMaxSize;
      return q[fp];
    } else {
      System.err.println("Underflow");
      return null;
    }
  }

  public void insert(Object c) {
    fp++;
    if (fp == qMaxSize) {
      fp = 0;
    }
    q[ fp ] = c;
    if (qs < qMaxSize) {
      qs++;
    }
  }

  public boolean emptyq() {
    return qs == 0;
  }

  public int size() {
    return qs;
  }
  
  public Object get(int i) {
    if (qs == 0) {
      return null;
    }
    // offset from fp
    int j = fp + i;
    if (j >= qMaxSize) {
      j -= qMaxSize;
    }
    return q[ j ];
  }

  public boolean fullq() {
    return qs == qMaxSize;
  }
}




Java Source Code List

com.szlosek.whenmoving.CalibrationActivity.java
com.szlosek.whenmoving.CircularBuffer.java
com.szlosek.whenmoving.DatabaseHelper.java
com.szlosek.whenmoving.DaysActivity.java
com.szlosek.whenmoving.MainActivity.java
com.szlosek.whenmoving.MainApplication.java
com.szlosek.whenmoving.MainReceiver.java
com.szlosek.whenmoving.MainService.java
com.szlosek.whenmoving.SettingsActivity.java
com.szlosek.whenmoving.TimeoutReceiver.java