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

panda.lang.CycleDetector Maven / Gradle / Ivy

Go to download

Panda Core is the core module of Panda Framework, it contains commonly used utility classes similar to apache-commons.

There is a newer version: 1.8.0
Show newest version
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;
	}
}