Counter.java 806 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. package com.its.bis.process;
  2. import com.its.app.utils.Converter;
  3. import java.util.concurrent.atomic.AtomicLong;
  4. public class Counter {
  5. private AtomicLong counter = new AtomicLong(0L);
  6. public Counter() {
  7. }
  8. public long reset() {
  9. return this.counter.getAndSet(0L);
  10. }
  11. public long reset(long value) {
  12. return this.counter.getAndSet(0L);
  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. public String toString() {
  27. return Converter.getSize(this.counter.doubleValue());
  28. }
  29. }