1 package net.suberic.util.cache; 2 3 7 public class SizedCacheEntry { 8 9 protected Object cachedValue; 12 13 protected long lastAccessedTime; 15 16 protected long size = 0; 18 19 22 public SizedCacheEntry() { 23 } 24 25 29 public SizedCacheEntry(Object value) { 30 cachedValue = value; 31 size = value.toString().length(); 33 touchEntry(); 34 } 35 36 39 public Object getCachedValue() { 40 return cachedValue; 41 } 42 43 50 public boolean removeFromCache() { 51 return true; 52 } 53 54 57 public void touchEntry() { 58 lastAccessedTime = System.currentTimeMillis(); 59 } 60 61 64 public long getSize() { 65 return size; 66 } 67 68 71 public long getLastAccessedTime() { 72 return lastAccessedTime; 73 } 74 75 78 public boolean equals(Object o) { 79 if (o != null) { 80 Object testValue = null; 81 if (o instanceof SizedCacheEntry) { 82 testValue = ((SizedCacheEntry)o).getCachedValue(); 83 } else { 84 testValue = o; 85 } 86 return o.equals(cachedValue); 87 } 88 89 return (cachedValue == null); 90 } 91 } 92 93 | Popular Tags |