package com.smtscript.lib.counter; public class ScriptCounter { private int _count; private int _waitTime; private long _lastTime; private String _printFmt; public ScriptCounter(int waitTime, String printFmt) { _printFmt = printFmt; _waitTime = waitTime; _lastTime = 0; _count = 0; } public void addCount(int addCount, boolean print) { _count += addCount; if(print) printCount(); } public int getCount() { return _count; } public void setCount(int addCount, boolean print) { _count = addCount; if(print) printCount(); } public boolean canPrint(boolean setNewTime) { long curTime = System.currentTimeMillis(); if((curTime - _lastTime) >= _waitTime) { if(setNewTime) _lastTime = curTime; return true; } else return false; } public boolean printCount() { if(!canPrint(true)) return false; System.out.println(String.format(_printFmt, _count)); return true; } }