    001    package org.maltparser.core.feature.value;
    002
    003    import java.util.HashMap;
    004    import java.util.HashSet;
    005    import java.util.Map;
    006    import java.util.Set;
    007    import java.util.SortedMap;
    008    import java.util.TreeMap;
    009
    010    import org.maltparser.core.feature.function.Function;
    011    /**
    012     *
    013     *
    014     * @author Johan Hall
    015     * @since 1.0
    016    **/
    017    public class MultipleFeatureValue extends FeatureValue {
    018            protected SortedMap<Integer, String> featureValues;
    019            protected Map<Integer, Boolean> featureKnown;
    020
    021            public MultipleFeatureValue(Function function) {
    022                    super(function);
    023                    setFeatureValues(new TreeMap<Integer, String>(), new HashMap<Integer, Boolean>());
    024            }
    025
    026            public void reset() {
    027                    super.reset();
    028                    featureValues.clear();
    029                    featureKnown.clear();
    030            }
    031
    032            public void addFeatureValue(int code, String Symbol, boolean known) {
    033                    featureValues.put(code, Symbol);
    034                    featureKnown.put(code, known);
    035            }
    036
    037            protected void setFeatureValues(SortedMap<Integer, String> featureValues, Map<Integer, Boolean> featureKnown) {
    038                    this.featureValues = featureValues;
    039                    this.featureKnown = featureKnown;
    040            }
    041
    042            public Set<Integer> getCodes() {
    043                    return (Set<Integer>)featureValues.keySet();
    044            }
    045
    046            public int getFirstCode() {
    047                    return featureValues.firstKey();
    048            }
    049
    050            public Set<String> getSymbols() {
    051                    return new HashSet<String>(featureValues.values());
    052            }
    053
    054            public String getFirstSymbol() {
    055                    return featureValues.get(featureValues.firstKey());
    056            }
    057
    058            public boolean isKnown(int value) {
    059                    return featureKnown.get(value);
    060            }
    061
    062            public String toString() {
    063                    final StringBuilder sb = new StringBuilder();
    064                    sb.append(super.toString()+ "{ ");
    065                    for (Integer code : featureValues.keySet()) {
    066                            sb.append("{"+featureValues.get(code) + "->" +code + ", known="+featureKnown.get(code)+"} ");
    067                    }
    068                    sb.append("}");
    069                    return sb.toString();
    070            }
    071    }