Added special commandline argument type to support multiple strings.
[svjatoslav_commons.git] / src / main / java / eu / svjatoslav / commons / commandline / parameterparser / parameter / IntegerParameter.java
old mode 100644 (file)
new mode 100755 (executable)
index 7af305b..7c75151
@@ -1,22 +1,36 @@
+/*
+ * 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.
+ */
+
 package eu.svjatoslav.commons.commandline.parameterparser.parameter;
 
 import eu.svjatoslav.commons.commandline.parameterparser.ArgumentCount;
 import eu.svjatoslav.commons.commandline.parameterparser.Parameter;
-import eu.svjatoslav.commons.commandline.parameterparser.type.IntegerArgument;
 
 public class IntegerParameter extends Parameter {
 
        public IntegerParameter(final String description) {
-               super(new IntegerArgument(), description, ArgumentCount.SINGLE);
+               super(description, ArgumentCount.SINGLE);
        }
 
        @Override
        public IntegerParameter addAliases(final String... aliasArray) {
-               super.addAliases(aliasArray);
+               super.addAliasesProtected(aliasArray);
                return this;
        }
 
-       public int getValue() {
+       @Override
+       public java.lang.String describeFormat() {
+               return "integer";
+       }
+
+       @Override
+       public Integer getValue() {
                if (arguments.size() != 1)
                        throw new RuntimeException("Parameter " + description
                                        + " shall have exactly 1 argument.");
@@ -25,7 +39,17 @@ public class IntegerParameter extends Parameter {
 
        @Override
        public IntegerParameter setMandatory() {
-               mandatory = true;
+               setMandatoryProtected();
                return this;
        }
+
+       @Override
+       public boolean validate(final java.lang.String value) {
+               try {
+                       java.lang.Integer.valueOf(value);
+                       return true;
+               } catch (final NumberFormatException e) {
+                       return false;
+               }
+       }
 }