projects
/
svjatoslav_commons.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Updated copyright info
[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
8141339
..
5940435
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,6
+1,6
@@
/*
* Svjatoslav Commons - shared library of common functionality.
/*
* Svjatoslav Commons - shared library of common functionality.
- * Copyright ©2012-20
14
, Svjatoslav Agejenko, svjatoslav@svjatoslav.eu
+ * Copyright ©2012-20
20
, 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
*
* 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
@@
-11,13
+11,20
@@
package eu.svjatoslav.commons.commandline.parameterparser;
import java.util.ArrayList;
import java.util.Collections;
import java.util.ArrayList;
import java.util.Collections;
+import java.util.List;
-public abstract class Parameter<T> {
+public abstract class Parameter<T
, I extends Parameter
> {
+ /**
+ * Purpose of this argument, like: input image path, compression level, etc...
+ *
+ * Note: for describing argument type (file, integer, ...) there is {@link #describeFormat()}.
+ */
public final String description;
public final String description;
- public final ArrayList<String> arguments = new ArrayList<>();
+
+ public final List<String> arguments = new ArrayList<>();
final ArgumentCount argumentCount;
final ArgumentCount argumentCount;
- private final
Array
List<String> aliases = new ArrayList<>();
+ private final List<String> aliases = new ArrayList<>();
/**
* Indicates that at least one argument is mandatory for this parameter.
*/
/**
* Indicates that at least one argument is mandatory for this parameter.
*/
@@
-26,7
+33,7
@@
public abstract class Parameter<T> {
* If this parameter was present in the commandline, then this boolean will
* be set to <code>true</code>.
*/
* If this parameter was present in the commandline, then this boolean will
* be set to <code>true</code>.
*/
- private boolean
parameterS
pecified;
+ private boolean
s
pecified;
public Parameter(final boolean mandatory,
final ArgumentCount argumentCount, final String description,
public Parameter(final boolean mandatory,
final ArgumentCount argumentCount, final String description,
@@
-47,12
+54,12
@@
public abstract class Parameter<T> {
}
@SuppressWarnings("unchecked")
}
@SuppressWarnings("unchecked")
- public
T
addAliases(final String... aliasArray) {
+ public
I
addAliases(final String... aliasArray) {
// save aliases
Collections.addAll(aliases, aliasArray);
// save aliases
Collections.addAll(aliases, aliasArray);
- return (
T
) this;
+ return (
I
) this;
}
/**
}
/**
@@
-92,7
+99,10
@@
public abstract class Parameter<T> {
}
/**
}
/**
- * @return Single line argument type description.
+ * @return Single line argument type description. If argument type should be file,
+ * date, integer, regular expression, etc..
+ *
+ * Note: for argument purpose description there is {@link #description}
*/
public abstract String describeFormat();
*/
public abstract String describeFormat();
@@
-116,7
+126,11
@@
public abstract class Parameter<T> {
// first line
buffer.append(getAliases());
if (!argumentCount.equals(ArgumentCount.NONE)) {
// first line
buffer.append(getAliases());
if (!argumentCount.equals(ArgumentCount.NONE)) {
- buffer.append(" (" + describeFormat() + ")");
+ buffer
+ .append(" (")
+ .append(isMandatory() ? "mandatory, " : "")
+ .append(describeFormat())
+ .append(")");
if (argumentCount.equals(ArgumentCount.MULTI))
buffer.append("...");
if (argumentCount.equals(ArgumentCount.MULTI))
buffer.append("...");
@@
-129,7
+143,7
@@
public abstract class Parameter<T> {
return buffer.toString();
}
return buffer.toString();
}
- public abstract
Object
getValue();
+ public abstract
T
getValue();
public boolean isMandatory() {
return mandatory;
public boolean isMandatory() {
return mandatory;
@@
-138,15
+152,15
@@
public abstract class Parameter<T> {
/**
* @return the parameterSpecified
*/
/**
* @return the parameterSpecified
*/
- public boolean is
Parameter
Specified() {
- return
parameterS
pecified;
+ public boolean isSpecified() {
+ return
s
pecified;
}
/**
}
/**
- * @param
parameterS
pecified the parameterSpecified to set
+ * @param
s
pecified the parameterSpecified to set
*/
*/
- p
ublic void setParameterSpecified(final boolean parameterS
pecified) {
- this.
parameterSpecified = parameterS
pecified;
+ p
rotected void setSpecified(final boolean s
pecified) {
+ this.
specified = s
pecified;
}
/**
}
/**
@@
-180,9
+194,9
@@
public abstract class Parameter<T> {
}
@SuppressWarnings("unchecked")
}
@SuppressWarnings("unchecked")
- public
T
setMandatory() {
+ public
I
setMandatory() {
mandatory = true;
mandatory = true;
- return (
T
) this;
+ return (
I
) this;
}
/**
}
/**