/** * always returns {@code false}, and instead invokes {@code removeLRU()} * if {@code size >= maxSize}. */ protected boolean removeEldestEntry(Map.Entry<K, V> pEldest) { // NOTE: As removeLRU() may remove more than one entry, this is better // than simply removing the eldest entry. if (size() >= maxSize) { removeLRU(); } return false; }
/** * Removes the least recently used mapping(s) from this map. * <p> * How many mappings are removed from the map, is controlled by the * trim factor. * In any case, at least one mapping will be removed. * * @see #getTrimFactor() */ public void removeLRU() { int removeCount = (int) Math.max((size() * trimFactor), 1); Iterator<Map.Entry<K, V>> entries = entrySet().iterator(); while ((removeCount--) > 0 && entries.hasNext()) { entries.next(); entries.remove(); } } }
/** * Creates an LRUHashMap with initial mappings from the given map, * and the given max size. * * @param pContents the map whose mappings are to be placed in this map. * May be {@code null}. * @param pMaxSize size limit */ public LRUHashMap(Map<? extends K, ? extends V> pContents, int pMaxSize) { super(16, .75f, true); setMaxSize(pMaxSize); putAll(pContents); }
/** * Creates an LRUHashMap with the given max size. * * @param pMaxSize size limit */ public LRUHashMap(int pMaxSize) { super(16, .75f, true); setMaxSize(pMaxSize); }
/** * Creates an LRUHashMap with initial mappings from the given map, * and default max size (1000 entries). * * <small>This is constructor is here to comply with the reccomendations for * "standard" constructors in the {@code Map} interface.</small> * * @param pContents the map whose mappings are to be placed in this map. * May be {@code null}. * * @see #LRUHashMap(java.util.Map, int) */ public LRUHashMap(Map<? extends K, ? extends V> pContents) { super(16, .75f, true); putAll(pContents); }
@Override public void removeLRU() { while (maxSize <= currentSize) { // NOTE: maxSize here is mem size super.removeLRU(); } } }
@Override public V put(K pKey, V pValue) { currentSize += sizeOf(pValue); V old = super.put(pKey, pValue); if (old != null) { currentSize -= sizeOf(old); } return old; }
entityCache = new LRUHashMap<String, CachedEntity>(pMaxCachedEntites); varyCache = new LRUHashMap<String, Properties>(pMaxCachedEntites);
/** * Creates an LRUHashMap with the given max size. * * @param pMaxSize size limit */ public LRUHashMap(int pMaxSize) { super(16, .75f, true); setMaxSize(pMaxSize); }
/** * Creates an LRUHashMap with initial mappings from the given map, * and default max size (1000 entries). * * <small>This is constructor is here to comply with the reccomendations for * "standard" constructors in the {@code Map} interface.</small> * * @param pContents the map whose mappings are to be placed in this map. * May be {@code null}. * * @see #LRUHashMap(java.util.Map, int) */ public LRUHashMap(Map<? extends K, ? extends V> pContents) { super(16, .75f, true); putAll(pContents); }
/** * Sets the maximum number of elements in this map. * * If the current size is greater than the new max size, the map will be * trimmed to fit the new max size constraint. * * @see #removeLRU() * * @param pMaxSize new size limit */ public void setMaxSize(int pMaxSize) { if (pMaxSize < 0) { throw new IllegalArgumentException("max size must be positive"); } maxSize = pMaxSize; while(size() > maxSize) { removeLRU(); } }
/** * Creates an LRUHashMap with initial mappings from the given map, * and the given max size. * * @param pContents the map whose mappings are to be placed in this map. * May be {@code null}. * @param pMaxSize size limit */ public LRUHashMap(Map<? extends K, ? extends V> pContents, int pMaxSize) { super(16, .75f, true); setMaxSize(pMaxSize); putAll(pContents); }
/** * Removes the least recently used mapping(s) from this map. * <p> * How many mappings are removed from the map, is controlled by the * trim factor. * In any case, at least one mapping will be removed. * * @see #getTrimFactor() */ public void removeLRU() { int removeCount = (int) Math.max((size() * trimFactor), 1); Iterator<Map.Entry<K, V>> entries = entrySet().iterator(); while ((removeCount--) > 0 && entries.hasNext()) { entries.next(); entries.remove(); } } }
/** * Creates an LRUHashMap with the given max size. * * @param pMaxSize size limit */ public LRUHashMap(int pMaxSize) { super(16, .75f, true); setMaxSize(pMaxSize); }
/** * Creates an LRUHashMap with initial mappings from the given map, * and default max size (1000 entries). * * <small>This is constructor is here to comply with the reccomendations for * "standard" constructors in the {@code Map} interface.</small> * * @param pContents the map whose mappings are to be placed in this map. * May be {@code null}. * * @see #LRUHashMap(java.util.Map, int) */ public LRUHashMap(Map<? extends K, ? extends V> pContents) { super(16, .75f, true); putAll(pContents); }
/** * always returns {@code false}, and instead invokes {@code removeLRU()} * if {@code size >= maxSize}. */ protected boolean removeEldestEntry(Map.Entry<K, V> pEldest) { // NOTE: As removeLRU() may remove more than one entry, this is better // than simply removing the eldest entry. if (size() >= maxSize) { removeLRU(); } return false; }
/** * Creates an LRUHashMap with initial mappings from the given map, * and the given max size. * * @param pContents the map whose mappings are to be placed in this map. * May be {@code null}. * @param pMaxSize size limit */ public LRUHashMap(Map<? extends K, ? extends V> pContents, int pMaxSize) { super(16, .75f, true); setMaxSize(pMaxSize); putAll(pContents); }
/** * Removes the least recently used mapping(s) from this map. * <p> * How many mappings are removed from the map, is controlled by the * trim factor. * In any case, at least one mapping will be removed. * * @see #getTrimFactor() */ public void removeLRU() { int removeCount = (int) Math.max((size() * mTrimFactor), 1); Iterator<Map.Entry<K, V>> entries = entrySet().iterator(); while ((removeCount--) > 0 && entries.hasNext()) { entries.next(); entries.remove(); } } }
/** * Creates an LRUHashMap with the given max size. * * @param pMaxSize size limit */ public LRUHashMap(int pMaxSize) { super(16, .75f, true); setMaxSize(pMaxSize); }
/** * Creates an LRUHashMap with initial mappings from the given map, * and default max size (1000 entries). * * <small>This is constructor is here to comply with the reccomendations for * "standard" constructors in the {@code Map} interface.</small> * * @param pContents the map whose mappings are to be placed in this map. * May be {@code null}. * * @see #LRUHashMap(java.util.Map, int) */ public LRUHashMap(Map<? extends K, ? extends V> pContents) { super(16, .75f, true); putAll(pContents); }