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