1234567891011121314151617181920212223242526272829303132333435363738 |
- package com.sig.app.common.utils;
- import java.util.concurrent.atomic.AtomicLong;
- public class Counter {
- private AtomicLong counter;
- public Counter() {
- this.counter = new AtomicLong(0);
- }
- public long reset() {
- return this.counter.getAndSet(0);
- }
- public long reset(long value) {
- return this.counter.getAndSet(0);
- }
- public long increment() {
- return this.counter.incrementAndGet();
- }
- public long add(long value) {
- return this.counter.addAndGet(value);
- }
- public long decrement() {
- return this.counter.decrementAndGet();
- }
- public long get() {
- return this.counter.get();
- }
- @Override
- public String toString() {
- return Converter.getSize(this.counter.doubleValue());
- }
- }
|