@@ -0,0 +1,1967 @@
+package range;%0A%0Apublic class IntRange implements Range%3CInteger%3E %7B%0A  protected int lower;%0A  protected int upper;%0A%0A  public IntRange(int lower, int upper) %7B%0A    this.lower = lower;%0A    this.upper = upper;%0A  %7D%0A%0A  public Range%3CInteger%3E merge(Range%3CInteger%3E other) %7B%0A    Range%3CInteger%3E ret = null;%0A    if (canMerge(other)) %7B%0A      ret = new IntRange(Math.min(lower, other.getLower()), Math.max(upper, other.getUpper()));%0A    %7D%0A    return ret;%0A  %7D%0A%0A  public boolean mergeIntoSelf(Range%3CInteger%3E other) %7B%0A    boolean ret = canMerge(other);%0A    if (ret) %7B%0A      this.lower = Math.min(lower, other.getLower());%0A      this.upper = Math.max(upper, other.getUpper());%0A    %7D%0A    return ret;%0A  %7D%0A%0A  public Integer getLower() %7B%0A    return lower;%0A  %7D%0A%0A  public Integer getUpper() %7B%0A    return upper;%0A  %7D%0A%0A  public boolean canMerge(Range%3CInteger%3E other) %7B%0A    boolean ret = (other.getLower() %3C= this.upper + 1 %7C%7C this.lower %3C= other.getUpper() + 1);%0A    // boolean ret = (other.compareTo(high + 1) == 0) %7C%7C (other.compareTo(low - 1) == 0);%0A    return ret;%0A  %7D%0A%0A  /*%0A  public int compareTo(Integer o) %7B%0A    return compareTo(o.intValue());%0A  %7D%0A  */%0A%0A  public int compareTo(int i) %7B%0A    int ret = (i %3C lower ? -1 : (i %3C= upper ? 0 : 1));%0A    return ret;%0A  %7D%0A%0A  public int compareTo(Range%3CInteger%3E o) %7B%0A    int ret = 0;%0A    if (o.getUpper() %3C lower) %7B%0A      ret = 1;%0A    %7D else if (upper %3C o.getLower()) %7B%0A      ret = -1;%0A    %7D else %7B%0A      ret = 0; // Only indicates that there is %3Csome%3E overlap! This does not create a total ordering on all %3Ccode%3EIntRange%3C/code%3Es%0A    %7D%0A    return ret;%0A  %7D%0A%0A  public boolean contains(Range%3CInteger%3E other) %7B%0A    boolean ret = (compareTo(other.getLower()) == 0 && compareTo(other.getUpper()) == 0);%0A    return ret;%0A  %7D%0A%0A  public Integer increment(Integer i) %7B%0A    return i + 1;%0A  %7D%0A%0A  public boolean equals(Object obj) %7B%0A    boolean ret = false;%0A    if (obj instanceof IntRange) %7B%0A      ret = (compareTo((IntRange)obj) == 0);%0A    %7D%0A    return ret;%0A  %7D%0A%7D%0A

Create IntRange.java