From: Svjatoslav Agejenko Date: Fri, 19 Dec 2014 20:37:47 +0000 (+0200) Subject: more elegant parameter initialization X-Git-Tag: svjatoslavcommons-1.8~90 X-Git-Url: http://www2.svjatoslav.eu/gitweb/?a=commitdiff_plain;h=be3c81cebf77e98c2723b61b26969ebdbc7a3082;p=svjatoslav_commons.git more elegant parameter initialization --- diff --git a/pom.xml b/pom.xml index 16c2b80..deffea3 100755 --- a/pom.xml +++ b/pom.xml @@ -1,4 +1,5 @@ - + 4.0.0 eu.svjatoslav svjatoslavcommons @@ -64,8 +65,8 @@ org.apache.maven.wagon - wagon-ssh - 2.4 + wagon-ssh-external + 2.6 @@ -90,12 +91,12 @@ svjatoslav.eu svjatoslav.eu - scp://svjatoslav.eu/var/www/svjatoslav.eu/maven + scpexe://svjatoslav.eu/var/www/svjatoslav.eu/maven svjatoslav.eu svjatoslav.eu - scp://svjatoslav.eu/var/www/svjatoslav.eu/maven + scpexe://svjatoslav.eu/var/www/svjatoslav.eu/maven diff --git a/src/main/java/eu/svjatoslav/commons/commandline/parameterparser/Parser.java b/src/main/java/eu/svjatoslav/commons/commandline/parameterparser/Parser.java index bd4cb17..e064cd5 100755 --- a/src/main/java/eu/svjatoslav/commons/commandline/parameterparser/Parser.java +++ b/src/main/java/eu/svjatoslav/commons/commandline/parameterparser/Parser.java @@ -11,13 +11,6 @@ package eu.svjatoslav.commons.commandline.parameterparser; 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; - /** *
  * Single commandline parameter can have any amount of arguments.
@@ -27,52 +20,16 @@ public class Parser {
 
 	private final ArrayList parameters = new ArrayList();
 
-	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 add(final E 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 null 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))
@@ -91,7 +48,7 @@ public class Parser {
 
 		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: "
diff --git a/src/test/java/eu/svjatoslav/commons/commandline/parameterparser/ParserTest.java b/src/test/java/eu/svjatoslav/commons/commandline/parameterparser/ParserTest.java
index 7917a77..e1640a0 100755
--- a/src/test/java/eu/svjatoslav/commons/commandline/parameterparser/ParserTest.java
+++ b/src/test/java/eu/svjatoslav/commons/commandline/parameterparser/ParserTest.java
@@ -32,11 +32,12 @@ public class ParserTest {
 
 		// define allowed parameters
 		final StringParameter helpParameter = parser
-				.createStringParameter("Show help screen")
+				.add(new StringParameter("Show help screen"))
 				.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();