Methods Summary |
---|
public void | clear()Removes all mappings from this pool.
synchronized (this) {
_map.clear();
_keyList.clear();
}
|
public boolean | containsKey(java.lang.Object key)Returns true if this pool contains mapping for the specified key.
return _map.containsKey(key);
|
public boolean | containsValue(java.lang.Object val)Returns true if this pool contains mapping for the specified value.
return _map.containsValue(val);
|
public java.lang.Object | get(java.lang.Object key)Returns the object for the given key.
return _map.get(key);
|
public int | getMaxSize()Returns the maximum number of mappings allowed in this pool.
return _maxSizeAllowed;
|
public java.lang.String | getName()Returns the name of the pool.
return _name;
|
public java.lang.Object | put(java.lang.Object key, java.lang.Object val)Adds the object to the pool. If pool size is greater
than the max allowed, the oldest entry is removed
from the pool.
if ((key == null) && (val == null)) {
throw new IllegalArgumentException();
}
Object oldVal = null;
synchronized (this) {
oldVal = _map.put(key, val);
_keyList.add(key);
// remove the extra entry from the pool
if (_keyList.size() > _maxSizeAllowed) {
Object rkey = _keyList.remove(0);
assert (rkey != null);
Object rval = _map.remove(rkey);
assert (rval != null);
}
}
return oldVal;
|
public java.lang.Object | remove(java.lang.Object key)Removes this keyed entry from the pool.
Object val = null;
synchronized (this) {
_keyList.remove(key);
val = _map.remove(key);
}
return val;
|
public void | resize(int size)Resets the max size of the pool. If new size is less than current
size, all extra entries in the pool are removed.
if (size < 1) {
return;
}
if (size == _maxSizeAllowed) {
// do nothing
} else if (size > _maxSizeAllowed) {
synchronized (this) {
_maxSizeAllowed = size;
}
} else {
// remove the extra entries from the pool
synchronized (this) {
int currentSize = _map.size();
int diff = currentSize - size;
// remove extra entries if current size is bigger than diff
for (int i=0; i<diff; i++) {
Object key = _keyList.get(i);
assert (key != null);
if (key != null) {
Object val = _map.remove(key);
assert (val != null);
}
}
for(int i=0; i <diff; i++) {
_keyList.remove(0);
}
_maxSizeAllowed = size;
}
}
|
public int | size()Returns the number of mappings in this pool.
return _map.size();
|
public java.util.Collection | values()Returns a collection view of the values contained in this pool.
return _map.values();
|