1 57 58 package com.Yasna.util; 59 60 import java.util.*; 61 62 67 public class CacheSizes { 68 69 75 public static int sizeOfObject() { 76 return 4; 77 } 78 79 85 public static int sizeOfString(String string) { 86 if (string == null) { 87 return 0; 88 } 89 return 4 + string.length()*2; 90 } 91 92 97 public static int sizeOfInt() { 98 return 4; 99 } 100 101 106 public static int sizeOfChar() { 107 return 2; 108 } 109 110 115 public static int sizeOfBoolean() { 116 return 1; 117 } 118 119 124 public static int sizeOfLong() { 125 return 8; 126 } 127 128 133 public static int sizeOfDouble() { 134 return 8; 135 } 136 137 142 public static int sizeOfDate() { 143 return 12; 144 } 145 146 153 public static int sizeOfProperties(Properties properties) { 154 if (properties == null) { 155 return 0; 156 } 157 int size = 36; 159 Enumeration enume = properties.elements(); 161 while(enume.hasMoreElements()) { 162 String prop = (String )enume.nextElement(); 163 size += sizeOfString(prop); 164 } 165 enume = properties.propertyNames(); 167 while(enume.hasMoreElements()) { 168 String prop = (String )enume.nextElement(); 169 size += sizeOfString(prop); 170 } 171 return size; 172 } 173 174 181 public static int sizeOfMap(Map map) { 182 if (map == null) { 183 return 0; 184 } 185 int size = 36; 187 Iterator iter = map.values().iterator(); 189 while(iter.hasNext()) { 190 String value = (String )iter.next(); 191 size += sizeOfString(value); 192 } 193 iter = map.keySet().iterator(); 195 while(iter.hasNext()) { 196 String key = (String )iter.next(); 197 size += sizeOfString(key); 198 } 199 return size; 200 } 201 } 202 | Popular Tags |