001 package org.maltparser.parser.history; 002 003 import java.util.ArrayList; 004 005 import org.maltparser.core.exception.MaltChainedException; 006 import org.maltparser.core.pool.ObjectPoolList; 007 import org.maltparser.parser.history.action.GuideUserAction; 008 /** 009 * 010 * @author Johan Hall 011 */ 012 public class HistoryList extends HistoryStructure { 013 protected ArrayList<HistoryNode> list; 014 protected final ObjectPoolList<HistoryNode> nodePool; 015 // protected BufferedWriter writer; 016 017 public HistoryList() throws MaltChainedException { 018 super(); 019 list = new ArrayList<HistoryNode>(); 020 nodePool = new ObjectPoolList<HistoryNode>() { 021 protected HistoryNode create() throws MaltChainedException { return new HistoryListNode(null, null); } 022 public void resetObject(HistoryNode o) throws MaltChainedException { o.clear(); } 023 }; 024 // try { 025 // writer = new BufferedWriter(new FileWriter("tseq.dat")); 026 // } catch (IOException e) { 027 // throw new MaltChainedException("", e); 028 // } 029 } 030 031 public HistoryNode getNewHistoryNode(HistoryNode previousNode, GuideUserAction action) throws MaltChainedException { 032 HistoryNode node = nodePool.checkOut(); 033 node.setAction(action); 034 node.setPreviousNode(previousNode); 035 list.add(node); 036 return node; 037 } 038 039 public void clear() throws MaltChainedException { 040 nodePool.checkInAll(); 041 list.clear(); 042 } 043 044 public boolean equals(Object obj) { 045 return super.equals(obj); 046 } 047 048 public int hashCode() { 049 return super.hashCode(); 050 } 051 052 public void toFile() throws MaltChainedException { 053 // try { 054 // for (int i = 0; i < list.size(); i++) { 055 // writer.write(((ComplexDecisionAction)list.get(i).getAction()).getSingleDecision(0).getDecisionSymbol()); 056 // writer.write("\n"); 057 // writer.flush(); 058 // } 059 // writer.write("\n"); 060 // } catch (IOException e) { 061 // throw new MaltChainedException("", e); 062 // } 063 } 064 065 public void close() throws MaltChainedException { 066 // if (writer != null) { 067 // try { 068 // writer.flush(); 069 // writer.close(); 070 // writer = null; 071 // } catch (IOException e) { 072 // throw new MaltChainedException("", e); 073 // } 074 // } 075 } 076 077 public String toString() { 078 final StringBuilder sb = new StringBuilder(); 079 for (int i = 0; i < list.size(); i++) { 080 sb.append(list.get(i)); 081 if (i < list.size()-1) { 082 sb.append(", "); 083 } 084 } 085 return sb.toString(); 086 } 087 088 }