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

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

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

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

import javax.annotation.Nullable;

import static java.lang.String.format;

/**
 * Sets the default billing address from the customer's addresses.
 *
 *  {@doc.gen intro}
 *
 * {@include.example io.sphere.sdk.customers.commands.CustomerUpdateCommandTest#setDefaultBillingAddress()}
 * @see Customer
 */
public class SetDefaultBillingAddress extends UpdateActionImpl {
    private final String addressId;

    private SetDefaultBillingAddress(@Nullable final String addressId) {
        super("setDefaultBillingAddress");
        this.addressId = addressId;
    }

    public static SetDefaultBillingAddress of(@Nullable final String addressId) {
        return new SetDefaultBillingAddress(addressId);
    }

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

    @Nullable
    public String getAddressId() {
        return addressId;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy