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

io.sphere.sdk.states.StateDraftBuilder Maven / Gradle / Ivy

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

import io.sphere.sdk.models.Base;
import io.sphere.sdk.models.Builder;
import io.sphere.sdk.models.LocalizedStrings;
import io.sphere.sdk.models.Reference;

import java.util.Optional;
import java.util.Set;

public class StateDraftBuilder extends Base implements Builder {
    private final String key;
    private final StateType type;
    private Optional name;
    private Optional description;
    private Optional initial;
    private Optional>> transitions;

    public StateDraftBuilder(final String key, final StateType type) {
        this.key = key;
        this.type = type;
    }

    public static StateDraftBuilder of(final String key, final StateType type) {
        return new StateDraftBuilder(key, type);
    }

    public static StateDraftBuilder of(final StateDraft template) {
        return new StateDraftBuilder(template.getKey(), template.getType())
                .name(template.getName())
                .description(template.getDescription())
                .transitions(template.getTransitions())
                .initial(template.isInitial());
    }

    public StateDraftBuilder name(final Optional name) {
        this.name = name;
        return this;
    }

    public StateDraftBuilder name(final LocalizedStrings name) {
        return name(Optional.of(name));
    }

    public StateDraftBuilder description(final Optional description) {
        this.description = description;
        return this;
    }

    public StateDraftBuilder description(final LocalizedStrings description) {
        return description(Optional.of(description));
    }

    public StateDraftBuilder initial(final Optional initial) {
        this.initial = initial;
        return this;
    }

    public StateDraftBuilder initial(final boolean initial) {
        return initial(Optional.of(initial));
    }

    public StateDraftBuilder transitions(final Optional>> transitions) {
        this.transitions = transitions;
        return this;
    }

    public StateDraftBuilder transitions(final Set> transitions) {
        return transitions(Optional.of(transitions));
    }

    @Override
    public StateDraft build() {
        return new StateDraft(key, type, name, description, initial, transitions);
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy