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

panda.lang.CycleDetector Maven / Gradle / Ivy

package panda.lang;


import java.util.ArrayList;
import java.util.List;


/**
 */
public class CycleDetector {
	/** cycle detect value stack */
	protected List stack = new ArrayList();

	/** cycle detect name stack */
	protected List names = new ArrayList();


	public void push(String name, Object value) {
		names.add(name);
		stack.add(value);
	}
	public void popup() {
		names.remove(names.size() - 1);
		stack.remove(stack.size() - 1);
	}
	public boolean isCycled(Object value) {
		return value != null && stack.contains(value);
	}
	
	public String toPath() {
		return '/' + Strings.join(names, '/');
	}
	
	public String toPath(String name) {
		return toPath() + '/' + name;
	}
}