1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74
|
package com.wcohen.ss.abbvGapsHmm;
import java.util.Comparator;
/**
* @author Dana Movshovitz-Attias
*/
public class Acronym implements Comparable<Acronym>{
public String _shortForm;
public String _longForm;
public Integer _frequency = null;
public Double _probability = null;
public AbbreviationAlignmentContainer<AbbvGapsHMM.Emissions, AbbvGapsHMM.States> _alignment = null;
int _hashCode;
public Acronym(String shortForm, String longForm){
_shortForm = shortForm;
_longForm = longForm;
_hashCode = (_shortForm+"\t"+_longForm).hashCode();
}
public Acronym(String shortForm, String longForm, Integer frequency){
this(shortForm, longForm);
_frequency = frequency;
}
/* (non-Javadoc)
* @see java.lang.Comparable#compareTo(java.lang.Object)
*/
public int compareTo(Acronym o) {
int compScore = _shortForm.compareTo(o._shortForm);
if(compScore == 0){
compScore = _longForm.compareTo(o._longForm);
}
return compScore;
}
public boolean equals(Object o){
if ( this == o ) return true;
if ( !(o instanceof Acronym) ) return false;
Acronym oPair = (Acronym)o;
return this.compareTo(oPair) == 0;
}
public int hashCode(){
return _hashCode;
}
public static class AcronymShortFormComparator implements Comparator<Acronym>{
public int compare(Acronym t1, Acronym t2) {
return t1._shortForm.compareTo(t2._shortForm);
}
}
public static class AcronymFrequencyComparator implements Comparator<Acronym>{
public int compare(Acronym t1, Acronym t2) {
return new Integer(t1._frequency).compareTo(t2._frequency);
}
}
public String toString(){
return _shortForm+"\t"+_longForm;
}
public String toStringWithFrequency(){
return toString()+"\t"+_frequency;
}
}
|