-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUIntRange.java
More file actions
36 lines (29 loc) · 1.05 KB
/
UIntRange.java
File metadata and controls
36 lines (29 loc) · 1.05 KB
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
package net.marcellperger.mathexpr;
import org.jetbrains.annotations.Contract;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.Objects;
public class UIntRange extends IntRange {
protected UIntRange(int min, int max, int ignoredMarker) {
super(workaround(() -> {
if(min < 0 || max < 0) throw new IllegalArgumentException();
}, min), max, ignoredMarker);
}
public UIntRange(@Nullable Integer min, @Nullable Integer max) {
this(Objects.requireNonNullElse(min, 0),
Objects.requireNonNullElse(max, Integer.MAX_VALUE), /*marker*/0);
}
public UIntRange() {
this(null, null);
}
/**
* Workaround to allow us to run code before super() call.
* This is required because java insists that super() be this first statement!
* So not even static stuff can be ran!
*/
@Contract("_, _ -> param2")
private static <T> T workaround(@NotNull Runnable r, T returnValue) {
r.run();
return returnValue;
}
}