import java.io.File;
+/**
+ * This class represents commandline option which accepts exactly one parameter
+ * which is a file.
+ */
public class FileOption extends Option<File, FileOption> {
private ExistenceType existenceType = ExistenceType.DOES_NOT_MATTER;
public FileOption(final String description) {
- super(description, ParameterCount.SINGLE);
+ super(description, ParameterCount.ONE);
}
protected static boolean validateFile(ExistenceType existenceType, String value) {
@Override
public java.lang.String describeFormat() {
- return existenceType.description + " file";
+ switch (existenceType) {
+ case MUST_EXIST:
+ return "Existing file.";
+ case MUST_NOT_EXIST:
+ return "Non-existing file.";
+ default:
+ return "File.";
+ }
}
@Override
return new File(parameters.get(0));
}
+ /**
+ * This method sets that file shall exist.
+ *
+ * @return This object.
+ */
public FileOption mustExist() {
existenceType = ExistenceType.MUST_EXIST;
return this;
}
+ /**
+ * This method sets that file shall not exist.
+ *
+ * @return This object.
+ */
public FileOption mustNotExist() {
existenceType = ExistenceType.MUST_NOT_EXIST;
return this;