public interface NamedAttributeAccess<T> extends AttributeAccess<T>
This style is useful if you have a few product types.
The usage:
ProductVariant variant = getProductVariantSomeHow(); Optional<LocalizedString> longDescription = variant.findAttribute(TShirt.longDescription());
See the test code.
The declaration:
public class TShirt {
public static NamedAttributeAccess<LocalizedString> longDescription() {
return AttributeAccess.ofLocalizedString().ofName("longDescription");
}
}
See the test code.
This style is useful if you have a few product types.
The usage:
ProductVariant variant = getProductVariantSomeHow(); Optional<LocalizedString> longDescription = variant.findAttribute(TShirt.LONG_DESCRIPTION);
See the test code.
The declaration:
public class TShirt {
public static final NamedAttributeAccess<LocalizedString> LONG_DESCRIPTION = AttributeAccess.ofLocalizedString().ofName("longDescription");
}
See the test code.
This is useful if you have a hierarchy of product types. It uses default implementations for interfaces to simulate multiple inheritance.
The usage:
ProductVariant variant = getProductVariantSomeHow(); Optional<LocalizedString> longDescription = variant.findAttribute(TShirt.attributes().longDescription());
See the test code.
The declaration:
Create groups of attributes:
public interface WithLongDescription {
default NamedAttributeAccess<LocalizedString> longDescription() {
return AttributeAccess.ofLocalizedString().ofName("longDescription");
}
}
See the test code.
public interface WithColor {
default NamedAttributeAccess<String> hexColor() {
return AttributeAccess.ofString().ofName("hex-color");
}
default NamedAttributeAccess<Double> rgb() {
return AttributeAccess.ofDouble().ofName("rgb");
}
}
See the test code.
public interface WithPromoMoney {
default NamedAttributeAccess<MonetaryAmount> promoMoney() {
return AttributeAccess.ofMoney().ofName("promo-money");
}
}
See the test code.
Mixin the the attributes:
public final class TShirt implements WithPromoMoney, WithLongDescription, WithColor {
public static TShirt attributes() {
return new TShirt();
}
}
See the test code.
Modifier and Type | Method and Description |
---|---|
AttributeDraft |
draftOf(T value) |
String |
getName() |
Attribute |
valueOf(T input) |
attributeMapper, canHandle, ofBoolean, ofBooleanSet, ofCategoryReference, ofCategoryReferenceSet, ofChannelReference, ofChannelReferenceSet, ofDate, ofDateSet, ofDateTime, ofDateTimeSet, ofDouble, ofDoubleSet, ofEnumValue, ofEnumValueSet, ofInteger, ofIntegerSet, ofJsonNode, ofLocalDate, ofLocalDateSet, ofLocalizedEnumValue, ofLocalizedEnumValueSet, ofLocalizedString, ofLocalizedStringSet, ofLocalTime, ofLocalTimeSet, ofLong, ofLongSet, ofMoney, ofMoneySet, ofName, ofNested, ofNestedSet, ofProductReference, ofProductReferenceSet, ofProductTypeReference, ofProductTypeReferenceSet, ofString, ofStringSet, ofText, ofTextSet, ofTime, ofTimeSet, ofZonedDateTime, ofZonedDateTimeSet
String getName()
AttributeDraft draftOf(T value)