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

io.sphere.sdk.payments.commands.updateactions.TransitionState Maven / Gradle / Ivy

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

import io.sphere.sdk.commands.UpdateActionImpl;
import io.sphere.sdk.models.Reference;
import io.sphere.sdk.models.Referenceable;
import io.sphere.sdk.payments.Payment;
import io.sphere.sdk.states.State;

import javax.annotation.Nullable;
import java.util.Optional;

/**
 * Transition to a new state. If there is no state yet, the new state must be an initial state. If there is an existing state, there must be a direct transition from the existing state to the new state.
 *
 * {@doc.gen intro}
 *
 * {@include.example io.sphere.sdk.payments.commands.PaymentUpdateCommandTest#transitionState()}
 *
 *  @see Payment
 *  @see io.sphere.sdk.payments.messages.PaymentStatusStateTransitionMessage
 */
public class TransitionState extends UpdateActionImpl {
    @Nullable
    private final Reference state;

    private TransitionState(final Reference state) {
        super("transitionState");
        this.state = state;
    }

    public static TransitionState of(final @Nullable Referenceable state) {
        final Reference stateReference =
                Optional.ofNullable(state).map(stateReferenceable -> stateReferenceable.toReference()).orElse(null);
        return new TransitionState(stateReference);
    }

    @Nullable
    public Reference getState() {
        return state;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy