T
- the class of the immutable item this attribute maps into.B
- the class of the builder for the immutable item this attribute maps into.R
- the class that the value of this attribute converts to.public final class ImmutableAttribute<T,B,R> extends Object
StaticImmutableTableSchema
composes
multiple attributes that map to a common immutable item class.
The recommended way to use this class is by calling
TableSchema.builder(Class, Class)
.
Example:
TableSchema.builder(Customer.class, Customer.Builder.class)
.addAttribute(String.class,
a -> a.name("customer_name").getter(Customer::name).setter(Customer.Builder::name))
// ...
.build();
It's also possible to construct this class on its own using the static builder. Example:
ImmutableAttribute<Customer, Customer.Builder, ?> customerNameAttribute =
ImmutableAttribute.builder(Customer.class, Customer.Builder.class, String.class)
.name("customer_name")
.getter(Customer::name)
.setter(Customer.Builder::name)
.build();
Modifier and Type | Class and Description |
---|---|
static class |
ImmutableAttribute.Builder<T,B,R>
A typed builder for
ImmutableAttribute . |
Modifier and Type | Method and Description |
---|---|
AttributeConverter<R> |
attributeConverter()
A custom
AttributeConverter that will be used to convert this attribute. |
static <T,B,R> ImmutableAttribute.Builder<T,B,R> |
builder(Class<T> itemClass,
Class<B> builderClass,
Class<R> attributeClass)
Constructs a new builder for this class using supplied types.
|
static <T,B,R> ImmutableAttribute.Builder<T,B,R> |
builder(Class<T> itemClass,
Class<B> builderClass,
EnhancedType<R> attributeType)
Constructs a new builder for this class using supplied types.
|
Function<T,R> |
getter()
A function that can get the value of this attribute from a modelled immutable item it composes.
|
String |
name()
The name of this attribute
|
BiConsumer<B,R> |
setter()
A function that can set the value of this attribute on a builder for the immutable modelled item it composes.
|
Collection<StaticAttributeTag> |
tags()
A collection of
StaticAttributeTag associated with this attribute. |
ImmutableAttribute.Builder<T,B,R> |
toBuilder()
Converts an instance of this class to a
ImmutableAttribute.Builder that can be used to modify and reconstruct it. |
EnhancedType<R> |
type()
A
EnhancedType that represents the type of the value this attribute stores. |
public static <T,B,R> ImmutableAttribute.Builder<T,B,R> builder(Class<T> itemClass, Class<B> builderClass, EnhancedType<R> attributeType)
itemClass
- The class of the immutable item that this attribute composes.builderClass
- The class of the builder for the immutable item that this attribute composes.attributeType
- A EnhancedType
that represents the type of the value this attribute stores.public static <T,B,R> ImmutableAttribute.Builder<T,B,R> builder(Class<T> itemClass, Class<B> builderClass, Class<R> attributeClass)
itemClass
- The class of the item that this attribute composes.builderClass
- The class of the builder for the immutable item that this attribute composes.attributeClass
- A class that represents the type of the value this attribute stores.public String name()
public Function<T,R> getter()
public BiConsumer<B,R> setter()
public Collection<StaticAttributeTag> tags()
StaticAttributeTag
associated with this attribute.public EnhancedType<R> type()
EnhancedType
that represents the type of the value this attribute stores.public AttributeConverter<R> attributeConverter()
AttributeConverter
that will be used to convert this attribute.
If no custom converter was provided, the value will be null.public ImmutableAttribute.Builder<T,B,R> toBuilder()
ImmutableAttribute.Builder
that can be used to modify and reconstruct it.Copyright © 2021. All rights reserved.