rendered paste bodyclass CmpX implements Comparator { public int compare(Object arg0, Object arg1) { int erg = ((Compareable2D)arg0).compareToX((Compareable2D)arg1); if(erg==0){ erg += ((Compareable2D)arg0).compareToY((Compareable2D)arg1); } return erg; }}; public class TreeSet2D extends TreeSet{ public TreeSet2D(){ super(new CmpX()); } public LinkedList getRegion(Location topleft, Location bottomright){ SortedSet xFits = subSet(topleft, bottomright); LinkedList list = new LinkedList(); Iterator xFitsIterator = xFits.iterator(); while( xFitsIterator.hasNext()){ Location loc = (Location) xFitsIterator.next(); if (loc.y >= topleft.y && loc.y <= bottomright.y){ list.add(loc); } } return list; }}