1
2
3
4
5
6 package gov.nist.secauto.metaschema.databind.io;
7
8 import gov.nist.secauto.metaschema.core.util.CollectionUtil;
9
10 import java.util.Arrays;
11 import java.util.HashSet;
12 import java.util.List;
13 import java.util.Locale;
14 import java.util.Set;
15 import java.util.stream.Collectors;
16
17 import edu.umd.cs.findbugs.annotations.NonNull;
18 import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
19
20
21
22
23 public enum Format {
24
25
26
27 XML(".xml", Set.of()),
28
29
30
31 JSON(".json", Set.of()),
32
33
34
35 YAML(".yaml", Set.of(".yml"));
36
37 private static final List<String> NAMES;
38
39 @NonNull
40 private final String defaultExtension;
41 @NonNull
42 private final Set<String> recognizedExtensions;
43
44 static {
45 NAMES = Arrays.stream(values())
46 .map(format -> format.name().toLowerCase(Locale.ROOT))
47 .collect(Collectors.toUnmodifiableList());
48 }
49
50
51
52
53
54
55 @SuppressFBWarnings(value = "MS_EXPOSE_REP", justification = "Exposes names provided by the enum")
56 public static List<String> names() {
57 return NAMES;
58 }
59
60 Format(@NonNull String defaultExtension, Set<String> otherExtensions) {
61 this.defaultExtension = defaultExtension;
62
63 Set<String> recognizedExtensions = new HashSet<>();
64 recognizedExtensions.add(defaultExtension);
65 recognizedExtensions.addAll(otherExtensions);
66
67 this.recognizedExtensions = CollectionUtil.unmodifiableSet(recognizedExtensions);
68 }
69
70
71
72
73
74
75 @NonNull
76 public Set<String> getRecognizedExtensions() {
77 return recognizedExtensions;
78 }
79
80
81
82
83
84
85 @NonNull
86 public String getDefaultExtension() {
87 return defaultExtension;
88 }
89 }