package org.tallison.lucene.syns;
public class TermDoublePair implements Valuable {
private String term = "";
private double val = 0.0;
public TermDoublePair(String term, double val){
this.term = term;
this.val = val;
}
public double getValue(){
return val;
}
public String getKey(){
return term;
}
public String toString(){
return term +" : " + val;
}
public boolean equals(Object other){
if (other instanceof TermDoublePair){
TermDoublePair op = (TermDoublePair)other;
if (equalVal(op.getValue()) && op.getKey().equals(term) ){
return true;
}
}
return false;
}
private boolean equalVal(double other){
return Math.abs(val - other) < .00000001;
}
public int compareTo(TermDoublePair other){
if (other.getKey().equals(term)){
if (equalVal(other.getValue())){
return 0;
} else if (val > getValue()){
return 1;
} else {
return 0;
}
} else {
return term.compareTo(other.getKey());
}
}
public int hashCode(){
return term.hashCode() + (int)val;
}
}