/** * always returns {@code false}, and instead invokes {@code removeLRU()} * if {@code size >= maxSize}. */ protected boolean removeEldestEntry(Entry 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; }
/** * 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(); } }
@Test public void testRemoveLRU() { LRUMap<Integer, String> map2 = new LRUMap<Integer, String>(3); map2.put(1,"foo"); map2.put(2,"foo"); map2.put(3,"foo"); map2.put(4,"foo"); // removes 1 since max size exceeded map2.removeLRU(); // should be Integer(2) assertTrue("Second to last value should exist",map2.get(new Integer(3)).equals("foo")); assertTrue("First value inserted should not exist", map2.get(new Integer(1)) == null); }
/** * always returns {@code false}, and instead invokes {@code removeLRU()} * if {@code size >= maxSize}. */ protected boolean removeEldestEntry(Entry 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(Entry 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(Entry 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; }
/** * 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(); } }
/** * 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(); } }
public void testRemoveLRU() { LRUMap map2 = new LRUMap(3); map2.put(new Integer(1),"foo"); map2.put(new Integer(2),"foo"); map2.put(new Integer(3),"foo"); map2.put(new Integer(4),"foo"); // removes 1 since max size exceeded map2.removeLRU(); // should be Integer(2) assertTrue("Second to last value should exist",map2.get(new Integer(3)).equals("foo")); assertTrue("First value inserted should not exist", map2.get(new Integer(1)) == null); }
public void testRemoveLRU() { LRUMap<Integer, String> map2 = new LRUMap<Integer, String>(3); map2.put(1,"foo"); map2.put(2,"foo"); map2.put(3,"foo"); map2.put(4,"foo"); // removes 1 since max size exceeded map2.removeLRU(); // should be Integer(2) assertTrue("Second to last value should exist",map2.get(new Integer(3)).equals("foo")); assertTrue("First value inserted should not exist", map2.get(new Integer(1)) == null); }
@Test public void testRemoveLRU() { LRUMap<Integer, String> map2 = new LRUMap<Integer, String>(3); map2.put(1,"foo"); map2.put(2,"foo"); map2.put(3,"foo"); map2.put(4,"foo"); // removes 1 since max size exceeded map2.removeLRU(); // should be Integer(2) assertTrue("Second to last value should exist",map2.get(new Integer(3)).equals("foo")); assertTrue("First value inserted should not exist", map2.get(new Integer(1)) == null); }