-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathIntRange.java
More file actions
38 lines (31 loc) · 939 Bytes
/
IntRange.java
File metadata and controls
38 lines (31 loc) · 939 Bytes
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
package net.marcellperger.mathexpr;
import org.jetbrains.annotations.Nullable;
import java.util.Objects;
public class IntRange {
int lo, hi;
protected IntRange(int min, int max, int ignoredMarker) {
if(min > max) throw new IllegalArgumentException("min must be grater than max");
lo = min;
hi = max;
}
public IntRange(@Nullable Integer min, @Nullable Integer max) {
this(Objects.requireNonNullElse(min, Integer.MIN_VALUE),
Objects.requireNonNullElse(max, Integer.MAX_VALUE), /*marker*/0);
}
public IntRange() {
this(null, null);
}
public int getMin() {
return lo;
}
public int getMax() {
return hi;
}
public boolean includes(int v) {
return lo <= v && v <= hi;
}
public String fancyRepr() {
if(lo == hi) return "exactly %d".formatted(lo);
return "%d to %d".formatted(lo, hi);
}
}