Record Class DefaultingDocProperty<E>
- Type Parameters:
E- the type which gets read/written by this property.- Record Components:
downstream- the doc property to delegate all operations to (possibly after injecting the default value).def- the default value to inject into the chain if needed, may be null.
- All Implemented Interfaces:
DocProperty<E>
- Since:
- 4.0
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final EThe field for thedefrecord component.private final @NonNull DocProperty<E> The field for thedownstreamrecord component. -
Constructor Summary
ConstructorsConstructorDescriptionDefaultingDocProperty(@NonNull DocProperty<E> downstream, E def) Creates an instance of aDefaultingDocPropertyrecord class. -
Method Summary
Modifier and TypeMethodDescriptionWraps this property in a new property that makes any write operation with this property throw an exception.def()Returns the value of thedefrecord component.Returns the value of thedownstreamrecord component.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.final StringtoString()Returns a string representation of this record class.withDefault(E 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<E, V> rewriteFunction) Wraps this property to apply a rewrite function when reading the property from a document.<V> @NonNull DocProperty<V> withReadWriteRewrite(@NonNull Function<E, V> readRewriteFunction, @Nullable Function<V, E> writeRewriteFunction) Wraps this property to apply a rewrite function when reading and writing the property from/to a document.writeTo(Document.Mutable document, E value) Writes the given value into the given document.
-
Field Details
-
downstream
The field for thedownstreamrecord component. -
def
-
-
Constructor Details
-
DefaultingDocProperty
Creates an instance of aDefaultingDocPropertyrecord class.- Parameters:
downstream- the value for thedownstreamrecord componentdef- the value for thedefrecord 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<E>- 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<E>- 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<E>- 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<E, 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<E>- 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<E, V> readRewriteFunction, @Nullable @Nullable Function<V, E> 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<E>- 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<E>- 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<E> writeTo(@NonNull Document.Mutable document, @Nullable E value) Writes the given value into the given document.- Specified by:
writeToin interfaceDocProperty<E>- 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). -
downstream
Returns the value of thedownstreamrecord component.- Returns:
- the value of the
downstreamrecord component
-
def
-