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.MULTI);
23 public String describeFormat() {
24 return existenceType.description + " directories";
28 public List<File> getValue() {
29 return parameters.stream().map(File::new).collect(Collectors.toList());
32 public DirectoryOptions mustExist() {
33 existenceType = ExistenceType.MUST_EXIST;
37 public DirectoryOptions mustNotExist() {
38 existenceType = ExistenceType.MUST_NOT_EXIST;
43 public boolean isValid(final String value) {
44 final File file = new File(value);
46 if (existenceType == ExistenceType.MUST_EXIST) {
47 return file.exists() && file.isDirectory();
50 if (existenceType == ExistenceType.MUST_NOT_EXIST) {
51 return !file.exists();
54 if (existenceType == ExistenceType.DOES_NOT_MATTER) {