X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=src%2Fedu%2Fberkeley%2Fsbp%2Fmisc%2FCartesian.java;h=23e588412024a2e16ad261d4a1ce5020f9aab919;hb=82f9b8d4a2fadb14cb004e5cc9f14944458f2e6c;hp=6627fbf1c5b8ce6c77240db2810347fc12152034;hpb=a96edcbb9051f33f65256dcd5adcbae6925956eb;p=sbp.git diff --git a/src/edu/berkeley/sbp/misc/Cartesian.java b/src/edu/berkeley/sbp/misc/Cartesian.java index 6627fbf..23e5884 100644 --- a/src/edu/berkeley/sbp/misc/Cartesian.java +++ b/src/edu/berkeley/sbp/misc/Cartesian.java @@ -51,7 +51,7 @@ public class Cartesian { public int getRow() { return row; } public Location(int col, int row) { this.row = row; this.col = col; } public int compareTo(Input.Location loc) throws ClassCastException { - if (!(loc instanceof Cartesian)) throw new ClassCastException(); + if (!(loc instanceof Cartesian.Location)) throw new ClassCastException(loc.getClass().getName()); Location c = (Location)loc; if (row < c.row) return -1; if (row > c.row) return 1; @@ -59,5 +59,24 @@ public class Cartesian { if (col > c.col) return 1; return 0; } + public Input.Region createRegion(Input.Location loc) { + return new Region(this, (Cartesian.Location)loc); } + } + + public static class Region implements Input.Region { + public final Location start; + public final Location end; + public String toString() { + if (start.row==end.row) return start.row+":"+(start.col+"-"+end.col); + return start+"-"+end; + } + public Region(Location a, Location b) { + switch(a.compareTo(b)) { + case -1: + case 0: start=a; end=b; return; + case 1: start=b; end=a; return; + default: throw new Error("impossible"); + } + } } }