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

javafixes.object.changing.builder.UpdateConfigBuilder Maven / Gradle / Ivy

There is a newer version: 1.4.2.0
Show newest version
package javafixes.object.changing.builder;

import javafixes.object.changing.config.ChangingValueUpdateConfig;
import javafixes.object.changing.function.valueHandler.AfterReplacedPreviousValueHandler;
import javafixes.object.changing.function.valueHandler.EachPotentialValueHandler;
import javafixes.object.changing.function.replacement.ValueReplacementRule;

import java.util.Optional;
import java.util.function.Consumer;

public  class UpdateConfigBuilder {

    protected ChangingValueUpdateConfig updateConfig = ChangingValueUpdateConfig.doNothingOnUpdateConfig();

    public static  UpdateConfigBuilder updateConfigBuilder() {
        return new UpdateConfigBuilder<>();
    }

    public ChangingValueUpdateConfig build() {
        return updateConfig;
    }

    public UpdateConfigBuilder withValueReplacementRule(ValueReplacementRule valueReplacementRule) {
        this.updateConfig = new ChangingValueUpdateConfig<>(
                Optional.of(valueReplacementRule),
                updateConfig.eachPotentialValueHandler,
                updateConfig.afterReplacedPreviousValueHandler,
                updateConfig.disposeFunction
        );
        return this;
    }

    public UpdateConfigBuilder withNOValueReplacementRule() {
        this.updateConfig = new ChangingValueUpdateConfig<>(
                Optional.empty(),
                updateConfig.eachPotentialValueHandler,
                updateConfig.afterReplacedPreviousValueHandler,
                updateConfig.disposeFunction
        );
        return this;
    }

    public UpdateConfigBuilder withValueReplacementRule(Optional> valueReplacementRule) {
        this.updateConfig = new ChangingValueUpdateConfig<>(
                valueReplacementRule,
                updateConfig.eachPotentialValueHandler,
                updateConfig.afterReplacedPreviousValueHandler,
                updateConfig.disposeFunction
        );
        return this;
    }

    public UpdateConfigBuilder withEachPotentialValueHandler(EachPotentialValueHandler eachPotentialValueHandler) {
        this.updateConfig = new ChangingValueUpdateConfig<>(
                updateConfig.valueReplacementRule,
                Optional.of(eachPotentialValueHandler),
                updateConfig.afterReplacedPreviousValueHandler,
                updateConfig.disposeFunction
        );
        return this;
    }

    public UpdateConfigBuilder withNOEachPotentialValueHandler() {
        this.updateConfig = new ChangingValueUpdateConfig<>(
                updateConfig.valueReplacementRule,
                Optional.empty(),
                updateConfig.afterReplacedPreviousValueHandler,
                updateConfig.disposeFunction
        );
        return this;
    }

    public UpdateConfigBuilder withEachPotentialValueHandler(Optional> eachPotentialValueHandler) {
        this.updateConfig = new ChangingValueUpdateConfig<>(
                updateConfig.valueReplacementRule,
                eachPotentialValueHandler,
                updateConfig.afterReplacedPreviousValueHandler,
                updateConfig.disposeFunction
        );
        return this;
    }

    public UpdateConfigBuilder withAfterReplacedPreviousValueHandler(AfterReplacedPreviousValueHandler afterReplacedPreviousValueHandler) {
        this.updateConfig = new ChangingValueUpdateConfig<>(
                updateConfig.valueReplacementRule,
                updateConfig.eachPotentialValueHandler,
                Optional.of(afterReplacedPreviousValueHandler),
                updateConfig.disposeFunction
        );
        return this;
    }

    public UpdateConfigBuilder withNOAfterReplacedPreviousValueHandler() {
        this.updateConfig = new ChangingValueUpdateConfig<>(
                updateConfig.valueReplacementRule,
                updateConfig.eachPotentialValueHandler,
                Optional.empty(),
                updateConfig.disposeFunction
        );
        return this;
    }

    public UpdateConfigBuilder withAfterReplacedPreviousValueHandler(Optional> afterReplacedPreviousValueHandler) {
        this.updateConfig = new ChangingValueUpdateConfig<>(
                updateConfig.valueReplacementRule,
                updateConfig.eachPotentialValueHandler,
                afterReplacedPreviousValueHandler,
                updateConfig.disposeFunction
        );
        return this;
    }

    public UpdateConfigBuilder withDisposeFunction(Consumer disposeFunction) {
        this.updateConfig = new ChangingValueUpdateConfig<>(
                updateConfig.valueReplacementRule,
                updateConfig.eachPotentialValueHandler,
                updateConfig.afterReplacedPreviousValueHandler,
                Optional.of(disposeFunction)
        );
        return this;
    }

    public UpdateConfigBuilder withNODisposeFunction() {
        this.updateConfig = new ChangingValueUpdateConfig<>(
                updateConfig.valueReplacementRule,
                updateConfig.eachPotentialValueHandler,
                updateConfig.afterReplacedPreviousValueHandler,
                Optional.empty()
        );
        return this;
    }

    public UpdateConfigBuilder withDisposeFunction(Optional> disposeFunction) {
        this.updateConfig = new ChangingValueUpdateConfig<>(
                updateConfig.valueReplacementRule,
                updateConfig.eachPotentialValueHandler,
                updateConfig.afterReplacedPreviousValueHandler,
                disposeFunction
        );
        return this;
    }

    public UpdateConfigBuilder withUpdateConfig(ChangingValueUpdateConfig updateConfig) {
        this.updateConfig = (ChangingValueUpdateConfig) updateConfig;
        return this;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy