import java.util.ArrayList;
import java.util.Collections;
+import java.util.List;
public abstract class Parameter<T, I extends Parameter> {
public final String description;
- public final ArrayList<String> arguments = new ArrayList<>();
+ public final List<String> arguments = new ArrayList<>();
final ArgumentCount argumentCount;
- private final ArrayList<String> aliases = new ArrayList<>();
+ private final List<String> aliases = new ArrayList<>();
/**
* Indicates that at least one argument is mandatory for this parameter.
*/
--- /dev/null
+/*
+ * Svjatoslav Commons - shared library of common functionality.
+ * Copyright ©2012-2017, Svjatoslav Agejenko, svjatoslav@svjatoslav.eu
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of version 3 of the GNU Lesser General Public License
+ * or later as published by the Free Software Foundation.
+ */
+
+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;
+
+import static eu.svjatoslav.commons.commandline.parameterparser.parameter.FileParameter.validateFile;
+
+public class FileParameters extends Parameter<List<File>, FileParameters> {
+
+ private ExistenceType existenceType = ExistenceType.DOES_NOT_MATTER;
+
+ public FileParameters(final String description) {
+ super(description, ArgumentCount.MULTI);
+ }
+
+ @Override
+ public String describeFormat() {
+ return existenceType.description + " files";
+ }
+
+ @Override
+ public List<File> getValue() {
+ return arguments.stream().map(File::new).collect(Collectors.toList());
+ }
+
+ public FileParameters mustExist() {
+ existenceType = ExistenceType.MUST_EXIST;
+ return this;
+ }
+
+ public FileParameters mustNotExist() {
+ existenceType = ExistenceType.MUST_NOT_EXIST;
+ return this;
+ }
+
+ @Override
+ public boolean validate(final String value) {
+ return validateFile(existenceType, value);
+ }
+
+}