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.Modifier and Type | Class and Description |
---|---|
private static class |
AbstractIDLeaseMap.LeaseEntry<K extends Lease>
The logic behind this Entry is that the identity which maintains strong
references to the key and value will not be added to the set or leaseMap
if it's already present.
|
AbstractMap.SimpleEntry<K,V>, AbstractMap.SimpleImmutableEntry<K,V>
Modifier and Type | Field and Description |
---|---|
private java.util.concurrent.ConcurrentMap<Object,Long> |
durationMap |
private java.util.concurrent.ConcurrentMap<Object,K> |
leaseMap |
private Set<Map.Entry<K,Long>> |
set |
Modifier | Constructor and Description |
---|---|
protected |
AbstractIDLeaseMap()
Constructor for subclasses.
|
Modifier and Type | Method and Description |
---|---|
(package private) void |
checkKey(Object key) |
(package private) void |
checkValue(Object value) |
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) |
private Object |
getIdentity(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
private final java.util.concurrent.ConcurrentMap<Object,K extends Lease> leaseMap
private final java.util.concurrent.ConcurrentMap<Object,Long> durationMap
void checkKey(Object key) throws IllegalArgumentException
IllegalArgumentException
void checkValue(Object value) throws IllegalArgumentException
IllegalArgumentException
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 2007-2013, multiple authors.
Licensed under the Apache License, Version 2.0, see the NOTICE file for attributions.