Package com.terracottatech.store
Interface ConditionalReadWriteRecordAccessor<K extends Comparable<K>>
- Type Parameters:
K
- the key type for the record
- All Superinterfaces:
ConditionalReadRecordAccessor<K>
public interface ConditionalReadWriteRecordAccessor<K extends Comparable<K>>
extends ConditionalReadRecordAccessor<K>
A ConditionalReadWriteRecordAccessor provides read and write transformations on a record.
However, those transformations are conditional on the predicate that was used to create the
ConditionalReadWriteRecordAccessor.
-
Method Summary
Modifier and TypeMethodDescriptiondelete()
Deletes the record held against the key used to create this ConditionalReadWriteRecordAccessor, if that record matches the predicate used to create this ConditionalReadWriteRecordAccessor.default <T> Optional<T>
Deletes the record held against the key used to create this ConditionalReadWriteRecordAccessor, if that record matches the predicate used to create this ConditionalReadWriteRecordAccessor.update
(UpdateOperation<? super K> transform) Updates the record held against the key used to create this ConditionalReadWriteRecordAccessor, if that record matches the predicate used to create this ConditionalReadWriteRecordAccessor.default <T> Optional<T>
update
(UpdateOperation<? super K> transform, BiFunction<? super Record<K>, ? super Record<K>, T> bimapper) Updates the record held against the key used to create this ConditionalReadWriteRecordAccessor, if that record matches the predicate used to create this ConditionalReadWriteRecordAccessor.Methods inherited from interface com.terracottatech.store.ConditionalReadRecordAccessor
exists, read, read
-
Method Details
-
update
default <T> Optional<T> update(UpdateOperation<? super K> transform, BiFunction<? super Record<K>, ? super Record<K>, T> bimapper) Updates the record held against the key used to create this ConditionalReadWriteRecordAccessor, if that record matches the predicate used to create this ConditionalReadWriteRecordAccessor. The the function defined in the bimapper parameter is applied to the combination of the record that existed before the update and the record that resulted from the update and the result of this is returned. An exception thrown frombimapper
is propagated to the caller of theupdate
method. The status of the update operation is unaffected by the failure ofbimapper
.- Type Parameters:
T
- the type returned by the function defined in the bimapper parameter.- Parameters:
transform
- the mutating transform to apply to the recordbimapper
- the function to apply to the combination of the record that existed before the update and the record that resulted from the update. The first argument to the apply() method will be the record that existed before the update and the second argument will be the record that resulted from the update.- Returns:
- an Optional containing the mapped result of applying the mutating transform to the record held against the key if it is present and if it also matches the predicate that was used to create this ConditionalReadWriteRecordAccessor, otherwise an empty Optional. If the Optional returned is not empty then it will contain the result of the application of the function defined in the bimapper parameter.
-
update
Updates the record held against the key used to create this ConditionalReadWriteRecordAccessor, if that record matches the predicate used to create this ConditionalReadWriteRecordAccessor.- Parameters:
transform
- the mutating transform to apply to the record- Returns:
- An Optional containing the result of applying the mutating transform to the record held against the key if it is present and if it also matches the predicate that was used to create this ConditionalReadWriteRecordAccessor, otherwise an empty Optional. If the Optional returned is not empty then it will contain a Tuple containing the record that existed before the update in the Tuple's first position and the record that resulted from the update in the Tuple's second position.
-
delete
Deletes the record held against the key used to create this ConditionalReadWriteRecordAccessor, if that record matches the predicate used to create this ConditionalReadWriteRecordAccessor. The the function defined in the mapper parameter is applied to the deleted record and the result of this is returned. An exception thrown frommapper
is propagated to the caller of thedelete
method. The status of the delete operation is unaffected by the failure ofmapper
.- Type Parameters:
T
- the type returned by the function defined in the mapper parameter.- Parameters:
mapper
- the function to apply to the deleted record.- Returns:
- An Optional containing the result of applying the function defined in the mapper parameter to the deleted record if a record was actually deleted, otherwise an empty Optional.
-
delete
Deletes the record held against the key used to create this ConditionalReadWriteRecordAccessor, if that record matches the predicate used to create this ConditionalReadWriteRecordAccessor.- Returns:
- An Optional containing the deleted record if a record was actually deleted, otherwise an empty Optional.
-