1 19 20 package org.netbeans.modules.java.codegen; 21 22 import org.openide.text.PositionRef; 23 import org.openide.text.PositionBounds; 24 30 class PositionComparator implements java.util.Comparator { 31 public int compare(java.lang.Object p1, java.lang.Object p2) { 32 if (p1 instanceof Integer ) { 33 return comparePosToBinding((Integer )p1, (ElementBinding)p2); 34 } else if (p2 instanceof PositionRef) { 35 return -comparePosToBinding((Integer )p2, (ElementBinding)p1); 36 } 37 ElementBinding b1 = (ElementBinding)p1; 38 ElementBinding b2 = (ElementBinding)p2; 39 40 return b1.wholeBounds.getBegin().getOffset() - 41 b2.wholeBounds.getBegin().getOffset(); 42 } 43 44 private int comparePosToBinding(Integer iPos, ElementBinding b) { 45 int off = iPos.intValue(); 46 PositionBounds w = b.wholeBounds; 47 if (w.getBegin().getOffset() <= off && 48 w.getEnd().getOffset() > off) 49 return 0; 50 return off - w.getBegin().getOffset(); 51 } 52 53 public boolean equals(java.lang.Object p1) { 54 return (p1 instanceof PositionComparator); 55 } 56 } 57 | Popular Tags |