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

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

package io.sphere.sdk.products;

import io.sphere.sdk.models.*;
import io.sphere.sdk.producttypes.ProductType;
import io.sphere.sdk.utils.ListUtils;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

public final class ProductDraftBuilder extends ProductDataProductDraftBuilderBase implements Builder {

    private final ResourceIdentifier productType;
    private ProductVariantDraft masterVariant;
    private List variants = Collections.emptyList();

    private ProductDraftBuilder(final ResourceIdentifier productType, final LocalizedString name, final LocalizedString slug, final ProductVariantDraft masterVariant) {
        super(name, slug);
        this.productType = productType;
        this.masterVariant = masterVariant;
    }

    public static ProductDraftBuilder of(final ResourceIdentifiable productType, final LocalizedString name, final LocalizedString slug, final ProductVariantDraft masterVariant) {
        return new ProductDraftBuilder(productType.toResourceIdentifier(), name, slug, masterVariant);
    }

    @Override
    public ProductDraft build() {
        return new ProductDraftImpl(productType, getName(), getSlug(), getDescription(), getCategories(), getMetaTitle(), getMetaDescription(), getMetaKeywords(), masterVariant, variants, getTaxCategory(), getSearchKeywords(), getState(), getCategoryOrderHints());
    }

    @Override
    protected ProductDraftBuilder getThis() {
        return this;
    }

    public ProductDraftBuilder variants(final List variants) {
        this.variants = Collections.unmodifiableList(new ArrayList<>(variants));
        return getThis();
    }

    public ProductDraftBuilder plusVariants(final ProductVariantDraft variantToAdd) {
        return variants(ListUtils.listOf(this.variants, variantToAdd));
    }

    public ProductDraftBuilder plusVariants(final List variantsToAdd) {
        return variants(ListUtils.listOf(this.variants, variantsToAdd));
    }

    public ProductDraftBuilder masterVariant(final ProductVariantDraft masterVariant) {
        this.masterVariant = masterVariant;
        return getThis();
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy