001 package 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 **/
008 public class DataFormatEntry implements Comparable<DataFormatEntry>{
009 /** Column position from 0 to n-1, where n is number of columns in the data format. */
010 private int position;
011 /** Column name */
012 private String dataFormatEntryName;
013 /** Column category (INPUT, HEAD or OUTPUT) */
014 private String category;
015 /** Column type (STRING, INTEGER, BOOLEAN, ECHO or IGNORE) */
016 private String type;
017 /** Default output for a ignore column */
018 private String defaultOutput;
019 /** Cache the hash code for the data format entry */
020 private int cachedHash;
021 /**
022 * Creates a data format entry
023 *
024 * @param position column position
025 * @param dataFormatEntryName column name
026 * @param category column category
027 * @param type column type
028 * @param defaultOutput default output for a ignore column
029 */
030 public DataFormatEntry(int position, String dataFormatEntryName, String category, String type, String defaultOutput) {
031 setPosition(position);
032 setDataFormatEntryName(dataFormatEntryName);
033 setCategory(category);
034 setType(type);
035 setDefaultOutput(defaultOutput);
036 }
037
038 /**
039 * Returns the column position
040 *
041 * @return the column position
042 */
043 public int getPosition() {
044 return position;
045 }
046
047 /**
048 * Sets the column position
049 *
050 * @param position column position
051 */
052 public void setPosition(int position) {
053 this.position = position;
054 }
055
056 /**
057 * Returns the column name
058 * @return the column name
059 */
060 public String getDataFormatEntryName() {
061 return dataFormatEntryName;
062 }
063
064 /**
065 * Sets the column name
066 * @param dataFormatEntryName column name
067 */
068 public void setDataFormatEntryName(String dataFormatEntryName) {
069 this.dataFormatEntryName = dataFormatEntryName.toUpperCase();
070 }
071
072 /**
073 * Returns the column category
074 *
075 * @return the column category
076 */
077 public String getCategory() {
078 return category;
079 }
080
081 /**
082 * Sets the column category
083 *
084 * @param category the column category
085 */
086 public void setCategory(String category) {
087 this.category = category.toUpperCase();
088 }
089
090 /**
091 * Return the column type
092 *
093 * @return the column type
094 */
095 public String getType() {
096 return type;
097 }
098
099 /**
100 * Sets the column type
101 *
102 * @param type the column type
103 */
104 public void setType(String type) {
105 this.type = type.toUpperCase();
106 }
107
108 /* (non-Javadoc)
109 * @see java.lang.Comparable#compareTo(java.lang.Object)
110 */
111 public int compareTo(DataFormatEntry obj) {
112 if (this.position == obj.position) {
113 return 0;
114 } else if (this.position < obj.position) {
115 return -1;
116 } else {
117 return 1;
118 }
119 }
120
121 /**
122 * Returns the default output of an ignore column
123 *
124 * @return the default output of an ignore column
125 */
126 public String getDefaultOutput() {
127 return defaultOutput;
128 }
129
130 /**
131 * Sets the default output of an ignore column
132 *
133 * @param defaultOutput the default output of an ignore column
134 */
135 public void setDefaultOutput(String defaultOutput) {
136 this.defaultOutput = defaultOutput;
137 }
138
139 public boolean equals(Object obj) {
140 if (this == obj)
141 return true;
142 if (obj == null)
143 return false;
144 if (getClass() != obj.getClass())
145 return false;
146 DataFormatEntry objC = (DataFormatEntry)obj;
147 return ((dataFormatEntryName == null) ? objC.dataFormatEntryName == null : dataFormatEntryName.equals(objC.dataFormatEntryName)) &&
148 ((type == null) ? objC.type == null : type.equals(objC.type)) &&
149 ((category == null) ? objC.category == null : category.equals(objC.category)) &&
150 ((defaultOutput == null) ? objC.defaultOutput == null : defaultOutput.equals(objC.defaultOutput));
151 }
152
153 public int hashCode() {
154 if (cachedHash == 0) {
155 int hash = 7;
156 hash = 31 * hash + (null == dataFormatEntryName ? 0 : dataFormatEntryName.hashCode());
157 hash = 31 * hash + (null == type ? 0 : type.hashCode());
158 hash = 31 * hash + (null == category ? 0 : category.hashCode());
159 hash = 31 * hash + (null == defaultOutput ? 0 : defaultOutput.hashCode());
160 cachedHash = hash;
161 }
162 return cachedHash;
163 }
164
165 public String toString() {
166 final StringBuilder sb = new StringBuilder();
167 sb.append(position);
168 sb.append("\t");
169 sb.append(dataFormatEntryName);
170 sb.append("\t");
171 sb.append(category);
172 sb.append("\t");
173 sb.append(type);
174 if (defaultOutput != null) {
175 sb.append("\t");
176 sb.append(defaultOutput);
177 }
178 return sb.toString();
179 }
180 }