Class Property<T,V>
- Type Parameters:
T- The object type.V- The value type.
This class provides a flexible, builder-based approach to defining properties on objects, supporting both method-based and field-based access patterns.
Features:
- Type-safe - generic types for object and value types
- Builder-based - fluent API for construction
- Flexible - supports arbitrary consumers and producers that can throw exceptions
- Convenience methods - easy integration with
FieldInfoandMethodInfo - Exception handling - uses
ThrowingFunctionandThrowingConsumer2for exception support
Usage:
See Also:
FieldInfo- Field introspectionMethodInfo- Method introspection- Reflection Package
-
Nested Class Summary
Nested Classes -
Constructor Summary
ConstructorsConstructorDescriptionProperty(ThrowingFunction<T, V> producer, ThrowingConsumer2<T, V> consumer) Constructor. -
Method Summary
Modifier and TypeMethodDescriptionbooleancanRead()Returnstrue if this property can be read.booleancanWrite()Returnstrue if this property can be written.static <T,V> Property.Builder<T, V> create()Creates a new builder for constructing a property.Gets the value from the specified object using the producer (getter).voidSets the value on the specified object using the consumer (setter).
-
Constructor Details
-
Property
Constructor.- Parameters:
producer- The producer function (getter). Can benull .consumer- The consumer function (setter). Can benull .
-
-
Method Details
-
create
Creates a new builder for constructing a property.Example:
Property<MyClass, String>
prop = Property .<MyClass, String>create () .getter(obj ->obj .getName()) .setter((obj ,val ) ->obj .setName(val )) .build();- Type Parameters:
T- The object type.V- The value type.- Returns:
- A new builder instance.
-
get
Gets the value from the specified object using the producer (getter).- Parameters:
object- The object from which to get the value. Must not benull .- Returns:
- The value.
- Throws:
ExecutableException
-
set
Sets the value on the specified object using the consumer (setter).- Parameters:
object- The object on which to set the value. Must not benull .value- The value to set. Can benull .- Throws:
ExecutableException
-
canRead
Returnstrue if this property can be read.- Returns:
true if this property can be read.
-
canWrite
Returnstrue if this property can be written.- Returns:
true if this property can be written.
-