001 package org.maltparser.parser.history.container; 002 003 004 import org.maltparser.core.exception.MaltChainedException; 005 import org.maltparser.core.symbol.Table; 006 /** 007 * 008 * @author Johan Hall 009 **/ 010 public class ActionContainer { 011 protected int actionCode; 012 protected String actionSymbol; 013 protected Table table; 014 protected String name; 015 016 public ActionContainer(TableContainer tableContainer) { 017 setTable(tableContainer.getTable()); 018 setName(tableContainer.getTableContainerName()); 019 clear(); 020 } 021 022 public void clear() { 023 actionCode = -1; 024 actionSymbol = null; 025 } 026 027 public String getActionSymbol() { 028 return actionSymbol; 029 } 030 031 public int getActionCode() { 032 return actionCode; 033 } 034 035 public String setAction(int code) throws MaltChainedException { 036 if (actionCode != code) { 037 if (code < 0) { 038 clear(); 039 } else { 040 actionSymbol = table.getSymbolCodeToString(code); 041 if (actionSymbol == null) { 042 clear(); 043 } else { 044 actionCode = code; 045 } 046 } 047 } 048 return actionSymbol; 049 } 050 051 public int setAction(String symbol) throws MaltChainedException { 052 if (symbol == null) { 053 clear(); 054 } else { 055 actionCode = table.getSymbolStringToCode(symbol); 056 if (actionCode == -1) { 057 clear(); 058 } else { 059 actionSymbol = symbol; 060 } 061 } 062 return actionCode; 063 } 064 065 public Table getTable() { 066 return table; 067 } 068 069 public String getTableName() { 070 if (table == null) { 071 return null; 072 } 073 return table.getName(); 074 } 075 076 public String getTableContainerName() { 077 return name; 078 } 079 080 public void setTable(Table table) { 081 this.table = table; 082 } 083 084 protected void setName(String name) { 085 this.name = name; 086 } 087 088 public String toString() { 089 final StringBuilder sb = new StringBuilder(); 090 sb.append(name); 091 sb.append(" -> "); 092 sb.append(actionSymbol); 093 sb.append(" = "); 094 sb.append(actionCode); 095 return sb.toString(); 096 } 097 }