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

io.sphere.sdk.carts.commands.updateactions.RemoveLineItem Maven / Gradle / Ivy

There is a newer version: 1.0.0-M12
Show newest version
package io.sphere.sdk.carts.commands.updateactions;

import com.fasterxml.jackson.annotation.JsonInclude;
import io.sphere.sdk.carts.Cart;
import io.sphere.sdk.carts.LineItem;
import io.sphere.sdk.commands.UpdateAction;

import java.util.Optional;

/**
 Decreases the quantity of the given line item. If after the update the quantity of the line item is not greater than 0 or the quantity is not specified, the line item is removed from the cart.

 {@include.example io.sphere.sdk.carts.commands.CartUpdateCommandTest#removeLineItem()}
 */
public class RemoveLineItem extends UpdateAction {
    private final String lineItemId;
    @JsonInclude(JsonInclude.Include.NON_EMPTY)
    private final Optional quantity;

    private RemoveLineItem(final String lineItemId, final Optional quantity) {
        super("removeLineItem");
        this.lineItemId = lineItemId;
        this.quantity = quantity;
    }

    public static RemoveLineItem of(final String lineItemId, final Optional quantity) {
        return new RemoveLineItem(lineItemId, quantity);
    }

    public static RemoveLineItem of(final String lineItemId, final Integer quantity) {
        return of(lineItemId, Optional.of(quantity));
    }

    public static RemoveLineItem of(final String lineItemId) {
        return of(lineItemId, Optional.empty());
    }

    public static RemoveLineItem of(final LineItem lineItem, final Optional quantity) {
        return of(lineItem.getId(), quantity);
    }

    public static RemoveLineItem of(final LineItem lineItem, final Integer quantity) {
        return of(lineItem.getId(), Optional.of(quantity));
    }

    public static RemoveLineItem of(final LineItem lineItem) {
        return of(lineItem.getId(), Optional.empty());
    }

    public String getLineItemId() {
        return lineItemId;
    }

    public Optional getQuantity() {
        return quantity;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy