public interface MetadataMap
MetadataKeys, and maps them to persistent or transient (expiring / weak) values.
Transient values will only be removed during map maintenance, which occurs during a housekeeping task running
every minute. Method signatures for the has(MetadataKey) and equivalent remain accurate though.TransientValue| Modifier and Type | Method and Description |
|---|---|
com.google.common.collect.ImmutableMap<MetadataKey<?>,Object> |
asMap()
Returns an immutable view of the backing map
|
void |
cleanup()
Removes expired
TransientValues from this map. |
void |
clear()
Clears the map
|
static MetadataMap |
create() |
<T> void |
forcePut(MetadataKey<T> key,
T value)
Adds a metadata key and corresponding value into this map, removing any previous value if present.
|
<T> void |
forcePut(MetadataKey<T> key,
TransientValue<T> value)
Adds a metadata key and corresponding value into this map, removing any previous value if present.
|
<T> Optional<T> |
get(MetadataKey<T> key)
Gets an optional value for the given key.
|
<T> T |
getOrDefault(MetadataKey<T> key,
T def)
Gets a value for the given key, or returns the default if one isn't present.
|
<T> T |
getOrNull(MetadataKey<T> key)
Gets a value for the given key, or null if one isn't present.
|
<T> T |
getOrPut(MetadataKey<T> key,
Supplier<? extends T> def)
Gets a value for the given key, or puts and returns the default if one isn't present.
|
<T> T |
getOrPutExpiring(MetadataKey<T> key,
Supplier<? extends TransientValue<T>> def)
Gets a value for the given key, or puts and returns the default if one isn't present.
|
boolean |
has(MetadataKey<?> key)
Returns if this map contains the given key, and the types of each key match.
|
<T> boolean |
ifPresent(MetadataKey<T> key,
Consumer<? super T> action)
Attempts to get a value for the given key, and applies the action is present.
|
boolean |
isEmpty()
Returns if the map is empty
|
<T> void |
put(MetadataKey<T> key,
T value)
Adds a metadata key and corresponding value into this map, removing any previous value if present.
|
<T> void |
put(MetadataKey<T> key,
TransientValue<T> value)
Adds a metadata key and corresponding value into this map, removing any previous value if present.
|
<T> boolean |
putIfAbsent(MetadataKey<T> key,
T value)
Adds a metadata key and corresponding value into this map, only if an existing key is not present.
|
<T> boolean |
putIfAbsent(MetadataKey<T> key,
TransientValue<T> value)
Adds a metadata key and corresponding value into this map, only if an existing key is not present.
|
boolean |
remove(MetadataKey<?> key)
Removes the given key from this map
|
@Nonnull static MetadataMap create()
<T> void put(@Nonnull MetadataKey<T> key, @Nonnull T value)
ClassCastException will be
thrown if they do not share the same type, and the existing value will remain.T - the value typekey - the key to putvalue - the value to map against (non null)ClassCastException - if any existing key with the same id has a differing type to the key being add<T> void put(@Nonnull MetadataKey<T> key, @Nonnull TransientValue<T> value)
ClassCastException will be
thrown if they do not share the same type, and the existing value will remain.T - the value typekey - the key to putvalue - the value to map against (non null)ClassCastException - if any existing key with the same id has a differing type to the key being add<T> void forcePut(@Nonnull MetadataKey<T> key, @Nonnull T value)
put(MetadataKey, Object), the existing value if present does not need to have the same type.T - the value typekey - the key to putvalue - the value to map against (non null)<T> void forcePut(@Nonnull MetadataKey<T> key, @Nonnull TransientValue<T> value)
put(MetadataKey, Object), the existing value if present does not need to have the same type.T - the value typekey - the key to putvalue - the value to map against (non null)<T> boolean putIfAbsent(@Nonnull MetadataKey<T> key, @Nonnull T value)
T - the value typekey - the key to putvalue - the value to map against (non null)<T> boolean putIfAbsent(@Nonnull MetadataKey<T> key, @Nonnull TransientValue<T> value)
T - the value typekey - the key to putvalue - the value to map against (non null)@Nonnull <T> Optional<T> get(@Nonnull MetadataKey<T> key)
T - the value typekey - the metadata key to getClassCastException - if there is a key held in the map with the same id but differing type to the given key.<T> boolean ifPresent(@Nonnull MetadataKey<T> key, @Nonnull Consumer<? super T> action)
T - the value typekey - the metadata key to lookupaction - the action to applyClassCastException - if there is a key held in the map with the same id but differing type to the given key.@Nullable <T> T getOrNull(@Nonnull MetadataKey<T> key)
T - the value typekey - the metadata key to getClassCastException - if there is a key held in the map with the same id but differing type to the given key.@Nonnull <T> T getOrDefault(@Nonnull MetadataKey<T> key, @Nullable T def)
T - the value typekey - the metadata key to getdef - the default valueClassCastException - if there is a key held in the map with the same id but differing type to the given key.@Nonnull <T> T getOrPut(@Nonnull MetadataKey<T> key, @Nonnull Supplier<? extends T> def)
T - the value typekey - the metadata key to getdef - the default valueClassCastException - if there is a key held in the map with the same id but differing type to the given key.@Nonnull <T> T getOrPutExpiring(@Nonnull MetadataKey<T> key, @Nonnull Supplier<? extends TransientValue<T>> def)
T - the value typekey - the metadata key to getdef - the default valueClassCastException - if there is a key held in the map with the same id but differing type to the given key.boolean has(@Nonnull MetadataKey<?> key)
key - the key to check forboolean remove(@Nonnull MetadataKey<?> key)
key - the key to removevoid clear()
@Nonnull com.google.common.collect.ImmutableMap<MetadataKey<?>,Object> asMap()
boolean isEmpty()
void cleanup()
TransientValues from this map.
Note that this method does need to be explicitly called - as cleanup happens naturally over time.
Copyright © 2022. All rights reserved.