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