001package org.maltparser.core.io.dataformat;
002/**
003 *  DataFormatEntry is used for storing information about one column in a data format. 
004 *
005 * @author Johan Hall
006 * @since 1.0
007**/
008public class DataFormatEntry {
009        /** Column name */
010        private String dataFormatEntryName;
011        /** Column category (INPUT, HEAD, DEPENDENCY_EDGE_LABEL, PHRASE_STRUCTURE_EDGE_LABEL, PHRASE_STRUCTURE_NODE_LABEL, SECONDARY_EDGE_LABEL, IGNORE and INTERNAL) */
012        private String category;
013        /** Column type (STRING, INTEGER, BOOLEAN, REAL) */
014        private String type;
015        /** Default output for a ignore column */
016        private String defaultOutput;
017        /** Cache the hash code for the data format entry */
018        private int cachedHash;
019        /**
020         * Creates a data format entry
021         * 
022         * @param dataFormatEntryName column name
023         * @param category      column category
024         * @param type  column type
025         * @param defaultOutput default output for a ignore column
026         */
027        public DataFormatEntry(String dataFormatEntryName, String category, String type, String defaultOutput) {
028                setDataFormatEntryName(dataFormatEntryName);
029                setCategory(category);
030                setType(type);
031                setDefaultOutput(defaultOutput);
032        }
033
034        /**
035         * Returns the column name
036         * @return      the column name
037         */
038        public String getDataFormatEntryName() {
039                return dataFormatEntryName;
040        }
041
042        /**
043         * Sets the column name
044         * @param dataFormatEntryName   column name
045         */
046        public void setDataFormatEntryName(String dataFormatEntryName) {
047                this.dataFormatEntryName = dataFormatEntryName.toUpperCase();
048        }
049
050        /**
051         * Returns the column category
052         * 
053         * @return      the column category
054         */
055        public String getCategory() {
056                return category;
057        }
058
059        /**
060         * Sets the column category
061         * 
062         * @param category      the column category
063         */
064        public void setCategory(String category) {
065                this.category = category.toUpperCase();
066        }
067
068        /**
069         * Return the column type
070         * 
071         * @return      the column type
072         */
073        public String getType() {
074                return type;
075        }
076
077        /**
078         * Sets the column type
079         * 
080         * @param type  the column type
081         */
082        public void setType(String type) {
083                this.type = type.toUpperCase();
084        }
085
086        /**
087         * Returns the default output of an ignore column
088         * 
089         * @return the default output of an ignore column
090         */
091        public String getDefaultOutput() {
092                return defaultOutput;
093        }
094
095        /**
096         * Sets the default output of an ignore column
097         * 
098         * @param defaultOutput  the default output of an ignore column
099         */
100        public void setDefaultOutput(String defaultOutput) {
101                this.defaultOutput = defaultOutput;
102        }
103        
104        public boolean equals(Object obj) {
105                if (this == obj)
106                        return true;
107                if (obj == null)
108                        return false;
109                if (getClass() != obj.getClass())
110                        return false;
111                DataFormatEntry objC = (DataFormatEntry)obj;
112                return ((dataFormatEntryName == null) ? objC.dataFormatEntryName == null : dataFormatEntryName.equals(objC.dataFormatEntryName)) &&
113                                ((type == null) ? objC.type == null : type.equals(objC.type)) &&
114                                ((category == null) ? objC.category == null : category.equals(objC.category)) && 
115                                ((defaultOutput == null) ? objC.defaultOutput == null : defaultOutput.equals(objC.defaultOutput));
116        }
117
118        public int hashCode() {
119                if (cachedHash == 0) {
120                        int hash = 7;
121                        hash = 31 * hash + (null == dataFormatEntryName ? 0 : dataFormatEntryName.hashCode());
122                        hash = 31 * hash + (null == type ? 0 : type.hashCode());
123                        hash = 31 * hash + (null == category ? 0 : category.hashCode());
124                        hash = 31 * hash + (null == defaultOutput ? 0 : defaultOutput.hashCode());
125                        cachedHash = hash;
126                }
127                return cachedHash;
128        }
129        
130        public String toString() {
131                final StringBuilder sb = new StringBuilder();
132                sb.append(dataFormatEntryName);
133                sb.append("\t");
134                sb.append(category);
135                sb.append("\t");
136                sb.append(type);
137                if (defaultOutput != null) {
138                        sb.append("\t");
139                        sb.append(defaultOutput);
140                }
141                return sb.toString();
142        }
143}