001    package org.maltparser.core.feature.value;
002    
003    import org.maltparser.core.feature.function.Function;
004    /**
005     *  
006     *
007     * @author Johan Hall
008     * @since 1.0
009    **/
010    public class SingleFeatureValue extends FeatureValue {
011            protected int indexCode;
012            protected String symbol;
013            protected double value;
014            
015            public SingleFeatureValue(Function function) {
016                    super(function);
017                    setIndexCode(0);
018                    setSymbol(null);
019                    setValue(0);
020            }
021            
022            public void reset() {
023                    super.reset();
024                    setIndexCode(0);
025                    setSymbol(null);
026                    setValue(0);
027            }
028            
029            public void update(int indexCode, String symbol, boolean nullValue, double value) {
030                    this.indexCode = indexCode;
031                    this.symbol = symbol;
032                    this.nullValue = nullValue;
033                    this.value = value;
034            }
035            
036            public int getIndexCode() {
037                    return indexCode;
038            }
039    
040            public void setIndexCode(int code) {
041                    this.indexCode = code;
042            }
043    
044            public String getSymbol() {
045                    return symbol;
046            }
047    
048            public void setSymbol(String symbol) {
049                    this.symbol = symbol;
050            }
051    
052            public double getValue() {
053                    return value;
054            }
055    
056            public void setValue(double value) {
057                    this.value = value;
058            }
059            
060            public boolean isMultiple() {
061                    return false;
062            }
063            
064            @Override
065            public int hashCode() {
066                    final int prime = 31;
067                    return prime * (prime + indexCode) + ((symbol == null) ? 0 : symbol.hashCode());
068            }
069    
070            public boolean equals(Object obj) {
071                    if (this == obj)
072                            return true;
073                    if (obj == null)
074                            return false;
075                    if (getClass() != obj.getClass())
076                            return false;
077                    SingleFeatureValue other = (SingleFeatureValue) obj;
078                    if (indexCode != other.indexCode)
079                            return false;
080                    if (symbol == null) {
081                            if (other.symbol != null)
082                                    return false;
083                    } else if (!symbol.equals(other.symbol))
084                            return false;
085                    return super.equals(obj);
086            }
087            public String toString() {
088                    StringBuilder sb = new StringBuilder();
089                    sb.append(super.toString());
090                    sb.append('{');
091                    sb.append(symbol);
092                    sb.append("->");
093                    sb.append(indexCode);
094                    sb.append('}');
095                    return sb.toString();
096            }
097    }