-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Expand file tree
/
Copy pathParam.java
More file actions
45 lines (35 loc) · 954 Bytes
/
Param.java
File metadata and controls
45 lines (35 loc) · 954 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
39
40
41
42
43
44
45
package com.reactnativenavigation.options.params;
import static com.reactnativenavigation.utils.ObjectUtils.equalsNotNull;
public abstract class Param<T> {
protected T value;
private boolean consumed;
Param(T value) {
this.value = value;
}
public T getAndConsume() {
T value = get();
consumed = true;
return value;
}
public void consume() {
consumed = true;
}
public T get() {
if (hasValue()) {
return value;
}
throw new RuntimeException("Tried to get null value!");
}
public T get(T defaultValue) {
return hasValue() ? value : defaultValue;
}
public boolean hasValue() {
return value != null && !consumed;
}
public boolean canApplyValue() {
return true;
}
public boolean equals(Param other) {
return value == other.value || equalsNotNull(value, other.value);
}
}