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

com.github.vkorobkov.jfixtures.processor.CircularPreventer Maven / Gradle / Ivy

There is a newer version: 2.0.0
Show newest version
package com.github.vkorobkov.jfixtures.processor;

import java.util.ArrayDeque;
import java.util.Deque;

class CircularPreventer {
    private static final String ARROW = "-->";
    private final Deque stack = new ArrayDeque<>();

    void doInStack(String element, Callback callback) {
        if (stack.contains(element)) {
            String chain = String.join(ARROW, stack);
            String message = "Circular dependency between tables found: " + chain + ARROW + element;
            throw new ProcessorException(message);
        }

        stack.addLast(element);
        callback.doInStack();
        stack.removeLast();
    }

    @FunctionalInterface
    public interface Callback {
        void doInStack();
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy