Skip to content

Commit

Permalink
Differentiate between default and other recognized extensions
Browse files Browse the repository at this point in the history
  • Loading branch information
david-waltermire committed May 27, 2024
1 parent ca69d92 commit b4c452a
Showing 1 changed file with 27 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@
package gov.nist.secauto.metaschema.databind.io;

import gov.nist.secauto.metaschema.core.util.CollectionUtil;
import gov.nist.secauto.metaschema.core.util.ObjectUtils;

import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Locale;
import java.util.Set;
Expand All @@ -45,20 +45,22 @@ public enum Format {
/**
* The <a href="https://www.w3.org/XML/">Extensible Markup Language</a> format.
*/
XML(Set.of(".xml")),
XML(".xml", Set.of()),
/**
* The <a href="https://www.json.org/">JavaScript Object Notation</a> format.
*/
JSON(Set.of(".json")),
JSON(".json", Set.of()),
/**
* The <a href="https://yaml.org/">YAML Ain't Markup Language</a> format.
*/
YAML(Set.of(".yml", ".yaml"));
YAML(".yaml", Set.of(".yml"));

private static final List<String> NAMES;

@NonNull
private final Set<String> defaultExtensions;
private final String defaultExtension;
@NonNull
private final Set<String> recognizedExtensions;

static {
NAMES = Arrays.stream(values())
Expand All @@ -76,8 +78,24 @@ public static List<String> names() {
return NAMES;
}

Format(Set<String> defaultExtensions) {
this.defaultExtensions = CollectionUtil.unmodifiableSet(ObjectUtils.requireNonNull(defaultExtensions));
Format(@NonNull String defaultExtension, Set<String> otherExtensions) {
this.defaultExtension = defaultExtension;

Set<String> recognizedExtensions = new HashSet<>();
recognizedExtensions.add(defaultExtension);
recognizedExtensions.addAll(otherExtensions);

this.recognizedExtensions = CollectionUtil.unmodifiableSet(recognizedExtensions);
}

/**
* Get the default extension to use for the format.
*
* @return the default extension
*/
@NonNull
public Set<String> getRecognizedExtensions() {
return recognizedExtensions;
}

/**
Expand All @@ -86,7 +104,7 @@ public static List<String> names() {
* @return the default extension
*/
@NonNull
public Set<String> getDefaultExtension() {
return defaultExtensions;
public String getDefaultExtension() {
return defaultExtension;
}
}

0 comments on commit b4c452a

Please sign in to comment.