001package org.maltparser.parser.history;
002
003import java.util.ArrayList;
004
005import org.maltparser.core.exception.MaltChainedException;
006import org.maltparser.core.pool.ObjectPoolList;
007import org.maltparser.parser.history.action.GuideUserAction;
008/**
009 * 
010 * @author Johan Hall
011*/
012public class HistoryList extends HistoryStructure {
013        protected final ArrayList<HistoryNode> list;
014        protected final ObjectPoolList<HistoryNode> nodePool;
015        
016        public HistoryList() throws MaltChainedException {
017                super();
018                list = new ArrayList<HistoryNode>();
019                nodePool = new ObjectPoolList<HistoryNode>() {
020                        protected HistoryNode create() throws MaltChainedException { return new HistoryListNode(null, null); }
021                        public void resetObject(HistoryNode o) throws MaltChainedException { o.clear(); }
022                };
023        }
024        
025        public HistoryNode getNewHistoryNode(HistoryNode previousNode, GuideUserAction action) throws MaltChainedException {
026                HistoryNode node = nodePool.checkOut();
027                node.setAction(action);
028                node.setPreviousNode(previousNode);
029                list.add(node);
030                return node;
031        }
032        
033        public void clear() throws MaltChainedException {
034                nodePool.checkInAll();
035                list.clear();
036        }
037        
038        public boolean equals(Object obj) {
039                return super.equals(obj);
040        }
041
042        public int hashCode() {
043                return super.hashCode();
044        }
045        
046        public String toString() {
047                final StringBuilder sb = new StringBuilder();
048                for (int i = 0; i < list.size(); i++) {
049                        sb.append(list.get(i));
050                        if (i < list.size()-1) {
051                                sb.append(", ");
052                        }
053                }
054                return sb.toString();
055        }
056        
057}