--- /dev/null
+/*
+ * Svjatoslav Commons - shared library of common functionality. Author: Svjatoslav Agejenko.
+ * This project is released under Creative Commons Zero (CC0) license.
+ */
+package eu.svjatoslav.commons.commandline.parameterparser.parameter;
+
+import eu.svjatoslav.commons.commandline.parameterparser.ArgumentCount;
+import eu.svjatoslav.commons.commandline.parameterparser.Parameter;
+
+import java.io.File;
+import java.util.List;
+import java.util.stream.Collectors;
+
+public class DirectoryParameters extends Parameter<List<File>, DirectoryParameters> {
+
+ private ExistenceType existenceType = ExistenceType.DOES_NOT_MATTER;
+
+ public DirectoryParameters(final String description) {
+ super(description, ArgumentCount.MULTI);
+ }
+
+ @Override
+ public String describeFormat() {
+ return existenceType.description + " directories";
+ }
+
+ @Override
+ public List<File> getValue() {
+ return arguments.stream().map(File::new).collect(Collectors.toList());
+ }
+
+ public DirectoryParameters mustExist() {
+ existenceType = ExistenceType.MUST_EXIST;
+ return this;
+ }
+
+ public DirectoryParameters mustNotExist() {
+ existenceType = ExistenceType.MUST_NOT_EXIST;
+ return this;
+ }
+
+ @Override
+ public boolean validate(final String value) {
+ final File file = new File(value);
+
+ if (existenceType == ExistenceType.MUST_EXIST) {
+ return file.exists() && file.isDirectory();
+ }
+
+ if (existenceType == ExistenceType.MUST_NOT_EXIST) {
+ return !file.exists();
+ }
+
+ if (existenceType == ExistenceType.DOES_NOT_MATTER) {
+ if (file.exists())
+ if (file.isFile())
+ return false;
+
+ return true;
+ }
+
+ return false;
+ }
+
+}