@@ -0,0 +1,1323 @@
+%0Apackage com.lofibucket.yotris.logic;%0A%0A%0A/**%0A * A simple counter class that wraps around when its value is less than zero.%0A */%0Apublic class ZeroBasedCounter %7B%0A%09private int value;%0A%09private int lowerLimit;%0A%09private int upperLimit;%0A%0A%09/**%0A%09 *%09%0A%09 * @param value%09The initial value for the counter%0A%09 * @param upperLimit%09The limit to which the value wraps around to when%0A%09 * under zero%0A%09 */%0A%09public ZeroBasedCounter(int value, int upperLimit) %7B%0A%09%09this.value = value;%0A%09%09this.lowerLimit = 0;%0A%09%09this.upperLimit = upperLimit;%0A%09%09checkLimit();%0A%09%7D%0A%0A%09/**%0A%09 *%09Returns the counter value%0A%09 * @return%0A%09 */%0A%09public int getValue() %7B%0A%09%09return value;%0A%09%7D%0A%0A%09/**%0A%09 *%0A%09 * @return%09counters upper limit%0A%09 */%0A%09public int getUpperLimit() %7B%0A%09%09return upperLimit;%0A%09%7D%0A%0A%09/**%0A%09 * %0A%09 * @return counters lower limit%0A%09 */%0A%09public int getLowerLimit() %7B%0A%09%09return lowerLimit;%0A%09%7D%0A%0A%09/**%0A%09 *%0A%09 * @param new_value%0A%09 */%0A%09public void setValue(int new_value) %7B%0A%09%09this.value = new_value;%09%0A%09%09checkLimit();%0A%09%7D%0A%0A%09/**%0A%09 *%09Decreases the counter by one, wraps around if necessary%0A%09 */%0A%09public void decrease() %7B%0A%09%09value--;%0A%09%09checkLimit();%0A%09%7D%0A%0A%09/**%0A%09 * Tells if the counter value is zero%0A%09 * @return true if value is zero, otherwise false%0A%09 */%0A%09public boolean isZero() %7B%0A%09%09return value==0;%0A%09%7D%0A%0A%09private void checkLimit() %7B%0A%09%09if (value %3C lowerLimit) %7B%0A%09%09%09value = upperLimit;%0A%09%09%7D%0A%09%7D%0A%0A%7D%0A

add zero based counter class