2 * To change this template, choose Tools | Templates
3 * and open the template in the editor.
5 package TransactionalIO.Utilities;
12 public class Range implements Comparable {
20 public Range(long start, long end) {
25 public long getEnd() {
29 public void setEnd(long end) {
33 public long getStart() {
37 public void setStart(long start) {
41 public Range intersection(Range secondrange) {
42 if ((secondrange.start <= this.start) && (this.start <= secondrange.end)) {
43 return new Range(this.start, Math.min(this.end, secondrange.end));
44 } else if ((secondrange.start <= this.end) && (this.end <= secondrange.end)) {
45 return new Range(Math.max(this.start, secondrange.start), this.end);
46 } else if ((this.start <= secondrange.start) && (secondrange.end <= this.end)) {
47 return new Range(secondrange.start, secondrange.end);
53 public boolean hasIntersection(Range secondrange) {
54 if ((secondrange.start <= this.start) && (this.start <= secondrange.end)) {
56 } else if ((secondrange.start <= this.end) && (this.end <= secondrange.end)) {
58 } else if ((this.start <= secondrange.start) && (secondrange.end <= this.end)) {
66 public boolean includes(Range secondrange) {
67 if (this.start <= secondrange.start && secondrange.end <= this.end) {
74 public Range[] minus(Range[] intersectedranges, int size) {
75 Range[] tmp = new Range[size + 1];
78 if (this.start < intersectedranges[0].start) {
79 tmp[counter] = new Range(this.start, intersectedranges[0].start);
82 for (int i = 1; i < size; i++) {
83 tmp[counter] = new Range(intersectedranges[i - 1].end, intersectedranges[i].start);
86 if (this.end > intersectedranges[size - 1].end) {
87 tmp[counter] = new Range(intersectedranges[size - 1].end, this.end);
90 Range[] result = new Range[counter];
91 for (int i = 0; i < counter; i++) {
97 public int compareTo(Object arg0) {
99 Range tmp = (Range) arg0;
100 if (this.start < tmp.start) {
102 } else if (this.start == tmp.start) {