001package org.maltparser.parser.history.container;
002
003
004import org.maltparser.core.exception.MaltChainedException;
005import org.maltparser.core.symbol.Table;
006/**
007*
008* @author Johan Hall
009**/
010public class ActionContainer {
011        private final Table table;
012        private final String name;
013        private int actionCode;
014        private String actionSymbol;
015
016        
017        public ActionContainer(TableContainer tableContainer) {
018                this.table = tableContainer.getTable();
019                this.name = 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 String toString() {
082                final StringBuilder sb = new StringBuilder();
083                sb.append(name);
084                sb.append(" -> ");
085                sb.append(actionSymbol);
086                sb.append(" = ");
087                sb.append(actionCode);
088                return sb.toString();
089        }
090}