1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 package net.sf.webmancer.util.integerset;
22
23 public class Interval {
24 public enum RelativePosition {
25 LOWER, LEFT_OUTSIDE, INSIDE, EQUAL, RIGHT_OUTSIDE, GREATER, OVER
26 }
27
28 private int from;
29
30 private int to;
31
32 public Interval(final int from, final int to) {
33 this.from = from;
34 this.to = to;
35 }
36
37
38
39
40 public int getFrom() {
41 return this.from;
42 }
43
44
45
46
47 public int getTo() {
48 return this.to;
49 }
50
51
52
53
54
55 public boolean contains(final int integer) {
56 return (this.from <= integer) && (integer <= this.to);
57 }
58
59
60
61
62
63 public RelativePosition getRelativePositionTo(final Interval interval) {
64 if (this.to < interval.getFrom()) {
65 return RelativePosition.LOWER;
66
67 } else if (this.from > interval.getTo()) {
68 return RelativePosition.GREATER;
69
70 } else if (this.from == interval.getFrom() && this.to == interval.getTo()) {
71 return RelativePosition.EQUAL;
72
73 } else if (this.from < interval.getFrom()) {
74
75 if (this.to <= interval.getTo()) {
76 return RelativePosition.LEFT_OUTSIDE;
77 } else {
78 return RelativePosition.OVER;
79 }
80
81 } else {
82
83 if (this.to <= interval.getTo()) {
84 return RelativePosition.INSIDE;
85 } else {
86 return RelativePosition.RIGHT_OUTSIDE;
87 }
88 }
89 }
90
91 }