1
2
3
4
5
6
7
8
9
10
11
12
13 package org.abstracthorizon.mercury.imap.util;
14
15
16
17
18
19
20
21 public class SimpleSequence implements Sequence {
22
23
24 protected int min = Integer.MIN_VALUE;
25
26
27 protected int max = Integer.MAX_VALUE;
28
29
30 protected int ptr = min;
31
32
33
34
35 public SimpleSequence() {
36 }
37
38
39
40
41
42 public int getMin() {
43 return min;
44 }
45
46
47
48
49
50 public void setMin(int min) {
51 this.min = min;
52 }
53
54
55
56
57
58 public int getMax() {
59 return max;
60 }
61
62
63
64
65
66 public void setMax(int max) {
67 this.max = max;
68 }
69
70
71
72
73
74 public void setLowerLimit(int lower) {
75 if (lower > min) {
76 min = lower;
77 }
78 }
79
80
81
82
83
84 public void setUpperLimit(int upper) {
85 if (upper < max) {
86 max = upper;
87 }
88 }
89
90
91
92
93 public void first() {
94 ptr = min;
95 }
96
97
98
99
100
101 public boolean more() {
102 return ptr <= max;
103 }
104
105
106
107
108
109 public int next() {
110 int r = ptr;
111 ptr = ptr + 1;
112 return r;
113 }
114
115
116
117
118
119
120 public boolean equals(Object o) {
121 if (o instanceof SimpleSequence) {
122 SimpleSequence s = (SimpleSequence)o;
123 if ((s.getMax() == max) && (s.getMin() == min)) {
124 return true;
125 }
126 }
127 return false;
128 }
129
130
131
132
133
134 public int hashCode() {
135 return min+max;
136 }
137
138
139
140
141
142
143 public int compareTo(Sequence o) {
144 Sequence s = (Sequence)o;
145 int i = getMin()+getMax();
146 int t = s.getMax()+s.getMin();
147 if (i < t) {
148 return -1;
149 } else if (i > t) {
150 return 1;
151 } else {
152 return 0;
153 }
154 }
155
156
157
158
159
160 public String toString() {
161 StringBuffer res = new StringBuffer();
162 if (min == max) {
163 res.append(min);
164 } else {
165 if (min == Integer.MIN_VALUE) {
166 res.append('*');
167 } else {
168 res.append(min);
169 }
170 res.append(':');
171 if (max == Integer.MAX_VALUE) {
172 res.append('*');
173 } else {
174 res.append(max);
175 }
176 }
177 return res.toString();
178 }
179 }