01: package org.incava.lang;
02:
03: import java.io.*;
04: import java.util.*;
05:
06: public class Range {
07: private int first;
08:
09: private int last;
10:
11: public Range(int first, int last) {
12: this .first = first;
13: this .last = last;
14: }
15:
16: public int getFirst() {
17: return first;
18: }
19:
20: public void setFirst(int first) {
21: this .first = first;
22: if (first > last) {
23: last = first;
24: }
25: }
26:
27: public int getLast() {
28: return last;
29: }
30:
31: public void setLast(int last) {
32: this .last = last;
33: if (first > last) {
34: first = last;
35: }
36: }
37:
38: public boolean includes(int n) {
39: return n >= first && n <= last;
40: }
41:
42: public Object[] lastArray() {
43: return new Object[] { new Integer(first), new Integer(last) };
44: }
45:
46: public boolean equals(Object obj) {
47: if (obj instanceof Range) {
48: Range other = (Range) obj;
49: return first == other.first && last == other.last;
50: } else {
51: return false;
52: }
53: }
54:
55: public void expandTo(int i) {
56: if (i < first) {
57: first = i;
58: }
59: if (i > last) {
60: last = i;
61: }
62: }
63:
64: public String toString() {
65: return "[" + first + ", " + last + "]";
66: }
67:
68: }
|