Main Page | Packages | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | Related Pages

CounterMap.java

Go to the documentation of this file.
00001 
00057 package com.arcle.rmt.j2se.util;
00058 
00059 import java.util.Map;
00060 import java.util.Hashtable;
00061 import com.arcle.rmt.xplat.util.MutableInteger;
00062 
00069 public class CounterMap {
00070 
00077     public int getCounter(Object key) {
00078         // returns the value of the MutableInteger
00079         return doGetCounter(key).value;
00080     }
00081 
00085     public int incrementCounter(Object key) {
00086         MutableInteger value = doGetCounter(key);
00087         doIncrementCounter(value);
00088         return value.value;
00089     }
00090 
00091     //-----------------------------------------------------------------------
00092     // Strategy methods
00093 
00098     protected void doIncrementCounter(MutableInteger counter) {
00099         counter.value++;
00100     }
00101 
00102 
00107     protected int doGetInitialCounterValue() {
00108         return 0;
00109     }
00110 
00117     protected MutableInteger doGetCounter(Object key) {
00118         Map m = getCounters();
00119         MutableInteger value = (MutableInteger) m.get(key);
00120         if (value == null) {
00121             value = createMutableInteger(doGetInitialCounterValue());
00122             m.put(key, value);
00123         }
00124         return value;
00125     }
00126 
00127     //-----------------------------------------------------------------------
00128     // Accessor methods
00129 
00134     protected Map getCounters() {
00135         if (_counters == null) {
00136             _counters = createCounters();
00137         }
00138         return _counters;
00139     }
00140 
00141     //-----------------------------------------------------------------------
00142     // Factory methods
00143 
00148     protected MutableInteger createMutableInteger(int init) {
00149         return new MutableInteger(init);
00150     }
00151 
00155     protected Map createCounters() {
00156         return new Hashtable();
00157     }
00158 
00159     //-----------------------------------------------------------------------
00160     // Member variables.
00161 
00165     private Map _counters = null;
00166 }
00167 

Generated on Fri Jun 18 19:51:14 2004 for Arcle Rambutan by doxygen 1.3.5