projects
/
svjatoslav_commons.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Changed license to LGPLv3 or later.
[svjatoslav_commons.git]
/
src
/
main
/
java
/
eu
/
svjatoslav
/
commons
/
commandline
/
parameterparser
/
Parameter.java
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
d9e78da
..
2e1c03a
100755
(executable)
--- a/
src/main/java/eu/svjatoslav/commons/commandline/parameterparser/Parameter.java
+++ b/
src/main/java/eu/svjatoslav/commons/commandline/parameterparser/Parameter.java
@@
-1,10
+1,10
@@
/*
* Svjatoslav Commons - shared library of common functionality.
/*
* Svjatoslav Commons - shared library of common functionality.
- * Copyright ©2012-201
3
, Svjatoslav Agejenko, svjatoslav@svjatoslav.eu
+ * Copyright ©2012-201
4
, Svjatoslav Agejenko, svjatoslav@svjatoslav.eu
*
* This program is free software; you can redistribute it and/or
*
* This program is free software; you can redistribute it and/or
- * modify it under the terms of version
2 of the GNU
General Public License
- * as published by the Free Software Foundation.
+ * 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;
*/
package eu.svjatoslav.commons.commandline.parameterparser;
@@
-13,15
+13,13
@@
import java.io.File;
import java.util.ArrayList;
import java.util.List;
import java.util.ArrayList;
import java.util.List;
-public class Parameter {
+public
abstract
class Parameter {
/**
* Indicates that at least one argument is mandatory for this parameter.
*/
protected boolean mandatory;
/**
* Indicates that at least one argument is mandatory for this parameter.
*/
protected boolean mandatory;
- private final Argument argumentType;
-
private final ArrayList<String> aliases = new ArrayList<String>();
public final String description;
private final ArrayList<String> aliases = new ArrayList<String>();
public final String description;
@@
-36,20
+34,11
@@
public class Parameter {
*/
private boolean parameterSpecified;
*/
private boolean parameterSpecified;
- public Parameter(final Argument argumentType, final String description,
- final ArgumentCount argumentCount) {
-
- this.description = description;
- this.argumentType = argumentType;
- this.argumentCount = argumentCount;
- };
-
public Parameter(final boolean mandatory,
public Parameter(final boolean mandatory,
- final ArgumentCount argumentCount, final
Argument argumentType
,
- final String
description, final String
... aliases2) {
+ final ArgumentCount argumentCount, final
String description
,
+ final String... aliases2) {
this.mandatory = mandatory;
this.mandatory = mandatory;
- this.argumentType = argumentType;
this.description = description;
this.argumentCount = argumentCount;
this.description = description;
this.argumentCount = argumentCount;
@@
-57,6
+46,11
@@
public class Parameter {
for (final String alias : aliases2)
aliases.add(alias);
for (final String alias : aliases2)
aliases.add(alias);
+ };
+
+ public Parameter(final String description, final ArgumentCount argumentCount) {
+ this.description = description;
+ this.argumentCount = argumentCount;
}
public Parameter addAliases(final String... aliasArray) {
}
public Parameter addAliases(final String... aliasArray) {
@@
-90,10
+84,10
@@
public class Parameter {
return false;
}
return false;
}
- if (!
argumentType.
validate(argumentString)) {
+ if (!validate(argumentString)) {
System.out.println("Error! Invalid argument \"" + argumentString
System.out.println("Error! Invalid argument \"" + argumentString
- + "\". It shall be " +
argumentType.
describeFormat() + ".");
+ + "\". It shall be " + describeFormat() + ".");
return false;
}
return false;
}
@@
-103,6
+97,11
@@
public class Parameter {
return true;
}
return true;
}
+ /**
+ * @return Single line argument type description.
+ */
+ public abstract String describeFormat();
+
public String getAliases() {
final StringBuffer buffer = new StringBuffer();
public String getAliases() {
final StringBuffer buffer = new StringBuffer();
@@
-148,7
+147,7
@@
public class Parameter {
// first line
buffer.append(getAliases());
if (!argumentCount.equals(ArgumentCount.NONE)) {
// first line
buffer.append(getAliases());
if (!argumentCount.equals(ArgumentCount.NONE)) {
- buffer.append(" (" +
argumentType.
describeFormat() + ")");
+ buffer.append(" (" + describeFormat() + ")");
if (argumentCount.equals(ArgumentCount.MULTI))
buffer.append("...");
if (argumentCount.equals(ArgumentCount.MULTI))
buffer.append("...");
@@
-216,4
+215,10
@@
public class Parameter {
this.parameterSpecified = parameterSpecified;
}
this.parameterSpecified = parameterSpecified;
}
+ /**
+ * @return <code>true</code> if value is correct, <code>false</code>
+ * otherwise.
+ */
+ public abstract boolean validate(String value);
+
}
}