/** Setter for property maximumSize. * @param maximumSize New value of property maximumSize. */ public void setMaximumSize(int maximumSize) { this.maximumSize = maximumSize; while (size() > maximumSize) { removeLRU(); } }
/** Setter for property maximumSize. * @param maximumSize New value of property maximumSize. */ public void setMaximumSize(int maximumSize) { this.maximumSize = maximumSize; while (size() > maximumSize) { removeLRU(); } }
public void writeExternal( ObjectOutput out ) throws IOException { out.writeInt( maximumSize ); out.writeInt( size() ); for( Iterator iterator = keySet().iterator(); iterator.hasNext(); ) { Object key = iterator.next(); out.writeObject( key ); // be sure to call super.get(key), or you're likely to // get infinite promotion recursion Object value = super.get( key ); out.writeObject( value ); } }
public void writeExternal( ObjectOutput out ) throws IOException { out.writeInt( maximumSize ); out.writeInt( size() ); for( Iterator iterator = keySet().iterator(); iterator.hasNext(); ) { Object key = iterator.next(); out.writeObject( key ); // be sure to call super.get(key), or you're likely to // get infinite promotion recursion Object value = super.get( key ); out.writeObject( value ); } }
/** * <p>Removes the key and its Object from the Map.</p> * * <p>(Note: this may result in the "Least Recently Used" * object being removed from the Map. In that case, * the removeLRU() method is called. See javadoc for * removeLRU() for more details.)</p> * * @param key Key of the Object to add. * @param value Object to add * @return Former value of the key */ public Object put( Object key, Object value ) { int mapSize = size(); Object retval = null; if ( mapSize >= maximumSize ) { // don't retire LRU if you are just // updating an existing key if (!containsKey(key)) { // lets retire the least recently used item in the cache removeLRU(); } } retval = super.put(key,value); return retval; }
/** * <p>Removes the key and its Object from the Map.</p> * * <p>(Note: this may result in the "Least Recently Used" * object being removed from the Map. In that case, * the removeLRU() method is called. See javadoc for * removeLRU() for more details.)</p> * * @param key Key of the Object to add. * @param value Object to add * @return Former value of the key */ public Object put( Object key, Object value ) { int mapSize = size(); Object retval = null; if ( mapSize >= maximumSize ) { // don't retire LRU if you are just // updating an existing key if (!containsKey(key)) { // lets retire the least recently used item in the cache removeLRU(); } } retval = super.put(key,value); return retval; }
/** * Confirm that putAll(Map) does not cause the LRUMap * to exceed its maxiumum size. */ public void testPutAll() { LRUMap map2 = new LRUMap(3); map2.put(new Integer(1),"foo"); map2.put(new Integer(2),"foo"); map2.put(new Integer(3),"foo"); HashMap hashMap = new HashMap(); hashMap.put(new Integer(4),"foo"); map2.putAll(hashMap); assertTrue("max size is 3, but actual size is " + map2.size(), map2.size() == 3); assertTrue("map should contain the Integer(4) object", map2.containsKey(new Integer(4))); }
/** * Test that the size of the map is reduced immediately * when setMaximumSize(int) is called */ public void testSetMaximumSize() { LRUMap map = new LRUMap(6); map.put("1","1"); map.put("2","2"); map.put("3","3"); map.put("4","4"); map.put("5","5"); map.put("6","6"); map.setMaximumSize(3); assertTrue("map should have size = 3, but actually = " + map.size(), map.size() == 3); }
public synchronized int size() { return strongReferenceCache.size(); }
public synchronized int size() { return cache.size(); }
/** Setter for property maximumSize. * @param maximumSize New value of property maximumSize. */ public void setMaximumSize(int maximumSize) { this.maximumSize = maximumSize; while (size() > maximumSize) { removeLRU(); } }
/** Setter for property maximumSize. * @param maximumSize New value of property maximumSize. */ public void setMaximumSize(int maximumSize) { this.maximumSize = maximumSize; while (size() > maximumSize) { removeLRU(); } }
/** Setter for property maximumSize. * @param maximumSize New value of property maximumSize. */ public void setMaximumSize(int maximumSize) { this.maximumSize = maximumSize; while (size() > maximumSize) { removeLRU(); } }
/** Setter for property maximumSize. * @param maximumSize New value of property maximumSize. */ public void setMaximumSize(int maximumSize) { this.maximumSize = maximumSize; while (size() > maximumSize) { removeLRU(); } }
/** Setter for property maximumSize. * @param maximumSize New value of property maximumSize. */ public void setMaximumSize(int maximumSize) { this.maximumSize = maximumSize; while (size() > maximumSize) { removeLRU(); } }
public void writeExternal( ObjectOutput out ) throws IOException { out.writeInt( maximumSize ); out.writeInt( size() ); for( Iterator iterator = keySet().iterator(); iterator.hasNext(); ) { Object key = iterator.next(); out.writeObject( key ); // be sure to call super.get(key), or you're likely to // get infinite promotion recursion Object value = super.get( key ); out.writeObject( value ); } }
public void writeExternal( ObjectOutput out ) throws IOException { out.writeInt( maximumSize ); out.writeInt( size() ); for( Iterator iterator = keySet().iterator(); iterator.hasNext(); ) { Object key = iterator.next(); out.writeObject( key ); // be sure to call super.get(key), or you're likely to // get infinite promotion recursion Object value = super.get( key ); out.writeObject( value ); } }
public void writeExternal( ObjectOutput out ) throws IOException { out.writeInt( maximumSize ); out.writeInt( size() ); for( Iterator iterator = keySet().iterator(); iterator.hasNext(); ) { Object key = iterator.next(); out.writeObject( key ); // be sure to call super.get(key), or you're likely to // get infinite promotion recursion Object value = super.get( key ); out.writeObject( value ); } }
public void writeExternal( ObjectOutput out ) throws IOException { out.writeInt( maximumSize ); out.writeInt( size() ); for( Iterator iterator = keySet().iterator(); iterator.hasNext(); ) { Object key = iterator.next(); out.writeObject( key ); // be sure to call super.get(key), or you're likely to // get infinite promotion recursion Object value = super.get( key ); out.writeObject( value ); } }
public void writeExternal( ObjectOutput out ) throws IOException { out.writeInt( maximumSize ); out.writeInt( size() ); for( Iterator iterator = keySet().iterator(); iterator.hasNext(); ) { Object key = iterator.next(); out.writeObject( key ); // be sure to call super.get(key), or you're likely to // get infinite promotion recursion Object value = super.get( key ); out.writeObject( value ); } }