Package com.terracottatech.store
Interface ReadRecordAccessor<K extends Comparable<K>>
- Type Parameters:
K
- the key type for the record
- All Known Subinterfaces:
ReadWriteRecordAccessor<K>
public interface ReadRecordAccessor<K extends Comparable<K>>
A ReadRecordAccessor provides fine-control over read operations on
the record held against the key that was used to create the ReadRecordAccessor.
-
Method Summary
Modifier and TypeMethodDescriptiondefault boolean
exists()
Returnstrue
if a record exists for the key used to create this accessor.getKey()
Returns the key that this accessor is against.Read operations on the returned ConditionalReadRecordAccessor will have the supplied predicate applied to the record held against the key used to create this ReadRecordAccessor.<T> Optional<T>
Maps the record held against the key used to create this ReadRecordAccessor.
-
Method Details
-
getKey
K getKey()Returns the key that this accessor is against.- Returns:
- the accessed key
-
iff
Read operations on the returned ConditionalReadRecordAccessor will have the supplied predicate applied to the record held against the key used to create this ReadRecordAccessor. If the predicate returns false, the read will proceed as if there is no record against the key. If the predicate returns true, the read will proceed as normal.- Parameters:
predicate
- the predicate to apply to the record held against the key used to create this ReadRecordAccessor.- Returns:
- A ConditionalReadRecordAccessor that provides conditional read operations on the record held against the key used to create this ReadRecordAccessor. Any reads using this ConditionalReadRecordAccessor will have the supplied predicate applied to the record held against the key and, if the predicate returns true, the record will be read, otherwise any read will act as if there is no record against the key.
-
read
Maps the record held against the key used to create this ReadRecordAccessor. The record is mapped by applying the supplied mapper function and the resulting value is returned.An exception thrown from
mapper
is propagated to the caller of theread
method.- Type Parameters:
T
- the type returned by the function defined in the mapper parameter.- Parameters:
mapper
- the function to apply to the record.- Returns:
- an Optional containing the result of applying the function defined in the mapper parameter to the record held against the key if it is present, otherwise an empty Optional.
-
exists
default boolean exists()Returnstrue
if a record exists for the key used to create this accessor.- Returns:
true
if the record exists.
-