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        @Override
064        public int hashCode() {
065                final int prime = 31;
066                return prime * (prime + indexCode) + ((symbol == null) ? 0 : symbol.hashCode());
067        }
068
069        public boolean equals(Object obj) {
070                if (this == obj)
071                        return true;
072                if (obj == null)
073                        return false;
074                if (getClass() != obj.getClass())
075                        return false;
076                SingleFeatureValue other = (SingleFeatureValue) obj;
077                if (indexCode != other.indexCode)
078                        return false;
079                if (symbol == null) {
080                        if (other.symbol != null)
081                                return false;
082                } else if (!symbol.equals(other.symbol))
083                        return false;
084                return super.equals(obj);
085        }
086        public String toString() {
087                StringBuilder sb = new StringBuilder();
088                sb.append(super.toString());
089                sb.append('{');
090                sb.append(symbol);
091                sb.append("->");
092                sb.append(indexCode);
093                sb.append('}');
094                return sb.toString();
095        }
096}