001package org.maltparser.core.feature.value;
002
003import java.util.Set;
004import java.util.SortedMap;
005import java.util.TreeMap;
006
007import org.maltparser.core.feature.function.Function;
008import org.maltparser.core.helper.HashSet;
009/**
010 *  
011 *
012 * @author Johan Hall
013**/
014public class MultipleFeatureValue extends FeatureValue {
015        protected SortedMap<Integer, String> featureValues;
016        
017        public MultipleFeatureValue(Function function) {
018                super(function);
019                setFeatureValues(new TreeMap<Integer, String>()); 
020        }
021        
022        public void reset() {
023                super.reset();
024                featureValues.clear();
025        }
026        
027        public void addFeatureValue(int code, String Symbol) { 
028                featureValues.put(code, Symbol);
029        }
030        
031        protected void setFeatureValues(SortedMap<Integer, String> featureValues) { 
032                this.featureValues = featureValues;
033        }
034        
035        public Set<Integer> getCodes() {
036                return (Set<Integer>)featureValues.keySet();
037        }
038        
039        public int getFirstCode() {
040                return featureValues.firstKey();
041        }
042        
043        public Set<String> getSymbols() {
044                return new HashSet<String>(featureValues.values());
045        }
046        
047        public String getFirstSymbol() {
048                return featureValues.get(featureValues.firstKey());
049        }       
050        
051        public boolean isMultiple() {
052                return true;
053        }
054        
055        public int nFeatureValues() {
056                return featureValues.size();
057        }
058        
059        public boolean equals(Object obj) {
060                if (this == obj)
061                        return true;
062                if (obj == null)
063                        return false;
064                if (getClass() != obj.getClass())
065                        return false;
066                MultipleFeatureValue v = ((MultipleFeatureValue)obj);
067                if (!featureValues.equals(v.featureValues))
068                        return false;
069                return super.equals(obj);
070        }
071        
072        public String toString() {
073                final StringBuilder sb = new StringBuilder();
074                sb.append(super.toString());
075                sb.append('{');
076                for (Integer code : featureValues.keySet()) {
077                        sb.append('{');
078                        sb.append(featureValues.get(code));
079                        sb.append("->");
080                        sb.append(code);
081                        sb.append('}');
082                }
083                sb.append('}');
084                return sb.toString();
085        }
086}