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

org.maltparserx.parser.history.HistoryTree Maven / Gradle / Ivy

package org.maltparserx.parser.history;

import org.maltparserx.core.exception.MaltChainedException;
import org.maltparserx.core.pool.ObjectPoolList;
import org.maltparserx.parser.history.action.GuideUserAction;
/**
 * 
 * @author Johan Hall
*/
public class HistoryTree extends HistoryStructure {
	private HistoryTreeNode root;
	protected final ObjectPoolList nodePool;
	
	public HistoryTree() {
		super();
		nodePool = new ObjectPoolList() {
			protected HistoryNode create() throws MaltChainedException { return new HistoryTreeNode(null, null); }
			public void resetObject(HistoryNode o) throws MaltChainedException { o.clear(); }
		};
		root = new HistoryTreeNode(null,null);
	}
	
	public HistoryNode getNewHistoryNode(HistoryNode previousNode, GuideUserAction action) throws MaltChainedException {
		HistoryNode node = nodePool.checkOut();
		node.setAction(action);
		if (previousNode == null) {
			node.setPreviousNode(root);
		} else {
			node.setPreviousNode(previousNode);
		}
		return node;
	}
	
	public void clear() throws MaltChainedException {
		nodePool.checkInAll();
		root.clear();
	}
	
	public void toFile() throws MaltChainedException {
		
	}
	
	public void close() throws MaltChainedException {
		
	}
	
	public String toString() {
		final StringBuilder sb = new StringBuilder();
		sb.append(root.toString());
		return sb.toString();
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy