import java.io.File;
+
+/**
+ * This class is used to define commandline option which accepts directory as parameter.
+ */
public class DirectoryOption extends Option<File, DirectoryOption> {
+ /**
+ * This enum is used to define if directory shall exist in filesystem or not.
+ */
private ExistenceType existenceType = ExistenceType.DOES_NOT_MATTER;
+ /**
+ * Constructor.
+ *
+ * @param description Description of the option.
+ */
public DirectoryOption(final String description) {
super(description, ParameterCount.ONE);
}
}
}
+ /**
+ * Retrieves the value of the option as a {@link File} object.
+ *
+ * @return The value of the option as a {@link File} object.
+ * @throws RuntimeException if the option does not have exactly 1 argument.
+ */
@Override
public File getValue() {
return new File(parameters.get(0));
}
+ /**
+ * This method sets that directory shall exist.
+ *
+ * @return This object.
+ */
public DirectoryOption mustExist() {
existenceType = ExistenceType.MUST_EXIST;
return this;
}
+ /**
+ * This method sets that directory shall not exist.
+ *
+ * @return This object.
+ */
public DirectoryOption mustNotExist() {
existenceType = ExistenceType.MUST_NOT_EXIST;
return this;
}
+ /**
+ * This method checks if a provided directory path is valid based on the specified existence type.
+ *
+ * @param value The directory path to validate.
+ * @return True if the directory path is valid according to the existence type, otherwise false.
+ */
@Override
public boolean isValid(final java.lang.String value) {
final File file = new File(value);