--- /dev/null
+/*
+ * Svjatoslav Commons - shared library of common functionality. Author: Svjatoslav Agejenko.
+ * This project is released under Creative Commons Zero (CC0) license.
+ */
+package eu.svjatoslav.commons.cli_helper.parameter_parser.parameter;
+
+import eu.svjatoslav.commons.cli_helper.parameter_parser.ParameterCount;
+import eu.svjatoslav.commons.cli_helper.parameter_parser.Option;
+
+public class IntegerOption extends Option<Integer, IntegerOption> {
+
+ public IntegerOption(final String description) {
+ super(description, ParameterCount.SINGLE);
+ }
+
+ @Override
+ public java.lang.String describeFormat() {
+ return "integer";
+ }
+
+ @Override
+ public Integer getValue() {
+ if (parameters.size() != 1)
+ throw new RuntimeException("Parameter " + description
+ + " shall have exactly 1 argument.");
+ return Integer.parseInt(parameters.get(0));
+ }
+
+ @Override
+ public boolean isValid(final java.lang.String value) {
+ try {
+ java.lang.Integer.valueOf(value);
+ return true;
+ } catch (final NumberFormatException e) {
+ return false;
+ }
+ }
+}