Record Class RewritingDocProperty<I,O>
- Type Parameters:
I- the type of the input property the actual read/write calls are delegated to.O- the output type after passing the values through the convert functions.- Record Components:
upstream- the upstream doc property to delegate all method calls to.readRewriteFunction- the function to apply when a non-null value was read from a document.writeRewriteFunction- the function to apply when a non-null value is written to a document, can be null.
- All Implemented Interfaces:
DocProperty<O>
- Since:
- 4.0
-
Field Summary
FieldsModifier and TypeFieldDescriptionThe field for thereadRewriteFunctionrecord component.private final @NonNull DocProperty<I> The field for theupstreamrecord component.The field for thewriteRewriteFunctionrecord component. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionWraps this property in a new property that makes any write operation with this property throw an exception.final booleanIndicates whether some other object is "equal to" this one.final inthashCode()Returns a hash code value for this object.key()Get the key of the member that is read from/written to a document.Called to read the value of this property from the given document.booleanreadOnly()Get if this property only supports being read from a document but not being written to one.Returns the value of thereadRewriteFunctionrecord component.final StringtoString()Returns a string representation of this record class.upstream()Returns the value of theupstreamrecord component.withDefault(O def) Wraps this property to make read and write operations set a default value in case the given value is either absent (not appended to the document) or set tonull.<V> @NonNull DocProperty<V> withReadRewrite(@NonNull Function<O, V> rewriteFunction) Wraps this property to apply a rewrite function when reading the property from a document.<V> @NonNull DocProperty<V> withReadWriteRewrite(@NonNull Function<O, V> readRewriteFunction, @Nullable Function<V, O> writeRewriteFunction) Wraps this property to apply a rewrite function when reading and writing the property from/to a document.Returns the value of thewriteRewriteFunctionrecord component.writeTo(Document.Mutable document, O value) Writes the given value into the given document.
-
Field Details
-
upstream
The field for theupstreamrecord component. -
readRewriteFunction
-
writeRewriteFunction
-
-
Constructor Details
-
RewritingDocProperty
RewritingDocProperty(@NonNull @NonNull DocProperty<I> upstream, @NonNull @NonNull Function<I, O> readRewriteFunction, @Nullable @Nullable Function<O, I> writeRewriteFunction) Creates an instance of aRewritingDocPropertyrecord class.- Parameters:
upstream- the value for theupstreamrecord componentreadRewriteFunction- the value for thereadRewriteFunctionrecord componentwriteRewriteFunction- the value for thewriteRewriteFunctionrecord component
-
-
Method Details
-
key
-
readOnly
public boolean readOnly()Get if this property only supports being read from a document but not being written to one.- Specified by:
readOnlyin interfaceDocProperty<I>- Returns:
- true if this property is read-only, false otherwise.
-
asReadOnly
Wraps this property in a new property that makes any write operation with this property throw an exception. Read operations will be delegated to the property this method is being called on.If this property is already read-only the current property is returned without wrapping.
- Specified by:
asReadOnlyin interfaceDocProperty<I>- Returns:
- a property that wraps this property to make it read-only.
-
withDefault
Wraps this property to make read and write operations set a default value in case the given value is either absent (not appended to the document) or set tonull. Read and write operations are delegated to the property this method is being called on.If this property already has a default and the given default is the same as current one (as defined by
==) the current property is returned without wrapping.- Specified by:
withDefaultin interfaceDocProperty<I>- Parameters:
def- the default value to use for the property.- Returns:
- a property that wraps this property and sets a default value during read and write operations.
-
withReadRewrite
@NonNull public <V> @NonNull DocProperty<V> withReadRewrite(@NonNull @NonNull Function<O, V> rewriteFunction) Wraps this property to apply a rewrite function when reading the property from a document. The parsed type of this property is passed to the function and returned as the new property value. Null values are not passed to the function and returned without processing.Note: as this method only sets a function to rewrite while reading the value, the returned property will be read-only as values passed for writing cannot be converted. Use
DocProperty.withReadWriteRewrite(Function, Function)to set a function that is called during writing as well.- Specified by:
withReadRewritein interfaceDocProperty<I>- Type Parameters:
V- the type of value that is the result of the value convert process.- Parameters:
rewriteFunction- the rewrite function to call when reading the value from a document.- Returns:
- a read-only property that wraps this property and applies the given rewrite function when reading.
-
withReadWriteRewrite
@NonNull public <V> @NonNull DocProperty<V> withReadWriteRewrite(@NonNull @NonNull Function<O, V> readRewriteFunction, @Nullable @Nullable Function<V, O> writeRewriteFunction) Wraps this property to apply a rewrite function when reading and writing the property from/to a document. The parsed type of this property is passed to the function and returned/written as the new property value. Null values are not passed to the function and returned without processing.Note: if the call to this method only sets a function to rewrite while reading the value (setting the rewrite function for reads to
null), the returned property will be read-only as values passed for writing cannot be converted.- Specified by:
withReadWriteRewritein interfaceDocProperty<I>- Type Parameters:
V- the type of value that is the result of the value convert process.- Parameters:
readRewriteFunction- the rewrite function to call when reading the value from a document.writeRewriteFunction- the rewrite function to call when writing the value to a document, can be null.- Returns:
- a property that wraps this property and applies the given rewrite function when reading or writing.
-
readFrom
Called to read the value of this property from the given document.- Specified by:
readFromin interfaceDocProperty<I>- Parameters:
document- the document to read the value from.- Returns:
- the parsed value from the document, or null if the value is not present.
-
writeTo
@NonNull public @NonNull DocProperty<O> writeTo(@NonNull Document.Mutable document, @Nullable O value) Writes the given value into the given document.- Specified by:
writeToin interfaceDocProperty<I>- Parameters:
document- the document to write the value to.value- the value to write.- Returns:
- the same property as used to call the method, for chaining.
-
toString
-
hashCode
-
equals
Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. All components in this record class are compared withObjects::equals(Object,Object). -
upstream
-
readRewriteFunction
Returns the value of thereadRewriteFunctionrecord component.- Returns:
- the value of the
readRewriteFunctionrecord component
-
writeRewriteFunction
Returns the value of thewriteRewriteFunctionrecord component.- Returns:
- the value of the
writeRewriteFunctionrecord component
-