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