package ca.umontreal.iro.rali; import java.util.Comparator; /** * Pair with a String and a count of its occurrences * to be used in a Map * */ public class PathCount implements Comparable{ private int val; private String path; /** * Initialize the count to 1 for this path string * @param path */ PathCount(String path){ this.path=path; this.val=1; } public String toString(){return path+":"+val;} /** * Accessor for the path * @return string describing the path */ public String getPath(){return path;} /** * Accessor for the count * @return the number of occurrences of this path */ public int getVal(){return val;} /** * Increment the count by one of this XPath */ public void bump(){val++;} /** * The hashcode of this element is the one of the string of the XPath * @see java.lang.Object#hashCode() */ public int hashCode(){ return path.hashCode(); } /** * Two paths are equals if their string are equal * @see java.lang.Object#equals(java.lang.Object) */ public boolean equals(Object that){ if(that==null)return false; if(!(that instanceof PathCount))return false; PathCount thatC = (PathCount) that; return path.equals(thatC.path); } /** * Natural comparison on the alphabetic value of the string * @see java.lang.Comparable#compareTo(java.lang.Object) */ public int compareTo(PathCount that){ return this.path.compareTo(that.path); } /** * Decreasing frequency comparator */ public static Comparator decVal = new Comparator(){ public int compare(PathCount c1,PathCount c2){ return c2.getVal()-c1.getVal(); } }; }