public int getSize() throws IOException { // return the hashtable size FastIterator iter = hashtable.keys(); int count = 0; while (iter.next() != null) count++; return count; }
private void addAllFileTableKeys(Set<Object> keys) throws IOException { FastIterator<Object> iter = fileTable.keys(); Object key = null; while ((key = iter.next()) != null) { keys.add(key); } }
public long getSizeInBytes() { long totalSize = 0; if (fileTable != null) { try { synchronized (this) { FastIterator<V> iter = fileTable.values(); V value = iter.next(); while (value != null) { totalSize += findSizeInBytes(value); value = iter.next(); } } } catch (IOException e) { Debug.logError(e, module); return 0; } } else { for (CacheLine<V> line : memoryTable.values()) { totalSize += findSizeInBytes(line.getValue()); } } return totalSize; }
public Collection<V> values() { if (fileTable != null) { List<V> values = FastList.newInstance(); try { synchronized (this) { FastIterator<V> iter = fileTable.values(); V value = iter.next(); while (value != null) { values.add(value); value = iter.next(); } } } catch (IOException e) { Debug.logError(e, module); } return values; } else { List<V> valuesList = FastList.newInstance(); for (CacheLine<V> line : memoryTable.values()) { valuesList.add(line.getValue()); } return valuesList; } }
/** * Returns the number of elements currently in the cache * * @return The number of elements currently in the cache */ public int size() { if (fileTable != null) { int size = 0; try { synchronized (this) { FastIterator<Object> iter = fileTable.keys(); while (iter.next() != null) { size++; } } } catch (IOException e) { Debug.logError(e, module); } return size; } else { return memoryTable.size(); } }
/** * Returns a boolean specifying whether or not an element with the specified key is in the cache. * * @param key The key for the element, used to reference it in the hastables and LRU linked list * @return True is the cache contains an element corresponding to the specified key, otherwise * false */ public boolean containsKey(Object key) { Object nulledKey = fromKey(key); CacheLine<V> line = memoryTable.get(nulledKey); if (line == null) { if (fileTable != null) { try { synchronized (this) { FastIterator<Object> iter = fileTable.keys(); Object checkKey = null; while ((checkKey = iter.next()) != null) { if (nulledKey.equals(checkKey)) { return true; } } } } catch (IOException e) { Debug.logError(e, module); } } return false; } else { return true; } }