more elegant parameter initialization
authorSvjatoslav Agejenko <svjatoslav@svjatoslav.eu>
Fri, 19 Dec 2014 20:37:47 +0000 (22:37 +0200)
committerSvjatoslav Agejenko <svjatoslav@svjatoslav.eu>
Fri, 19 Dec 2014 20:37:47 +0000 (22:37 +0200)
pom.xml
src/main/java/eu/svjatoslav/commons/commandline/parameterparser/Parser.java
src/test/java/eu/svjatoslav/commons/commandline/parameterparser/ParserTest.java

diff --git a/pom.xml b/pom.xml
index 16c2b80..deffea3 100755 (executable)
--- a/pom.xml
+++ b/pom.xml
@@ -1,4 +1,5 @@
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+       xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
        <modelVersion>4.0.0</modelVersion>
        <groupId>eu.svjatoslav</groupId>
        <artifactId>svjatoslavcommons</artifactId>
        <modelVersion>4.0.0</modelVersion>
        <groupId>eu.svjatoslav</groupId>
        <artifactId>svjatoslavcommons</artifactId>
@@ -64,8 +65,8 @@
                <extensions>
                        <extension>
                                <groupId>org.apache.maven.wagon</groupId>
                <extensions>
                        <extension>
                                <groupId>org.apache.maven.wagon</groupId>
-                               <artifactId>wagon-ssh</artifactId>
-                               <version>2.4</version>
+                               <artifactId>wagon-ssh-external</artifactId>
+                               <version>2.6</version>
                        </extension>
                </extensions>
        </build>
                        </extension>
                </extensions>
        </build>
                <snapshotRepository>
                        <id>svjatoslav.eu</id>
                        <name>svjatoslav.eu</name>
                <snapshotRepository>
                        <id>svjatoslav.eu</id>
                        <name>svjatoslav.eu</name>
-                       <url>scp://svjatoslav.eu/var/www/svjatoslav.eu/maven</url>
+                       <url>scpexe://svjatoslav.eu/var/www/svjatoslav.eu/maven</url>
                </snapshotRepository>
                <repository>
                        <id>svjatoslav.eu</id>
                        <name>svjatoslav.eu</name>
                </snapshotRepository>
                <repository>
                        <id>svjatoslav.eu</id>
                        <name>svjatoslav.eu</name>
-                       <url>scp://svjatoslav.eu/var/www/svjatoslav.eu/maven</url>
+                       <url>scpexe://svjatoslav.eu/var/www/svjatoslav.eu/maven</url>
                </repository>
        </distributionManagement>
 
                </repository>
        </distributionManagement>
 
index bd4cb17..e064cd5 100755 (executable)
@@ -11,13 +11,6 @@ package eu.svjatoslav.commons.commandline.parameterparser;
 
 import java.util.ArrayList;
 
 
 import java.util.ArrayList;
 
-import eu.svjatoslav.commons.commandline.parameterparser.parameter.DirectoryParameter;
-import eu.svjatoslav.commons.commandline.parameterparser.parameter.FileParameter;
-import eu.svjatoslav.commons.commandline.parameterparser.parameter.IntegerParameter;
-import eu.svjatoslav.commons.commandline.parameterparser.parameter.NullParameter;
-import eu.svjatoslav.commons.commandline.parameterparser.parameter.StringParameter;
-import eu.svjatoslav.commons.commandline.parameterparser.parameter.StringParameters;
-
 /**
  * <pre>
  * Single commandline parameter can have any amount of arguments.
 /**
  * <pre>
  * Single commandline parameter can have any amount of arguments.
@@ -27,52 +20,16 @@ public class Parser {
 
        private final ArrayList<Parameter> parameters = new ArrayList<Parameter>();
 
 
        private final ArrayList<Parameter> parameters = new ArrayList<Parameter>();
 
-       public void addParameter(final Parameter parameter) {
-               parameters.add(parameter);
-       }
-
-       public DirectoryParameter createDirectoryParameter(final String description) {
-               final DirectoryParameter parameter = new DirectoryParameter(description);
-               parameters.add(parameter);
-               return parameter;
-       }
-
-       public FileParameter createFileParameter(final String description) {
-               final FileParameter parameter = new FileParameter(description);
-               parameters.add(parameter);
-               return parameter;
-       }
-
-       public IntegerParameter createIntegerParameter(final String description) {
-               final IntegerParameter parameter = new IntegerParameter(description);
-               parameters.add(parameter);
-               return parameter;
-       }
-
-       public NullParameter createNullParameter(final String description) {
-               final NullParameter parameter = new NullParameter(description);
+       public <E extends Parameter> E add(final E parameter) {
                parameters.add(parameter);
                return parameter;
        }
 
                parameters.add(parameter);
                return parameter;
        }
 
-       public StringParameter createStringParameter(final String description) {
-               final StringParameter parameter = new StringParameter(description);
-               parameters.add(parameter);
-               return parameter;
-       }
-
-       public StringParameters createStringParameters(final String description) {
-               final StringParameters stingParameters = new StringParameters(
-                               description);
-               parameters.add(stingParameters);
-               return stingParameters;
-       }
-
        /**
         * Return parameter by given alias or <code>null</code> if no parameter
         * exists for given alias.
         */
        /**
         * Return parameter by given alias or <code>null</code> if no parameter
         * exists for given alias.
         */
-       public Parameter getParameterByAlias(final String alias) {
+       public Parameter findParameterByAlias(final String alias) {
 
                for (final Parameter parameter : parameters)
                        if (parameter.matchesAlias(alias))
 
                for (final Parameter parameter : parameters)
                        if (parameter.matchesAlias(alias))
@@ -91,7 +48,7 @@ public class Parser {
 
                for (final String argument : args) {
 
 
                for (final String argument : args) {
 
-                       final Parameter parameterForAlias = getParameterByAlias(argument);
+                       final Parameter parameterForAlias = findParameterByAlias(argument);
                        if (parameterForAlias == null) {
                                if (currentParameter == null) {
                                        System.out.println("Unknown commandline parameter: "
                        if (parameterForAlias == null) {
                                if (currentParameter == null) {
                                        System.out.println("Unknown commandline parameter: "
index 7917a77..e1640a0 100755 (executable)
@@ -32,11 +32,12 @@ public class ParserTest {
 
                // define allowed parameters
                final StringParameter helpParameter = parser
 
                // define allowed parameters
                final StringParameter helpParameter = parser
-                               .createStringParameter("Show help screen")
+                               .add(new StringParameter("Show help screen"))
                                .addAliases("--help", "-h").setMandatory();
 
                                .addAliases("--help", "-h").setMandatory();
 
-               final StringParameter compileParameter = parser.createStringParameter(
-                               "Compile code").addAliases("--compile", "-c");
+               final StringParameter compileParameter = parser.add(
+                               new StringParameter("Compile code")).addAliases("--compile",
+                               "-c");
 
                // check help generation
                parser.showHelp();
 
                // check help generation
                parser.showHelp();