001package org.unix4j.util; 002 003public class Counter { 004 005 private long count; 006 007 public Counter() { 008 count = 0; 009 } 010 011 public long getCount() { 012 return count; 013 } 014 015 public void reset() { 016 count = 0; 017 } 018 public long increment() { 019 return ++count; 020 } 021 public long increment(long inc) { 022 count += inc; 023 return count; 024 } 025 public long decrement() { 026 return --count; 027 } 028 public long decrement(long dec) { 029 count -= dec; 030 return count; 031 } 032 public int getWidth(){ 033 return String.valueOf(getCount()).length(); 034 } 035 036 @Override 037 public String toString() { 038 return "count=" + count; 039 } 040}