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

org.eclipse.ditto.placeholders.ImmutablePipelineElementVisitor Maven / Gradle / Ivy

There is a newer version: 3.6.2
Show newest version
/*
 * Copyright (c) 2021 Contributors to the Eclipse Foundation
 *
 * See the NOTICE file(s) distributed with this work for additional
 * information regarding copyright ownership.
 *
 * This program and the accompanying materials are made available under the
 * terms of the Eclipse Public License 2.0 which is available at
 * http://www.eclipse.org/legal/epl-2.0
 *
 * SPDX-License-Identifier: EPL-2.0
 */
package org.eclipse.ditto.placeholders;

import static org.eclipse.ditto.base.model.common.ConditionChecker.checkNotNull;

import java.util.function.Function;
import java.util.function.Supplier;

import javax.annotation.Nullable;

/**
 * Package-private implementation of {@code PipelineElementVisitor}.
 *
 * @param  type of visitor result.
 */
final class ImmutablePipelineElementVisitor implements PipelineElementVisitor {

    private final Function onResolution;
    private final Supplier onIrresolution;
    private final Supplier onDeletion;

    private ImmutablePipelineElementVisitor(
            final Function onResolution,
            final Supplier onIrresolution,
            final Supplier onDeletion) {
        this.onResolution = onResolution;
        this.onIrresolution = onIrresolution;
        this.onDeletion = onDeletion;
    }

    static  PipelineElementVisitor.Builder newBuilder() {
        return new Builder<>();
    }

    @Override
    public T resolved(final String resolved) {
        return onResolution.apply(resolved);
    }

    @Override
    public T unresolved() {
        return onIrresolution.get();
    }

    @Override
    public T deleted() {
        return onDeletion.get();
    }

    private static final class Builder implements PipelineElementVisitor.Builder {

        @Nullable private Function onResolution;
        @Nullable private Supplier onIrresolution;
        @Nullable private Supplier onDeletion;

        private Builder() {}

        @Override
        public PipelineElementVisitor build() {
            return new ImmutablePipelineElementVisitor<>(
                    checkNotNull(onResolution, "onResolution"),
                    checkNotNull(onIrresolution, "onIrresolution"),
                    checkNotNull(onDeletion, "onDeletion"));
        }

        @Override
        public PipelineElementVisitor.Builder resolved(final Function onResolution) {
            this.onResolution = onResolution;
            return this;
        }

        @Override
        public PipelineElementVisitor.Builder unresolved(final Supplier onIrresolution) {
            this.onIrresolution = onIrresolution;
            return this;
        }

        @Override
        public PipelineElementVisitor.Builder deleted(final Supplier onDeletion) {
            this.onDeletion = onDeletion;
            return this;
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy