Created
December 31, 2018 18:02
-
-
Save benjishults/2b6969fb38583c01b85f465a3841f7df to your computer and use it in GitHub Desktop.
DocumentType first pass in enum refactoring demo
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public enum DocumentType { | |
TXT("txt", "text"), | |
MD("md", "markdown"), | |
HTML("html", "htm"); | |
String[] extensions; | |
DocumentType(String... extensions) { | |
this.extensions = Arrays.copyOf(extensions, extensions.length); | |
} | |
public static DocumentType forPath(Path file) { | |
String ext = FileNameHelper.getLowercaseExtension(file); | |
for (DocumentType type : DocumentType.values()) { | |
if (Arrays.stream(type.extensions).anyMatch(ext::equals)) { | |
return type; | |
} | |
} | |
return null; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment