Package com.terracottatech.store
Interface ReadWriteRecordAccessor<K extends Comparable<K>>
- Type Parameters:
K
- the key type for the record
- All Superinterfaces:
ReadRecordAccessor<K>
A ReadWriteRecordAccessor provides fine-control over read and write operations on
the record held against the key that was used to create the ReadWriteRecordAccessor.
-
Method Summary
Modifier and TypeMethodDescriptionCreates a record for the key used to create this ReadWriteRecordAccessor.Creates a record for the key used to create this ReadWriteRecordAccessor.default <T> Optional<T>
Creates a record for the key that was used to create this ReadWriteRecordAccessor.default <T> Optional<T>
Creates a record for the key that was used to create this ReadWriteRecordAccessor.delete()
Deletes a record held against the key used to create this ReadWriteRecordAccessor.default <T> Optional<T>
Deletes a record held against the key used to create this ReadWriteRecordAccessor.Read and write operations on the returned ConditionalReadWriteRecordAccessor will have the supplied predicate applied to the record held against the key used to create this ReadWriteRecordAccessor.update
(UpdateOperation<? super K> transform) Updates a record held against the key used to create this ReadWriteRecordAccessor.default <T> Optional<T>
update
(UpdateOperation<? super K> transform, BiFunction<? super Record<K>, ? super Record<K>, T> mapper) Updates a record held against the key used to create this ReadWriteRecordAccessor.default void
Ensures that the record has the supplied cells.default void
upsert
(UpdateOperation<K> update) Apply the given update against this record or the empty record if no record exists.default void
Ensures that the record has the supplied cells.Methods inherited from interface com.terracottatech.store.ReadRecordAccessor
exists, getKey, read
-
Method Details
-
iff
Read and write operations on the returned ConditionalReadWriteRecordAccessor will have the supplied predicate applied to the record held against the key used to create this ReadWriteRecordAccessor. If the predicate returns false, the operation will proceed as if there is no record against the key. If the predicate returns true, the operation will proceed as normal.- Specified by:
iff
in interfaceReadRecordAccessor<K extends Comparable<K>>
- Parameters:
predicate
- the predicate to apply to the record held against the key used to create this ReadWriteRecordAccessor.- Returns:
- A ConditionalReadWriteRecordAccessor that provides conditional read and write operations on the record held against the key used to create this ReadWriteRecordAccessor. Any operations using this ConditionalReadWriteRecordAccessor will have the supplied predicate applied to the record held against the key and, if the predicate returns true, the record will be treated as present, otherwise any operation will act as if there is no record against the key.
-
upsert
Ensures that the record has the supplied cells. If no record exists, a record is created. If there is an existing record then its cells are set to be those supplied. Any cells that were on an existing record that were not in the set of cells supplied will no longer be on the record at the time that the operation completes.- Parameters:
cells
- the cells to ensure are on the record
-
upsert
Ensures that the record has the supplied cells. If no record exists, a record is created. If there is an existing record then its cells are set to be those supplied. Any cells that were on an existing record that were not in the set of cells supplied will no longer be on the record at the time that the operation completes.- Parameters:
cells
- a non-null
Iterable
supplying the cells to ensure are on the record- Throws:
NullPointerException
- ifcells
isnull
-
upsert
Apply the given update against this record or the empty record if no record exists.If there is an existing record then it is updated using the supplied operation. If no record exists, a record is created whose cells are the result of applying the update against an empty record instance.
- Parameters:
update
- a non-null
UpdateOperation<K>
to apply to the record- Throws:
NullPointerException
- ifupdate
isnull
-
add
Creates a record for the key that was used to create this ReadWriteRecordAccessor. If a record is created an empty Optional is returned. If a record existed already, an Optional containing the result of applying the supplied mapper function to the existing record is returned. An exception thrown frommapper
is propagated to the caller of theadd
method. The status of the add operation is unaffected by the failure ofmapper
.- Type Parameters:
T
- the type returned by the function defined in the mapper parameter.- Parameters:
mapper
- function to apply to the record held against the key used to create this ReadWriteRecordAccessor, if such a record existed already.cells
- cells which form the record- Returns:
- an empty Optional if the record was created, otherwise an Optional containing the result of applying the function defined by the mapper parameter to the record that was already held against the key used to create this ReadWriteRecordAccessor.
-
add
Creates a record for the key that was used to create this ReadWriteRecordAccessor. If a record is created an empty Optional is returned. If a record existed already, an Optional containing the result of applying the supplied mapper function to the existing record is returned. An exception thrown frommapper
is propagated to the caller of theadd
method. The status of the add operation is unaffected by the failure ofmapper
.- Type Parameters:
T
- the type returned by the function defined in the mapper parameter.- Parameters:
mapper
- function to apply to the record held against the key used to create this ReadWriteRecordAccessor, if such a record existed already.cells
- a non-null
Iterable
supplying cells which form the record- Returns:
- an empty Optional if the record was created, otherwise an Optional containing the result of applying the function defined by the mapper parameter to the record that was already held against the key used to create this ReadWriteRecordAccessor.
- Throws:
NullPointerException
- ifcells
isnull
-
add
Creates a record for the key used to create this ReadWriteRecordAccessor. If a record is created an empty Optional is returned. If a record existed already, an Optional containing the existing record is returned.- Parameters:
cells
- cells which form the record- Returns:
- an empty Optional if the record was created, otherwise an Optional containing the record that was already held against the key used to create this ReadWriteRecordAccessor.
-
add
Creates a record for the key used to create this ReadWriteRecordAccessor. If a record is created an empty Optional is returned. If a record existed already, an Optional containing the existing record is returned.- Parameters:
cells
- a non-null
Iterable
supplying cells which form the record- Returns:
- an empty Optional if the record was created, otherwise an Optional containing the record that was already held against the key used to create this ReadWriteRecordAccessor.
- Throws:
NullPointerException
- ifcells
isnull
-
update
default <T> Optional<T> update(UpdateOperation<? super K> transform, BiFunction<? super Record<K>, ? super Record<K>, T> mapper) Updates a record held against the key used to create this ReadWriteRecordAccessor. If the record is updated, an Optional containing the result of applying the mapper function is returned. If no record to update was found, an empty Optional is returned. An exception thrown frommapper
is propagated to the caller of theupdate
method. The status of the update operation is unaffected by the failure ofmapper
.- Type Parameters:
T
- the type returned by the function defined in the mapper parameter.- Parameters:
transform
- the mutating transformation to apply to the recordmapper
- 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:
- if a record was held against the key, an Optional containing the result of applying the mapper function to the combination of the record that existed before the update and the record that resulted from the update, otherwise, if there was no record against the key, an empty Optional
-
update
Updates a record held against the key used to create this ReadWriteRecordAccessor. If the record is updated, an Optional containing 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, is returned. If there was no record to update, an empty Optional is returned.- Parameters:
transform
- the mutating transformation to apply to the record- Returns:
- if a record was held against the key, an Optional containing 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, otherwise, if there was no record against the key, an empty Optional
-
delete
Deletes a record held against the key used to create this ReadWriteRecordAccessor. If the record is deleted, an Optional containing the result of applying the mapper function to the deleted record is returned. If there was no record held against the key, an empty Optional is returned.An exception thrown from
mapper
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
- function to apply to the deleted record.- Returns:
- an Optional containing the result of applying the mapper function to the deleted record, or an empty Optional if there was no record held against the key.
-
delete
Deletes a record held against the key used to create this ReadWriteRecordAccessor. If the record is deleted, an Optional containing the deleted record is returned. If there was no record held against the key, an empty Optional is returned.- Returns:
- an Optional containing the record deleted, or an empty Optional if there was no record held against the key.
-