You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

RingPuffer.java 866B

1234567891011121314151617181920212223242526272829303132333435363738
  1. package com.example.greenwatch.sensors.MicrofonHelperClasses;
  2. public class RingPuffer {
  3. private short[] puffer;
  4. private final int laenge;
  5. private int anzahlEnthaltenerDaten;
  6. private int position;
  7. public RingPuffer(int n) {
  8. laenge = n;
  9. anzahlEnthaltenerDaten = 0;
  10. position = 0;
  11. puffer = new short[laenge];
  12. }
  13. public void hinzufuegen(short wert) {
  14. puffer[position] = wert;
  15. position++;
  16. if (position >= laenge) {
  17. position = 0;
  18. }
  19. if (anzahlEnthaltenerDaten < laenge) {
  20. anzahlEnthaltenerDaten++;
  21. }
  22. }
  23. public short maximum() {
  24. short max = 0;
  25. for (int i = 0; i < anzahlEnthaltenerDaten; i++) {
  26. if (puffer[i] > max) {
  27. max = puffer[i];
  28. }
  29. }
  30. return max;
  31. }
  32. }