001package org.maltparser.parser.history; 002 003import org.maltparser.core.exception.MaltChainedException; 004import org.maltparser.core.pool.ObjectPoolList; 005import org.maltparser.parser.history.action.GuideUserAction; 006/** 007 * 008 * @author Johan Hall 009*/ 010public class HistoryTree extends HistoryStructure { 011 private final HistoryTreeNode root; 012 protected final ObjectPoolList<HistoryNode> nodePool; 013 014 public HistoryTree() { 015 super(); 016 nodePool = new ObjectPoolList<HistoryNode>() { 017 protected HistoryNode create() throws MaltChainedException { return new HistoryTreeNode(null, null); } 018 public void resetObject(HistoryNode o) throws MaltChainedException { o.clear(); } 019 }; 020 root = new HistoryTreeNode(null,null); 021 } 022 023 public HistoryNode getNewHistoryNode(HistoryNode previousNode, GuideUserAction action) throws MaltChainedException { 024 HistoryNode node = nodePool.checkOut(); 025 node.setAction(action); 026 if (previousNode == null) { 027 node.setPreviousNode(root); 028 } else { 029 node.setPreviousNode(previousNode); 030 } 031 return node; 032 } 033 034 public void clear() throws MaltChainedException { 035 nodePool.checkInAll(); 036 root.clear(); 037 } 038 039 public String toString() { 040 final StringBuilder sb = new StringBuilder(); 041 sb.append(root.toString()); 042 return sb.toString(); 043 } 044}