1 package org.incava.lang; 2 3 import java.io.*; 4 import java.util.*; 5 6 7 public class Range 8 { 9 private int first; 10 11 private int last; 12 13 public Range(int first, int last) 14 { 15 this.first = first; 16 this.last = last; 17 } 18 19 public int getFirst() 20 { 21 return first; 22 } 23 24 public void setFirst(int first) 25 { 26 this.first = first; 27 if (first > last) { 28 last = first; 29 } 30 } 31 32 public int getLast() 33 { 34 return last; 35 } 36 37 public void setLast(int last) 38 { 39 this.last = last; 40 if (first > last) { 41 first = last; 42 } 43 } 44 45 public boolean includes(int n) 46 { 47 return n >= first && n <= last; 48 } 49 50 public Object [] lastArray() 51 { 52 return new Object [] { new Integer (first), new Integer (last) }; 53 } 54 55 public boolean equals(Object obj) 56 { 57 if (obj instanceof Range) { 58 Range other = (Range)obj; 59 return first == other.first && last == other.last; 60 } 61 else { 62 return false; 63 } 64 } 65 66 public void expandTo(int i) 67 { 68 if (i < first) { 69 first = i; 70 } 71 if (i > last) { 72 last = i; 73 } 74 } 75 76 public String toString() 77 { 78 return "[" + first + ", " + last + "]"; 79 } 80 81 } 82 | Popular Tags |