Skip to content

Commit f29d5d7

Browse files
Differentiate between default and other recognized extensions
1 parent 879e58d commit f29d5d7

File tree

1 file changed

+27
-9
lines changed
  • databind/src/main/java/gov/nist/secauto/metaschema/databind/io

1 file changed

+27
-9
lines changed

databind/src/main/java/gov/nist/secauto/metaschema/databind/io/Format.java

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,9 @@
2727
package gov.nist.secauto.metaschema.databind.io;
2828

2929
import gov.nist.secauto.metaschema.core.util.CollectionUtil;
30-
import gov.nist.secauto.metaschema.core.util.ObjectUtils;
3130

3231
import java.util.Arrays;
32+
import java.util.HashSet;
3333
import java.util.List;
3434
import java.util.Locale;
3535
import java.util.Set;
@@ -45,20 +45,22 @@ public enum Format {
4545
/**
4646
* The <a href="https://www.w3.org/XML/">Extensible Markup Language</a> format.
4747
*/
48-
XML(Set.of(".xml")),
48+
XML(".xml", Set.of()),
4949
/**
5050
* The <a href="https://www.json.org/">JavaScript Object Notation</a> format.
5151
*/
52-
JSON(Set.of(".json")),
52+
JSON(".json", Set.of()),
5353
/**
5454
* The <a href="https://yaml.org/">YAML Ain't Markup Language</a> format.
5555
*/
56-
YAML(Set.of(".yml", ".yaml"));
56+
YAML(".yaml", Set.of(".yml"));
5757

5858
private static final List<String> NAMES;
5959

6060
@NonNull
61-
private final Set<String> defaultExtensions;
61+
private final String defaultExtension;
62+
@NonNull
63+
private final Set<String> recognizedExtensions;
6264

6365
static {
6466
NAMES = Arrays.stream(values())
@@ -76,8 +78,24 @@ public static List<String> names() {
7678
return NAMES;
7779
}
7880

79-
Format(Set<String> defaultExtensions) {
80-
this.defaultExtensions = CollectionUtil.unmodifiableSet(ObjectUtils.requireNonNull(defaultExtensions));
81+
Format(@NonNull String defaultExtension, Set<String> otherExtensions) {
82+
this.defaultExtension = defaultExtension;
83+
84+
Set<String> recognizedExtensions = new HashSet<>();
85+
recognizedExtensions.add(defaultExtension);
86+
recognizedExtensions.addAll(otherExtensions);
87+
88+
this.recognizedExtensions = CollectionUtil.unmodifiableSet(recognizedExtensions);
89+
}
90+
91+
/**
92+
* Get the default extension to use for the format.
93+
*
94+
* @return the default extension
95+
*/
96+
@NonNull
97+
public Set<String> getRecognizedExtensions() {
98+
return recognizedExtensions;
8199
}
82100

83101
/**
@@ -86,7 +104,7 @@ public static List<String> names() {
86104
* @return the default extension
87105
*/
88106
@NonNull
89-
public Set<String> getDefaultExtension() {
90-
return defaultExtensions;
107+
public String getDefaultExtension() {
108+
return defaultExtension;
91109
}
92110
}

0 commit comments

Comments
 (0)