Add Javadoc comments to enhance code clarity
[cli-helper.git] / src / main / java / eu / svjatoslav / commons / cli_helper / parameter_parser / parameter / DirectoryOption.java
index 8f97a8b..ee52751 100755 (executable)
@@ -9,19 +9,44 @@ import eu.svjatoslav.commons.cli_helper.parameter_parser.Option;
 
 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.SINGLE);
+        super(description, ParameterCount.ONE);
     }
 
     @Override
     public java.lang.String describeFormat() {
-        return existenceType.description + " directory";
+        switch (existenceType) {
+            case MUST_EXIST:
+                return "Existing directory.";
+            case MUST_NOT_EXIST:
+                return "Non-existing directory.";
+            default:
+                return "Directory.";
+        }
     }
 
+    /**
+     * 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() {
 
@@ -32,16 +57,32 @@ public class DirectoryOption extends Option<File, DirectoryOption> {
         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);