Android Open Source - piepsendroid Memory






From Project

Back to project page piepsendroid.

License

The source code is released under:

This software is copyrighted by Michael Straeubig. The following terms (the "Standard Improved BSD License") apply to all files associated with the software unless explicitly disclaimed in individual ...

If you think the Android project piepsendroid 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 de.i3games.piepsendroid;
//from  www . ja  v a 2  s . c  o m
public class Memory {
  private static final int DEFAULT_SIZE = 10;
  private int mSize;
  private int mPos;
  private float[] mValues;

  public Memory(int size) {
    mSize = size;
    mValues = new float[size];
    mPos = 0;
  }

  public Memory() {
    this(DEFAULT_SIZE);
  }

  void add(float val) {
    mValues[mPos] = val;
    mPos = (mPos + 1) % mSize;
  }

  float getAverage() {
    float sum = 0.0f;
    for (int i = 0; i < mSize; i++) {
      sum = sum + mValues[i];
    }
    return sum / mSize;
  }
  
  float getVariance() {
    float sum = 0.0f, diff = 0.0f;
    final float average = getAverage();
    
    for (int i = 0; i < mSize; i++) {
      diff = average - mValues[i];
      sum = sum + diff * diff;
    }
    
    return sum / mSize;
    
  }
  

}




Java Source Code List

de.i3games.piepsendroid.AboutActivity.java
de.i3games.piepsendroid.Memory.java
de.i3games.piepsendroid.PiepsenDroidActivity.java
de.i3games.piepsendroid.SettingsActivity.java