001    package org.maltparser.parser.history;
002    
003    import org.maltparser.core.exception.MaltChainedException;
004    import org.maltparser.core.pool.ObjectPoolList;
005    import org.maltparser.parser.history.action.GuideUserAction;
006    /**
007     * 
008     * @author Johan Hall
009    */
010    public class HistoryTree extends HistoryStructure {
011            private 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 void toFile() throws MaltChainedException {
040                    
041            }
042            
043            public void close() throws MaltChainedException {
044                    
045            }
046            
047            public String toString() {
048                    final StringBuilder sb = new StringBuilder();
049                    sb.append(root.toString());
050                    return sb.toString();
051            }
052    }