2 * Svjatoslav Commons - shared library of common functionality. Author: Svjatoslav Agejenko.
3 * This project is released under Creative Commons Zero (CC0) license.
5 package eu.svjatoslav.commons.cli_helper.parameter_parser.parameter;
7 import eu.svjatoslav.commons.cli_helper.parameter_parser.ParameterCount;
8 import eu.svjatoslav.commons.cli_helper.parameter_parser.Option;
11 import java.util.List;
12 import java.util.stream.Collectors;
14 public class DirectoryOptions extends Option<List<File>, DirectoryOptions> {
16 private ExistenceType existenceType = ExistenceType.DOES_NOT_MATTER;
18 public DirectoryOptions(final String description) {
19 super(description, ParameterCount.ONE_OR_MORE);
23 public String describeFormat() {
24 switch (existenceType) {
26 return "One to many existing directories.";
28 return "One to many non-existing directories.";
30 return "One to many directories.";
35 public List<File> getValue() {
36 return parameters.stream().map(File::new).collect(Collectors.toList());
39 public DirectoryOptions mustExist() {
40 existenceType = ExistenceType.MUST_EXIST;
44 public DirectoryOptions mustNotExist() {
45 existenceType = ExistenceType.MUST_NOT_EXIST;
50 public boolean isValid(final String value) {
51 final File file = new File(value);
53 if (existenceType == ExistenceType.MUST_EXIST) {
54 return file.exists() && file.isDirectory();
57 if (existenceType == ExistenceType.MUST_NOT_EXIST) {
58 return !file.exists();
61 if (existenceType == ExistenceType.DOES_NOT_MATTER) {