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

io.sphere.sdk.customers.commands.updateactions.SetDefaultShippingAddress Maven / Gradle / Ivy

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

import io.sphere.sdk.commands.UpdateAction;
import io.sphere.sdk.customers.Customer;
import io.sphere.sdk.models.Address;

import java.util.Optional;

import static java.lang.String.format;

/**
 * Sets the default shipping address from the customer's addresses.
 *
 * {@include.example io.sphere.sdk.customers.commands.CustomerUpdateCommandTest#setDefaultShippingAddress()}
 */
public class SetDefaultShippingAddress extends UpdateAction {
    private final Optional addressId;

    private SetDefaultShippingAddress(final Optional addressId) {
        super("setDefaultShippingAddress");
        this.addressId = addressId;
    }

    public static SetDefaultShippingAddress of(final Optional addressId) {
        return new SetDefaultShippingAddress(addressId);
    }

    public static SetDefaultShippingAddress of(final String addressId) {
        return of(Optional.of(addressId));
    }

    public static SetDefaultShippingAddress of(final Address address) {
        if (!address.getId().isPresent()) {
            throw new IllegalArgumentException(format("The address %s should have an id.", address));
        }
        return of(address.getId());
    }

    public Optional getAddressId() {
        return addressId;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy