Added Javadoc comments to Option and Parameter classes to provide a more detailed explanation of their functionalities. Changes include explanations for each method and variable in these classes. This aims to improve code readability and provide clearer direction for future development.
import static java.util.Collections.addAll;
import static java.util.stream.Collectors.joining;
+/**
+ * Represents an option that can be provided on CLI.
+ * This class allows specifying whether the option is mandatory,
+ * the parameter count, a description, and any aliases for the option.
+ *
+ * @param <T> type of value that this option returns.
+ * @param <I> type of this option.
+ */
public abstract class Option<T, I extends Option> {
/**
*/
private boolean isPresent;
+ /**
+ * Represents an option that can be provided on CLI.
+ * This class allows specifying whether the option is mandatory,
+ * the parameter count, a description, and any aliases for the option.
+ *
+ * @param mandatory indicates whether the option is mandatory
+ * @param parameterCount the number of parameters required for the option
+ * @param description a description of the option
+ * @param aliases2 any additional aliases for the option
+ */
public Option(final boolean mandatory,
final ParameterCount parameterCount, final String description,
final String... aliases2) {
this.parameterCount = parameterCount;
}
+ /**
+ * Adds additional aliases to the option.
+ *
+ * @param aliasArray an array of strings representing the aliases to be added
+ * @return the modified option object
+ */
@SuppressWarnings("unchecked")
public I addAliases(final String... aliasArray) {
}
/**
- * @return help for this option.
+ * Returns the help message for this parameter.
+ *
+ * @return the help message as a string.
*/
public String getHelp() {
final StringBuilder result = new StringBuilder();
return result.toString();
}
+ /**
+ * Returns the value of the object.
+ *
+ * @return the value of the object.
+ */
public abstract T getValue();
public boolean isMandatory() {
}
/**
- * @return the parameterSpecified
+ * @return <code>true</code> if this parameter was present in the commandline.
*/
public boolean isPresent() {
return isPresent;
}
/**
- * @param present the parameterSpecified to set
+ * Sets the present status of this parameter.
+ *
+ * @param present <code>true</code> if this parameter is present in the command line,
+ * <code>false</code> otherwise.
*/
protected void setPresent(final boolean present) {
this.isPresent = present;
return true;
}
+ /**
+ * Sets the option as mandatory. This means that the option must be provided by the user
+ * in order for the program to run successfully.
+ *
+ * @return The updated instance of the option.
+ */
@SuppressWarnings("unchecked")
public I setMandatory() {
mandatory = true;
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);
import java.util.List;
import java.util.stream.Collectors;
+/**
+ * DirectoryOptions class represents a command-line option for one or more directories.
+ */
public class DirectoryOptions extends Option<List<File>, DirectoryOptions> {
+ /**
+ * This enum is used to define if resource denoted by particular option parameter shall exist or not.
+ * <p>
+ * This allows to specify for example if directory shall exist or not.
+ */
private ExistenceType existenceType = ExistenceType.DOES_NOT_MATTER;
+ /**
+ * Creates a new DirectoryOptions object with the given description.
+ *
+ * @param description The description of the directory options.
+ */
public DirectoryOptions(final String description) {
super(description, ParameterCount.ONE_OR_MORE);
}
+ /**
+ * Returns a string describing the format of the option.
+ *
+ * @return A string describing the format of the option.
+ */
@Override
public String describeFormat() {
switch (existenceType) {
}
}
+ /**
+ * Returns the value of the option as a list of File objects.
+ *
+ * @return The value of the option as a list of File objects.
+ */
@Override
public List<File> getValue() {
return parameters.stream().map(File::new).collect(Collectors.toList());
return this;
}
+
@Override
public boolean isValid(final String value) {
final File file = new File(value);
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;
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;
import static eu.svjatoslav.commons.cli_helper.parameter_parser.parameter.FileOption.validateFile;
+/**
+ * This class represents commandline option which accepts one or more parameters
+ * which are files.
+ */
public class FileOptions extends Option<List<File>, FileOptions> {
private ExistenceType existenceType = ExistenceType.DOES_NOT_MATTER;
return parameters.stream().map(File::new).collect(Collectors.toList());
}
+ /**
+ * This method is used to define that file shall exist in filesystem.
+ *
+ * @return This object.
+ */
public FileOptions mustExist() {
existenceType = ExistenceType.MUST_EXIST;
return this;
}
+ /**
+ * This method is used to define that file shall not exist in filesystem.
+ *
+ * @return This object.
+ */
public FileOptions mustNotExist() {
existenceType = ExistenceType.MUST_NOT_EXIST;
return this;
import eu.svjatoslav.commons.cli_helper.parameter_parser.ParameterCount;
import eu.svjatoslav.commons.cli_helper.parameter_parser.Option;
+/**
+ * This class represents commandline option which accepts exactly one parameter
+ * which is an integer.
+ */
public class IntegerOption extends Option<Integer, IntegerOption> {
public IntegerOption(final String description) {
import eu.svjatoslav.commons.cli_helper.parameter_parser.ParameterCount;
import eu.svjatoslav.commons.cli_helper.parameter_parser.Option;
+/**
+ * This class represents commandline option which accepts exactly zero parameters.
+ */
public class NullOption extends Option<Boolean, NullOption> {
public NullOption(final String description) {
import eu.svjatoslav.commons.cli_helper.parameter_parser.ParameterCount;
import eu.svjatoslav.commons.cli_helper.parameter_parser.Option;
+/**
+ * This class represents commandline option which accepts exactly one parameter
+ * which is a string.
+ */
public class StringOption extends Option<String, StringOption> {
public final String defaultValue;
import java.util.List;
+/**
+ * This class represents commandline option which accepts one or more parameters
+ * which are strings.
+ */
public class StringOptions extends Option<List<String>, StringOptions> {
public StringOptions(final String description) {