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