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 private int actionCode;
012 private String actionSymbol;
013 private Table table;
014 private String name;
015
016 public ActionContainer(TableContainer tableContainer) {
017 this.table = tableContainer.getTable();
018 this.name = 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
081
082 public String toString() {
083 final StringBuilder sb = new StringBuilder();
084 sb.append(name);
085 sb.append(" -> ");
086 sb.append(actionSymbol);
087 sb.append(" = ");
088 sb.append(actionCode);
089 return sb.toString();
090 }
091 }