All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.sphere.sdk.products.attributes.AttributeAccess Maven / Gradle / Ivy

There is a newer version: 1.0.0-M26
Show newest version
package io.sphere.sdk.products.attributes;

import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.JsonNode;
import io.sphere.sdk.categories.Category;
import io.sphere.sdk.channels.Channel;
import io.sphere.sdk.json.TypeReferences;
import io.sphere.sdk.models.LocalizedEnumValue;
import io.sphere.sdk.models.LocalizedString;
import io.sphere.sdk.models.EnumValue;
import io.sphere.sdk.models.Reference;
import io.sphere.sdk.products.AttributeContainer;
import io.sphere.sdk.products.Product;
import io.sphere.sdk.producttypes.ProductType;

import javax.money.MonetaryAmount;
import java.time.LocalDate;
import java.time.LocalTime;
import java.time.ZonedDateTime;
import java.util.Set;

import static io.sphere.sdk.json.TypeReferences.*;

/**
 *
 * @param  the type of the attribute
 * @see NamedAttributeAccess
 */
public interface AttributeAccess {
    NamedAttributeAccess ofName(String name);

    AttributeMapper attributeMapper();

    boolean canHandle(AttributeDefinition attributeDefinition);

    static AttributeAccess ofBoolean() {
        return AttributeAccessImpl.ofPrimitive(booleanTypeReference(), BooleanType.class);
    }

    static AttributeAccess> ofBooleanSet() {
        return AttributeAccessImpl.ofSet(BooleanType.class, new TypeReference>() {
        });
    }

    static AttributeAccess ofString() {
        return AttributeAccessImpl.ofPrimitive(stringTypeReference(), StringType.class);
    }

    static AttributeAccess> ofStringSet() {
        return AttributeAccessImpl.ofSet(StringType.class, new TypeReference>() {
        });
    }

    static AttributeAccess ofText() {
        return ofString();
    }

    static AttributeAccess> ofTextSet() {
        return ofStringSet();
    }

    static AttributeAccess ofLocalizedString() {
        return AttributeAccessImpl.ofPrimitive(LocalizedString.typeReference(), LocalizedStringType.class);
    }

    static AttributeAccess> ofLocalizedStringSet() {
        return AttributeAccessImpl.ofSet(LocalizedStringType.class, new TypeReference>() {
        });
    }

    static AttributeAccess ofEnumValue() {
        return AttributeAccessImpl.ofEnumLike(EnumValue.typeReference(), EnumType.class);
    }

    static AttributeAccess> ofEnumValueSet() {
        return AttributeAccessImpl.ofEnumLikeSet(EnumType.class, new TypeReference>() {
        });
    }

    static AttributeAccess ofLocalizedEnumValue() {
        return AttributeAccessImpl.ofEnumLike(LocalizedEnumValue.typeReference(), LocalizedEnumType.class);
    }

    static AttributeAccess> ofLocalizedEnumValueSet() {
        return AttributeAccessImpl.ofEnumLikeSet(LocalizedEnumType.class, new TypeReference>() {
        });
    }

    static AttributeAccess ofDouble() {
        return AttributeAccessImpl.ofPrimitive(doubleTypeReference(), NumberType.class);
    }

    static AttributeAccess> ofDoubleSet() {
        return AttributeAccessImpl.ofSet(NumberType.class, new TypeReference>() {
        });
    }

    static AttributeAccess ofInteger() {
        return AttributeAccessImpl.ofPrimitive(integerTypeReference(), NumberType.class);
    }

    static AttributeAccess> ofIntegerSet() {
        return AttributeAccessImpl.ofSet(NumberType.class, new TypeReference>() {
        });
    }

    static AttributeAccess ofLong() {
        return AttributeAccessImpl.ofPrimitive(longTypeReference(), NumberType.class);
    }

    static AttributeAccess> ofLongSet() {
        return AttributeAccessImpl.ofSet(NumberType.class, new TypeReference>() {
        });
    }

    static AttributeAccess ofMoney() {
        return AttributeAccessImpl.ofPrimitive(monetaryAmountTypeReference(), MoneyType.class);
    }

    static AttributeAccess> ofMoneySet() {
        return AttributeAccessImpl.ofSet(MoneyType.class, new TypeReference>() {
        });
    }

    static AttributeAccess ofLocalDate() {
        return ofDate();
    }

    static AttributeAccess> ofLocalDateSet() {
        return ofDateSet();
    }

    static AttributeAccess ofDate() {
        return AttributeAccessImpl.ofPrimitive(localDateTypeReference(), DateType.class);
    }

    static AttributeAccess> ofDateSet() {
        return AttributeAccessImpl.ofSet(DateType.class, new TypeReference>() {
        });
    }

    static AttributeAccess ofLocalTime() {
        return ofTime();
    }

    static AttributeAccess> ofLocalTimeSet() {
        return ofTimeSet();
    }

    static AttributeAccess ofTime() {
        return AttributeAccessImpl.ofPrimitive(localTimeTypeReference(), TimeType.class);
    }

    static AttributeAccess> ofTimeSet() {
        return AttributeAccessImpl.ofSet(TimeType.class, new TypeReference>() {
        });
    }

    static AttributeAccess ofDateTime() {
        return AttributeAccessImpl.ofPrimitive(zonedDateTimeTypeReference(), DateTimeType.class);
    }

    static AttributeAccess> ofDateTimeSet() {
        return AttributeAccessImpl.ofSet(DateTimeType.class, new TypeReference>() {
        });
    }

    static AttributeAccess ofZonedDateTime() {
        return ofDateTime();
    }

    static AttributeAccess> ofZonedDateTimeSet() {
        return ofDateTimeSet();
    }

    static AttributeAccess> ofProductReference() {
        return AttributeAccessImpl.ofReferenceType(ReferenceType.ofProduct());
    }

    static AttributeAccess>> ofProductReferenceSet() {
        return AttributeAccessImpl.ofSet(ReferenceType.ofProduct(), new TypeReference>>() {
        });
    }

    static AttributeAccess> ofProductTypeReference() {
        return AttributeAccessImpl.ofReferenceType(ReferenceType.ofProductType());
    }

    static AttributeAccess>> ofProductTypeReferenceSet() {
        return AttributeAccessImpl.ofSet(ReferenceType.ofProductType(), new TypeReference>>() {
        });
    }

    static AttributeAccess> ofCategoryReference() {
        return AttributeAccessImpl.ofReferenceType(ReferenceType.ofCategory());
    }

    static AttributeAccess>> ofCategoryReferenceSet() {
        return AttributeAccessImpl.ofSet(ReferenceType.ofCategory(), new TypeReference>>() {
        });
    }

    static AttributeAccess> ofChannelReference() {
        return AttributeAccessImpl.ofReferenceType(ReferenceType.ofChannel());
    }

    static AttributeAccess>> ofChannelReferenceSet() {
        return AttributeAccessImpl.ofSet(ReferenceType.ofChannel(), new TypeReference>>() {
        });
    }

    static AttributeAccess ofJsonNode() {
        final AttributeMapper attributeMapper = new AttributeMapper() {
            @Override
            public JsonNode deserialize(final JsonNode value) {
                return value;
            }

            @Override
            public JsonNode serialize(final JsonNode value) {
                return value;
            }
        };
        return new AttributeAccessImpl<>(attributeMapper, TypeReferences.jsonNodeTypeReference(), ad -> true);
    }

    static AttributeAccess ofNested() {
        return new AttributeAccessImpl<>(new NestedAttributeMapperImpl(), new TypeReference() {
            @Override
            public String toString() {
                return "TypeReference";
            }
        }, attributeDefinition -> attributeDefinition.getAttributeType() instanceof NestedType);
    }

    static AttributeAccess> ofNestedSet() {
        return AttributeAccessImpl.ofSet(NestedType.class, new TypeReference>() {
            @Override
            public String toString() {
                return "TypeReference>";
            }
        }, new NestedSetAttributeMapperImpl());
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy