io.sphere.sdk.products.ProductVariantBuilder Maven / Gradle / Ivy
package io.sphere.sdk.products;
import io.sphere.sdk.models.Base;
import io.sphere.sdk.models.Builder;
import io.sphere.sdk.attributes.Attribute;
import io.sphere.sdk.models.Image;
import java.util.*;
public final class ProductVariantBuilder extends Base implements Builder {
private final int id;
private Optional sku = Optional.empty();
private List prices = Collections.emptyList();
private List attributes = Collections.emptyList();
private List images = Collections.emptyList();
private Optional availability = Optional.empty();
private ProductVariantBuilder(final int id) {
this.id = id;
}
public static ProductVariantBuilder of(final int id) {
return new ProductVariantBuilder(id);
}
public static ProductVariantBuilder ofMasterVariant() {
return of(1);
}
public ProductVariantBuilder sku(final Optional sku) {
this.sku = sku;
return this;
}
public ProductVariantBuilder sku(final String sku) {
Objects.requireNonNull(sku);
return sku(Optional.of(sku));
}
public ProductVariantBuilder prices(final List prices) {
this.prices = prices;
return this;
}
public ProductVariantBuilder prices(final Price ... prices) {
return prices(Arrays.asList(prices));
}
public ProductVariantBuilder price(final Price price) {
return prices(Arrays.asList(price));
}
public ProductVariantBuilder attributes(final List attributes) {
this.attributes = attributes;
return this;
}
public ProductVariantBuilder attributes(final Attribute ... attributes) {
return attributes(Arrays.asList(attributes));
}
public ProductVariantBuilder images(final List images) {
this.images = images;
return this;
}
public ProductVariantBuilder availability(final Optional availability) {
this.availability = availability;
return this;
}
public ProductVariantBuilder availability(final ProductVariantAvailability availability) {
Objects.requireNonNull(availability);
return availability(Optional.of(availability));
}
@Override
public ProductVariant build() {
return new ProductVariantImpl(id, sku, prices, attributes, images, availability);
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy