+/*
+ * 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.");
@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;
+ }
+ }
}