/** * 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(); } } }
/** * 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(); } }
/** * 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; }
/** * 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; }
/** * 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() >= mMaxSize) { 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(); } } }
/** * 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(); } } }
/** * 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(); } } }
/** * 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(); } }
/** * 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(); } }
/** * 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"); } mMaxSize = pMaxSize; while(size() > mMaxSize) { removeLRU(); } }