-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathMode.java
More file actions
72 lines (56 loc) · 2.18 KB
/
Copy pathMode.java
File metadata and controls
72 lines (56 loc) · 2.18 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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
package fr.insee.genesis.domain.model.surveyunit;
import com.fasterxml.jackson.annotation.JsonCreator;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Getter;
import org.jspecify.annotations.Nullable;
import java.util.HashMap;
import java.util.Map;
@Getter
public enum Mode {
WEB("WEB", "WEB", "CAWI"),
TEL("TEL", "ENQ", "CATI"),
F2F("F2F", "ENQ", "CAPI"),
OTHER("OTHER", "", ""),
PAPER("PAPER", "", "PAPI");
@Nullable
@Schema(nullable = true, type = "string", allowableValues = { "WEB", "TEL", "F2F", "PAPER", "OTHER" })
private final String modeName;
private final String folder;
private final String jsonName;
Mode(@Nullable String modeName, String folder, String jsonName) {
this.modeName = modeName;
this.folder = folder;
this.jsonName = jsonName;
}
// lookup Maps
private static final Map<String, Mode> BY_MODE_NAME = new HashMap<>();
private static final Map<String, Mode> BY_JSON_NAME = new HashMap<>();
private static final Map<String, Mode> BY_ANY_NAME = new HashMap<>();
static {
for (Mode mode : values()) {
if (mode.modeName != null && !mode.modeName.isBlank()) {
BY_MODE_NAME.put(mode.modeName.toUpperCase(), mode);
BY_ANY_NAME.put(mode.modeName.toUpperCase(), mode);
}
if (mode.jsonName != null && !mode.jsonName.isBlank()) {
BY_JSON_NAME.put(mode.jsonName.toUpperCase(), mode);
BY_ANY_NAME.put(mode.jsonName.toUpperCase(), mode);
}
}
}
@JsonCreator
public static Mode fromString(String value) {
if (value == null){ return null;}
Mode mode = BY_ANY_NAME.get(value.trim().toUpperCase());
if (mode != null) { return mode; }
throw new IllegalArgumentException("Invalid Mode: " + value);
}
public static Mode getEnumFromModeName(@Nullable String modeName) {
if (modeName == null) { return null; }
return BY_MODE_NAME.get(modeName.trim().toUpperCase());
}
public static Mode getEnumFromJsonName(@Nullable String jsonName) {
if (jsonName == null) { return null; }
return BY_JSON_NAME.get(jsonName.trim().toUpperCase());
}
}