public class DelegatingStateRepository<V> extends java.lang.Object implements StateRepository<V>
| Constructor and Description |
|---|
DelegatingStateRepository(StateRepository<V> delegate) |
| Modifier and Type | Method and Description |
|---|---|
void |
clear()
Removes all of the mappings from this repository (optional operation).
|
void |
close() |
java.util.Optional<V> |
compute(java.lang.String key,
java.util.function.BiFunction<? super java.lang.String,? super java.util.Optional<V>,? extends V> remappingFunction)
Attempts to compute a mapping for the specified key and its current
mapped value (or
null if there is no current mapping). |
java.util.Optional<V> |
get(java.lang.String key)
Returns the optional value to which the specified key is mapped,
or
Optional.empty() if this repository contains no mapping for the key. |
com.google.common.collect.ImmutableSet<java.lang.String> |
keySet()
/**
Returns an immutable set of the keys in this repository.
|
java.util.Optional<V> |
put(java.lang.String key,
V value)
Associates the specified value with the specified key in this repository.
|
java.util.Optional<V> |
remove(java.lang.String key)
Removes the mapping for a key from this repository if it is present.
|
long |
size()
Returns the number of key-value mappings in this repository.
|
public DelegatingStateRepository(StateRepository<V> delegate)
public java.util.Optional<V> compute(java.lang.String key, java.util.function.BiFunction<? super java.lang.String,? super java.util.Optional<V>,? extends V> remappingFunction)
StateRepositorynull if there is no current mapping). For
example, to either create or append a String msg to a value
mapping:
repository.compute(key, (k, v) -> (v == null) ? msg : v.concat(msg))
If the function returns null, the mapping is removed (or
remains absent if initially absent). If the function itself throws an
(unchecked) exception, the exception is rethrown, and the current mapping
is left unchanged.
The default implementation is equivalent to performing the following
steps for this repository, then returning the current value or
null if absent:
OptionalV> oldValue = repository.get(key);
V newValue = remappingFunction.apply(key, oldValue);
if (!oldValue.isEmpty()) {
if (newValue != null)
repository.put(key, newValue);
else
repository.remove(key);
} else {
if (newValue != null)
repository.put(key, newValue);
else
return Optional.empty();
}
compute in interface StateRepository<V>key - key with which the specified value is to be associatedremappingFunction - the function to compute a valuepublic java.util.Optional<V> put(java.lang.String key, V value)
StateRepositorym.get(k) would return
a non-empty value.)put in interface StateRepository<V>key - key with which the specified value is to be associatedvalue - value to be associated with the specified keypublic java.util.Optional<V> remove(java.lang.String key)
StateRepository(key==null ? k==null : key.equals(k)), that mapping
is removed. (The repository can contain at most one such mapping.)
Returns the optional value to which this repository previously associated the key, or Optional.empty() if the repository contained no mapping for the key.
The repository will not contain a mapping for the specified key once the call returns.
remove in interface StateRepository<V>key - key whose mapping is to be removed from the repositorypublic void clear()
StateRepositoryclear in interface StateRepository<V>public java.util.Optional<V> get(java.lang.String key)
StateRepositoryOptional.empty() if this repository contains no mapping for the key.
More formally, if this repository contains a mapping from a key
k to a value v such that (key==null ? k==null :
key.equals(k)), then this method returns Optional.of(v); otherwise
it returns Optional.empty(). (There can be at most one such mapping.)
get in interface StateRepository<V>key - the key whose associated value is to be returnedOptional.empty() if this repository contains no mapping for the keypublic com.google.common.collect.ImmutableSet<java.lang.String> keySet()
StateRepositorykeySet in interface StateRepository<V>public long size()
StateRepositorysize in interface StateRepository<V>public void close()
throws java.lang.Exception
close in interface StateRepository<V>close in interface java.lang.AutoCloseablejava.lang.Exception