    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 isMultiple() {
    053                    return true;
    054            }
    055
    056            public boolean equals(Object obj) {
    057                    if (this == obj)
    058                            return true;
    059                    if (obj == null)
    060                            return false;
    061                    if (getClass() != obj.getClass())
    062                            return false;
    063                    MultipleFeatureValue v = ((MultipleFeatureValue)obj);
    064                    if (!featureValues.equals(v.featureValues))
    065                            return false;
    066                    return super.equals(obj);
    067            }
    068
    069            public String toString() {
    070                    final StringBuilder sb = new StringBuilder();
    071                    sb.append(super.toString());
    072                    sb.append('{');
    073                    for (Integer code : featureValues.keySet()) {
    074                            sb.append('{');
    075                            sb.append(featureValues.get(code));
    076                            sb.append("->");
    077                            sb.append(code);
    078                            sb.append('}');
    079                    }
    080                    sb.append('}');
    081                    return sb.toString();
    082            }
    083    }