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 ArrayList<String> arguments = new ArrayList<>();
+
+ public final List<String> arguments = new ArrayList<>();
final ArgumentCount argumentCount;
- private final ArrayList<String> aliases = new ArrayList<>();
+ private final List<String> aliases = new ArrayList<>();
/**
* Indicates that at least one argument is mandatory for this parameter.
*/
* If this parameter was present in the commandline, then this boolean will
* be set to <code>true</code>.
*/
- private boolean parameterSpecified;
+ private boolean specified;
public Parameter(final boolean mandatory,
final ArgumentCount argumentCount, final String description,
}
@SuppressWarnings("unchecked")
- public T addAliases(final String... aliasArray) {
+ public I addAliases(final String... aliasArray) {
// save aliases
Collections.addAll(aliases, aliasArray);
- return (T) this;
+ return (I) this;
}
/**
}
/**
- * @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();
// 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("...");
return buffer.toString();
}
- public abstract Object getValue();
+ public abstract T getValue();
public boolean isMandatory() {
return mandatory;
/**
* @return the parameterSpecified
*/
- public boolean isParameterSpecified() {
- return parameterSpecified;
+ public boolean isSpecified() {
+ return specified;
}
/**
- * @param parameterSpecified the parameterSpecified to set
+ * @param specified the parameterSpecified to set
*/
- public void setParameterSpecified(final boolean parameterSpecified) {
- this.parameterSpecified = parameterSpecified;
+ protected void setSpecified(final boolean specified) {
+ this.specified = specified;
}
/**
}
@SuppressWarnings("unchecked")
- public T setMandatory() {
+ public I setMandatory() {
mandatory = true;
- return (T) this;
+ return (I) this;
}
/**