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

io.sphere.sdk.products.ProductVariant Maven / Gradle / Ivy

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

import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import io.sphere.sdk.attributes.Attribute;
import io.sphere.sdk.attributes.AttributeGetter;

import java.util.List;
import java.util.Optional;

import static java.util.Objects.requireNonNull;

@JsonDeserialize(as = ProductVariantImpl.class)
public interface ProductVariant {

    long getId();

    Optional getSku();

    List getPrices();

    List getAttributes();

    /**
     * Access one attribute of a specific name and type which is known in the first place, consult {@link io.sphere.sdk.attributes.AttributeGetterSetter} how to implement these.
     *
     * @throws io.sphere.sdk.attributes.AttributeMappingException if the type of attribute cannot be parsed
     *
     * @param accessor declaration of the name and type of the attribute
     * @param  the underlying type of the attribute
     * @return the value of the attribute, or Optional.empty if absent
     */
     Optional getAttribute(final AttributeGetter accessor);

    default boolean hasAttribute(String attributeName) {
        return getAttributes().stream().anyMatch(attr -> attr.getName().equals(attributeName));
    }

    default Optional getAttribute(final String attributeName) {
        requireNonNull(attributeName);
        return getAttributes().stream().filter(attr -> attr.getName().equals(attributeName)).findAny();
    }

    //TODO images

    //TODO availability
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy