1 25 26 27 package org.nemesis.forum.util.cache; 28 29 import java.util.Enumeration ; 30 import java.util.Iterator ; 31 import java.util.Map ; 32 import java.util.Properties ; 33 34 39 public class CacheSizes { 40 41 47 public static int sizeOfObject() { 48 return 4; 49 } 50 51 57 public static int sizeOfString(String string) { 58 if (string == null) { 59 return 0; 60 } 61 return 4 + string.length()*2; 62 } 63 64 69 public static int sizeOfInt() { 70 return 4; 71 } 72 73 78 public static int sizeOfChar() { 79 return 2; 80 } 81 82 87 public static int sizeOfBoolean() { 88 return 1; 89 } 90 91 96 public static int sizeOfLong() { 97 return 8; 98 } 99 100 105 public static int sizeOfDouble() { 106 return 8; 107 } 108 109 114 public static int sizeOfDate() { 115 return 12; 116 } 117 118 125 public static int sizeOfProperties(Properties properties) { 126 if (properties == null) { 127 return 0; 128 } 129 int size = 36; 131 Enumeration e = properties.elements(); 133 while(e.hasMoreElements()) { 134 String prop = (String )e.nextElement(); 135 size += sizeOfString(prop); 136 } 137 e = properties.propertyNames(); 139 while(e.hasMoreElements()) { 140 String prop = (String )e.nextElement(); 141 size += sizeOfString(prop); 142 } 143 return size; 144 } 145 146 153 public static int sizeOfMap(Map map) { 154 if (map == null) { 155 return 0; 156 } 157 int size = 36; 159 Iterator iter = map.values().iterator(); 161 while(iter.hasNext()) { 162 String value = (String )iter.next(); 163 size += sizeOfString(value); 164 } 165 iter = map.keySet().iterator(); 167 while(iter.hasNext()) { 168 String key = (String )iter.next(); 169 size += sizeOfString(key); 170 } 171 return size; 172 } 173 } 174 | Popular Tags |