Class ImmutableAttribute<T,​B,​R>

  • Type Parameters:
    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.

    @ThreadSafe
    public final class ImmutableAttribute<T,​B,​R>
    extends Object
    A class that represents an attribute on an mapped immutable item. A 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();

    • Method Detail

      • builder

        public 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.
        Parameters:
        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.
        Returns:
        A new typed builder for an attribute.
      • builder

        public static <T,​B,​R> ImmutableAttribute.Builder<T,​B,​R> builder​(EnhancedType<T> itemType,
                                                                                                EnhancedType<B> builderType,
                                                                                                EnhancedType<R> attributeType)
        Constructs a new builder for this class using supplied types.
        Parameters:
        itemType - The EnhancedType of the immutable item that this attribute composes.
        builderType - The EnhancedType of the builder for the immutable item that this attribute composes.
        attributeType - A EnhancedType that represents the type of the value this attribute stores.
        Returns:
        A new typed builder for an attribute.
      • builder

        public 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.
        Parameters:
        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.
        Returns:
        A new typed builder for an attribute.
      • name

        public String name()
        The name of this attribute
      • getter

        public Function<T,​R> getter()
        A function that can get the value of this attribute from a modelled immutable item it composes.
      • setter

        public BiConsumer<B,​R> setter()
        A function that can set the value of this attribute on a builder for the immutable modelled item it composes.