    001    package org.maltparser.ml.lib;
    002
    003
    004    public class MaltFeatureNode implements Comparable<MaltFeatureNode> {
    005
    006            int index;
    007            double value;
    008
    009            public MaltFeatureNode() {
    010                    index = -1;
    011                    value = 0;
    012            }
    013
    014            public MaltFeatureNode(int index, double value) {
    015                    setIndex(index);
    016                    setValue(value);
    017            }
    018
    019            public int getIndex() {
    020                    return index;
    021            }
    022
    023            public void setIndex(int index) {
    024                    this.index = index;
    025            }
    026
    027            public double getValue() {
    028                    return value;
    029            }
    030
    031            public void setValue(double value) {
    032                    this.value = value;
    033            }
    034
    035            public void clear() {
    036                    index = -1;
    037                    value = 0;
    038            }
    039            public int hashCode() {
    040                    final int prime = 31;
    041                    final long temp = Double.doubleToLongBits(value);
    042                    int result = prime * 1 + index;
    043                    result = prime * result + (int) (temp ^ (temp >>> 32));
    044                    return result;
    045            }
    046
    047            public boolean equals(Object obj) {
    048                    if (this == obj)
    049                            return true;
    050                    if (obj == null)
    051                            return false;
    052                    if (getClass() != obj.getClass())
    053                            return false;
    054                    MaltFeatureNode other = (MaltFeatureNode) obj;
    055                    if (index != other.index)
    056                            return false;
    057                    if (Double.doubleToLongBits(value) != Double.doubleToLongBits(other.value))
    058                            return false;
    059                    return true;
    060            }
    061
    062            public int compareTo(MaltFeatureNode aThat) {
    063                    final int BEFORE = -1;
    064                    final int EQUAL = 0;
    065                    final int AFTER = 1;
    066
    067                    if (this == aThat)
    068                            return EQUAL;
    069
    070                    if (this.index < aThat.index)
    071                            return BEFORE;
    072                    if (this.index > aThat.index)
    073                            return AFTER;
    074
    075                    if (this.value < aThat.value)
    076                            return BEFORE;
    077                    if (this.value > aThat.value)
    078                            return AFTER;
    079
    080                    return EQUAL;
    081            }
    082
    083            public String toString() {
    084                    return "XNode [index=" + index + ", value=" + value + "]";
    085            }
    086    }