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