From: Svjatoslav Agejenko Date: Fri, 20 Mar 2015 22:02:42 +0000 (+0200) Subject: minor updates X-Git-Tag: svjatoslavcommons-1.8~78 X-Git-Url: http://www2.svjatoslav.eu/gitweb/?a=commitdiff_plain;h=a8164358cbf6ceedabae88880078307b604db829;p=svjatoslav_commons.git minor updates + slight code refactoring + documentation update --- diff --git a/doc/index.html b/doc/index.html index ca5ad74..61599bf 100644 --- a/doc/index.html +++ b/doc/index.html @@ -4,7 +4,7 @@ Svjatoslav Commons - Java library of commonly used functions - + @@ -180,15 +180,30 @@ License or later as published by the Free Software Foundation. Library contains:

-

2 Usage

@@ -244,7 +268,7 @@ Maven pom.xml file snippet:

Author: Svjatoslav Agejenko

-

Created: 2015-03-01 Sun 19:03

+

Created: 2015-03-21 Sat 00:00

Emacs 24.4.1 (Org mode 8.2.10)

Validate

diff --git a/doc/index.org b/doc/index.org index 4d7cb24..cfb8b4b 100644 --- a/doc/index.org +++ b/doc/index.org @@ -16,18 +16,34 @@ * General Library contains: -- Wildcards matcher. (?, *) +- Commandline Interface helper - Commandline arguments parser and validator. +- Bit input and output streams. + +- Slightly enhanced data input and output streams. + +- Byte array to HEX string converter. + +- Utility that tries to quess user desktop directory. + - File path parser. +- File IO helper. + - Graphical error dialog. - Reusable graphical dialog to capture and show program exceptions and associated program call stack traceback. -- Primitive URL parameters encoder / decoder. +- Primitive and simple component to add navigation menus to the web + sites. + +- String tokenizer. +- Improved String, optimized for dealing with prefixes and suffixes. + +- Wildcards matcher. (?, *) * Usage Instructions to embed svjatoslav-commons in your project as a library: diff --git a/src/main/java/eu/svjatoslav/commons/commandline/parameterparser/ArgumentCount.java b/src/main/java/eu/svjatoslav/commons/commandline/parameterparser/ArgumentCount.java index e97c8cf..0d9e23d 100755 --- a/src/main/java/eu/svjatoslav/commons/commandline/parameterparser/ArgumentCount.java +++ b/src/main/java/eu/svjatoslav/commons/commandline/parameterparser/ArgumentCount.java @@ -1,7 +1,7 @@ /* * Svjatoslav Commons - shared library of common functionality. * Copyright ©2012-2014, Svjatoslav Agejenko, svjatoslav@svjatoslav.eu - * + * * This program is free software; you can redistribute it and/or * modify it under the terms of version 3 of the GNU Lesser General Public License * or later as published by the Free Software Foundation. @@ -11,6 +11,8 @@ package eu.svjatoslav.commons.commandline.parameterparser; public enum ArgumentCount { - NONE, SINGLE, MULTI + NONE, // parameter has no arguments + SINGLE, // parameter has one argument + MULTI // parameter can have multiple arguments } diff --git a/src/main/java/eu/svjatoslav/commons/commandline/parameterparser/Parameter.java b/src/main/java/eu/svjatoslav/commons/commandline/parameterparser/Parameter.java index f259f7f..fd22c89 100755 --- a/src/main/java/eu/svjatoslav/commons/commandline/parameterparser/Parameter.java +++ b/src/main/java/eu/svjatoslav/commons/commandline/parameterparser/Parameter.java @@ -68,8 +68,8 @@ public abstract class Parameter { // check if arguments are allowed for this parameter if (argumentCount.equals(ArgumentCount.NONE)) { System.out - .println("Error! No arguments are allowed for parameters: " - + getAliases()); + .println("Error! No arguments are allowed for parameters: " + + getAliases()); return false; } @@ -77,8 +77,8 @@ public abstract class Parameter { if ((arguments.size() > 0) && (argumentCount.equals(ArgumentCount.SINGLE))) { System.out - .println("Error! Only single argument is allowed for parameters: " - + getAliases()); + .println("Error! Only single argument is allowed for parameters: " + + getAliases()); return false; } 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 e064cd5..69b26dc 100755 --- a/src/main/java/eu/svjatoslav/commons/commandline/parameterparser/Parser.java +++ b/src/main/java/eu/svjatoslav/commons/commandline/parameterparser/Parser.java @@ -25,6 +25,22 @@ public class Parser { return parameter; } + /** + * @return true if no errors were found. false + * otherwise. + */ + private boolean checkMandatoryArgumentsPresent() { + + for (final Parameter parameter : parameters) + if (parameter.isMandatory() && (!parameter.isParameterSpecified())) { + System.out.println("Error! Mandatory parameter (" + + parameter.getAliases() + ") is not specified."); + return false; + } + + return true; + } + /** * Return parameter by given alias or null if no parameter * exists for given alias. @@ -70,16 +86,7 @@ public class Parser { } - // check if any mandatory parameters are missing - - for (final Parameter parameter : parameters) - if (parameter.isMandatory() && (!parameter.isParameterSpecified())) { - System.out.println("Error! Mandatory parameter (" - + parameter.getAliases() + ") is not specified."); - return false; - } - - return true; + return checkMandatoryArgumentsPresent(); } public void showHelp() {