1 20 package org.enhydra.dods.cache; 21 22 import java.util.HashMap ; 23 import org.enhydra.dods.statistics.CacheStatistics; 24 25 33 public class DODSHashMap extends HashMap implements CacheStatistics { 34 35 38 protected int cacheAccessNum = 0; 39 40 43 protected int cacheHitsNum = 0; 44 45 50 DODSHashMap() { 51 super(); 52 clearStatistics(); 53 } 54 55 60 public int getCacheAccessNum() { 61 return cacheAccessNum; 62 } 63 64 69 public void setCacheAccessNum(int num) { 70 this.cacheAccessNum = num; 71 } 72 73 76 public void incrementCacheAccessNum(int num) { 77 cacheAccessNum += num; 78 } 79 80 85 public int getCacheHitsNum() { 86 return cacheHitsNum; 87 } 88 89 94 public void setCacheHitsNum(int cacheHitsNum) { 95 this.cacheHitsNum = cacheHitsNum; 96 } 97 98 101 public void incrementCacheHitsNum(int num) { 102 cacheHitsNum += num; 103 } 104 105 111 public double getUsedPercents() { 112 int maxCacheSize = -1; 113 114 if (maxCacheSize < 0) { 115 return 100; 116 } 117 int temp = size() * 10000; 118 double res = temp / maxCacheSize; 119 120 return res / 100; 121 } 122 123 130 public double getCacheHitsPercents() { 131 if (cacheAccessNum == 0) { 132 return 0; 133 } 134 int temp = cacheHitsNum * 10000; 135 double res = temp / cacheAccessNum; 136 137 return res / 100; 138 } 139 140 143 public void clearStatistics() { 144 this.cacheAccessNum = 0; 145 this.cacheHitsNum = 0; 146 } 147 } 148 | Popular Tags |