URLog.java 1.0 KB

123456789101112131415161718192021222324252627282930313233343536
  1. package at.acdp.urweb.sclient;
  2. import at.acdp.urweb.sclient.data.IJsonObject;
  3. import at.acdp.urweb.sclient.data.LogHolder;
  4. public class URLog {
  5. private final static int LENGTH=100;
  6. private static LogHolder[] list=new LogHolder[LENGTH];
  7. private static int pos=0;
  8. public static void add(IJsonObject jo) {
  9. synchronized (list) {
  10. list[pos++%LENGTH]=new LogHolder(jo);;
  11. }
  12. }
  13. public static LogEntries get(int from) {
  14. from%=LENGTH;
  15. int to=pos%LENGTH;
  16. synchronized (list){
  17. int length=to-from;
  18. if(from > to) {
  19. var ret=new LogHolder[LENGTH-from+to];
  20. System.arraycopy(list, from, ret,0,LENGTH-from);
  21. System.arraycopy(list, 0, ret,LENGTH-from,to);
  22. return new LogEntries(ret, pos);
  23. }
  24. else {
  25. var ret=new LogHolder[length];
  26. System.arraycopy(list, from, ret,0,length);
  27. return new LogEntries(ret, pos);
  28. }
  29. }
  30. }
  31. }