-
Notifications
You must be signed in to change notification settings - Fork 18
/
IntegerRange.cls
43 lines (39 loc) · 1.47 KB
/
IntegerRange.cls
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
/* ============================================================
* This code is part of the "apex-lang" open source project avaiable at:
*
* http://code.google.com/p/apex-lang/
*
* This code is licensed under the Apache License, Version 2.0. You may obtain a
* copy of the License at:
*
* http://www.apache.org/licenses/LICENSE-2.0
* ============================================================
*/
global class IntegerRange {
private Integer min;
private Integer max;
global IntegerRange(Integer number1){
if(number1 == null){
throw new IllegalArgumentException('illegal argument: null number');
}
min = max = number1;
}
global IntegerRange(Integer number1, Integer number2){
if(number1 == null || number2 == null){
throw new IllegalArgumentException('illegal argument: null number');
}
if(number1 < number2){
min = number1;
max = number2;
} else {
min = number2;
max = number1;
}
}
global Integer max(){ return max; }
global Integer min(){ return min;}
global String toAString(){ return '[' + min + ',' + max + ']'; }
global Boolean contains(Integer value){ return min <= value && value <= max; }
global Boolean contains(IntegerRange value){ return min <= value.min() && value.max() <= max; }
global Boolean overlaps(IntegerRange value){ return min <= value.max() && value.min() <= max; }
}