Counter.java 805 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. package com.sig.app.common.utils;
  2. import java.util.concurrent.atomic.AtomicLong;
  3. public class Counter {
  4. private AtomicLong counter;
  5. public Counter() {
  6. this.counter = new AtomicLong(0);
  7. }
  8. public long reset() {
  9. return this.counter.getAndSet(0);
  10. }
  11. public long reset(long value) {
  12. return this.counter.getAndSet(0);
  13. }
  14. public long increment() {
  15. return this.counter.incrementAndGet();
  16. }
  17. public long add(long value) {
  18. return this.counter.addAndGet(value);
  19. }
  20. public long decrement() {
  21. return this.counter.decrementAndGet();
  22. }
  23. public long get() {
  24. return this.counter.get();
  25. }
  26. @Override
  27. public String toString() {
  28. return Converter.getSize(this.counter.doubleValue());
  29. }
  30. }