K
- public abstract class AbstractIDLeaseMap<K extends Lease> extends AbstractMap<K,Long> implements LeaseMap<K,Long>
Lease
interface:
In the real world, when a Lease is renewed, a new Lease contract document
is issued, however when an electronic Lease is renewed the Lease expiry
date is changed and the record of the previous Lease is lost. Ideally the
renew method would return a new Lease.
Current Lease implementations rely on a Uuid
to represents the lease,
the expiry date is not included the equals or hashCode calculations. For this
reason, two Lease objects, one expired and one valid, may be equal, this
is undesirable.
The Lease interface doesn't specify a contract for equals or hashCode,
all Lease implementations are also mutable, previous implementations
of LeaseMap
used Leases as keys.
AbstractIDLeaseMap uses only the ID
, usually a Uuid
provided by a Lease for internal map keys, if ID
is not implemented
then the Lease itself is used as the key.
Both Lease keys and Long values are actually stored internally as values
referred to by ID keys, allowing Lease implementations to either not override
hashCode and equals object methods or allow implementations that more
accurately model reality.
This implementation is thread safe, concurrent and doesn't require external
synchronization.AbstractMap.SimpleEntry<K,V>, AbstractMap.SimpleImmutableEntry<K,V>
Modifier | Constructor and Description |
---|---|
protected |
AbstractIDLeaseMap()
Constructor for subclasses.
|
Modifier and Type | Method and Description |
---|---|
boolean |
containsKey(Object key)
Determines whether the ID of the key matches the ID of another key
in the map.
|
boolean |
containsValue(Object value) |
Set<Map.Entry<K,Long>> |
entrySet() |
Long |
get(Object key) |
Long |
put(K key,
Long value)
This implementation will place a new key value pair association in the map,
or it will replace both the key and the value if an equivalent association
currently exists in the map.
|
Long |
remove(Object key) |
clear, clone, equals, hashCode, isEmpty, keySet, putAll, size, toString, values
finalize, getClass, notify, notifyAll, wait, wait, wait
cancelAll, canContainKey, renewAll
clear, compute, computeIfAbsent, computeIfPresent, equals, forEach, getOrDefault, hashCode, isEmpty, keySet, merge, putAll, putIfAbsent, remove, replace, replace, replaceAll, size, values
public boolean containsValue(Object value)
containsValue
in interface Map<K extends Lease,Long>
containsValue
in class AbstractMap<K extends Lease,Long>
public boolean containsKey(Object key)
containsKey
in interface Map<K extends Lease,Long>
containsKey
in class AbstractMap<K extends Lease,Long>
key
- public Long put(K key, Long value)
Copyright © 2016–2018. All rights reserved.