io.sphere.sdk.products.ProductBuilder Maven / Gradle / Ivy
package io.sphere.sdk.products;
import java.util.Optional;
import io.sphere.sdk.models.DefaultModelFluentBuilder;
import io.sphere.sdk.models.Reference;
import io.sphere.sdk.models.Referenceable;
import io.sphere.sdk.producttypes.ProductType;
import io.sphere.sdk.taxcategories.TaxCategory;
/**
Builds test doubles1 for products.
Example:
{@include.example io.sphere.sdk.products.ProductBuilderTest#demoUsage()}
*/
public class ProductBuilder extends DefaultModelFluentBuilder {
private final Reference productType;
private final ProductCatalogData masterData;
private Optional> taxCategory = Optional.empty();
private ProductBuilder(final Reference productType, final ProductCatalogData masterData) {
this.productType = productType;
this.masterData = masterData;
}
public static ProductBuilder of(final Referenceable productType, final ProductCatalogData masterData) {
return new ProductBuilder(productType.toReference(), masterData);
}
public ProductBuilder taxCategory(final Optional> taxCategory) {
this.taxCategory = taxCategory;
return getThis();
}
public ProductBuilder taxCategory(final Referenceable taxCategory) {
return taxCategory(Optional.of(taxCategory.toReference()));
}
@Override
protected ProductBuilder getThis() {
return this;
}
@Override
public Product build() {
return new ProductImpl(id, version, createdAt, lastModifiedAt, productType, masterData, taxCategory);
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy