com.github.vkorobkov.jfixtures.processor.CircularPreventer Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of jfixtures Show documentation
Show all versions of jfixtures Show documentation
Easy test data creator for SQL databases
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();
}
}