public final class ExpiryFolder extends Object
get(Object)
method.
Listeners are supported. Listeners are added using the
addListener(ExpiryListener)
method and removed using the
removeListener(ExpiryListener)
method. If a listener is registered
multiple times, it will receive the events multiple times as well. And it
will have to be removed multiple times as well.
This class is thread-safe.
Constructor and Description |
---|
ExpiryFolder(String name,
ExpiryStrategy strategy)
Constructs a new
ExpiryFolder with the specified name and
strategy. |
Modifier and Type | Method and Description |
---|---|
void |
addListener(ExpiryListener listener)
Adds the specified object as a listener for expiry events.
|
void |
copy(ExpiryFolder newFolder)
Copies the entries of this
ExpiryFolder into another one. |
boolean |
equals(Object obj)
Checks whether this object is considered equal to the argument.
|
Object |
find(Object key)
Finds the value associated with a key.
|
Object |
get(Object key)
Gets the value associated with a key and extends the lifetime of the
matching entry, if there was a match.
|
String |
getName()
Returns the name given to this expiry folder.
|
ExpiryStrategy |
getStrategy()
Returns the strategy associated with this folder.
|
int |
hashCode()
Returns a hash code value for the object.
|
void |
put(Object key,
Object value)
Associates the specified key with the specified value.
|
Object |
remove(Object key)
Removes the specified key from this folder.
|
void |
removeListener(ExpiryListener listener)
Removes the specified object as a listener for expiry events.
|
int |
size()
Gets the number of entries.
|
String |
toString()
Returns a textual representation of this object.
|
public ExpiryFolder(String name, ExpiryStrategy strategy) throws IllegalArgumentException, IllegalStateException
ExpiryFolder
with the specified name and
strategy. When the strategy is stopped (see
ExpiryStrategy.stop()
then this folder becomes invalid and can
no longer be used.name
- description of this folder, to be used in log and exception messages,
not null
.strategy
- the strategy that should be applied, not null
.IllegalArgumentException
- if name == null || strategy == null
.IllegalStateException
- if the strategy is already stopped.public boolean equals(Object obj)
equals
in class Object
obj
- the object to compare with.true
if this object is considered equal to
obj
, or false
otherwise.Object.equals(Object)
public int hashCode()
hashCode
in class Object
Object.hashCode()
,
equals(Object)
public String getName()
null
.public void addListener(ExpiryListener listener) throws IllegalStateException, IllegalArgumentException
listener
- the listener to be registered, cannot be null
.IllegalStateException
- if the associated ExpiryStrategy
has stopped already.IllegalArgumentException
- if listener == null
.public void removeListener(ExpiryListener listener) throws IllegalStateException, IllegalArgumentException
If the listener cannot be found, then nothing happens.
listener
- the listener to be unregistered, cannot be null
.IllegalStateException
- if the associated ExpiryStrategy
has stopped already.IllegalArgumentException
- if listener == null
.public int size() throws IllegalStateException
IllegalStateException
- if the associated ExpiryStrategy
has stopped already.public Object get(Object key) throws IllegalStateException, IllegalArgumentException
The more recently the specified entry was accessed, the faster the lookup.
key
- the key to lookup, cannot be null
.null
if
and only if this folder does not contain an entry with the specified
key.IllegalStateException
- if the associated ExpiryStrategy
has stopped already.IllegalArgumentException
- if key == null
.public Object find(Object key) throws IllegalStateException, IllegalArgumentException
The more recently the specified entry was accessed, the faster the lookup.
key
- the key to lookup, cannot be null
.null
if
and only if this folder does not contain an entry with the specified
key.IllegalStateException
- if the associated ExpiryStrategy
has stopped already.IllegalArgumentException
- if key == null
.public void put(Object key, Object value) throws IllegalStateException, IllegalArgumentException
key
- they key for the entry, cannot be null
.value
- they value for the entry, cannot be null
.IllegalStateException
- if the associated ExpiryStrategy
has stopped already.IllegalArgumentException
- if key == null || value == null
.public Object remove(Object key) throws IllegalStateException, IllegalArgumentException
key
- the key for the entry, cannot be null
.null
if and only if this folder does not contain an entry with the
specified key.IllegalStateException
- if the associated ExpiryStrategy
has stopped already.IllegalArgumentException
- if key == null
.public void copy(ExpiryFolder newFolder) throws IllegalStateException, IllegalArgumentException
ExpiryFolder
into another one.
This method does not perform a deep copy, so if a key is added or
removed, both folders will be modified.newFolder
- the new folder where the entries should be copied into,
cannot be null
, cannot be this
.IllegalStateException
- if the associated ExpiryStrategy
has stopped already.IllegalArgumentException
- if newFolder == null
or newFolder == this
or if the precision of newFolder
is not the same as for
this ExpiryFolder
.public ExpiryStrategy getStrategy() throws IllegalStateException
null
.IllegalStateException
- if the associated strategy has already stopped.See http://www.xins.org/.