roxspring 2004/04/20 13:59:19 Modified: cli/src/java/org/apache/commons/cli2/option Tag: RESEARCH_CLI_2_ROXSPRING PropertyOption.java GroupImpl.java DefaultOption.java Switch.java ParentImpl.java OptionImpl.java Command.java ArgumentImpl.java cli/src/java/org/apache/commons/cli2 Tag: RESEARCH_CLI_2_ROXSPRING Argument.java Group.java Option.java Log: isRequired(), getMinimum() and getMaximum() refactored into the Option, Argument and Group interfaces Revision Changes Path No revision No revision 1.1.2.3 +1 -1 jakarta-commons/cli/src/java/org/apache/commons/cli2/option/Attic/PropertyOption.java Index: PropertyOption.java =================================================================== RCS file: /home/cvs/jakarta-commons/cli/src/java/org/apache/commons/cli2/option/Attic/PropertyOption.java,v retrieving revision 1.1.2.2 retrieving revision 1.1.2.3 diff -u -r1.1.2.2 -r1.1.2.3 --- PropertyOption.java 14 Apr 2004 18:31:16 -0000 1.1.2.2 +++ PropertyOption.java 20 Apr 2004 20:59:19 -0000 1.1.2.3 @@ -57,7 +57,7 @@ final String optionString, final String description, final int id) { - super(id); + super(id,false); this.optionString = optionString; this.description = description; this.prefixes = Collections.singleton(optionString); 1.1.2.4 +5 -9 jakarta-commons/cli/src/java/org/apache/commons/cli2/option/Attic/GroupImpl.java Index: GroupImpl.java =================================================================== RCS file: /home/cvs/jakarta-commons/cli/src/java/org/apache/commons/cli2/option/Attic/GroupImpl.java,v retrieving revision 1.1.2.3 retrieving revision 1.1.2.4 diff -u -r1.1.2.3 -r1.1.2.4 --- GroupImpl.java 19 Apr 2004 21:35:10 -0000 1.1.2.3 +++ GroupImpl.java 20 Apr 2004 20:59:19 -0000 1.1.2.4 @@ -66,7 +66,7 @@ final int minimum, final int maximum) { - super(0); + super(0,false); this.name = name; this.description = description; @@ -433,21 +433,17 @@ return null; } - /** - * Gets the minimum number of member Options for a valid CommandLine - * @return the minimum number of member Options - */ public int getMinimum() { return minimum; } - /** - * Gets the maximum number of member Options for a valid CommandLine - * @return the maximum number of member Options - */ public int getMaximum() { return maximum; } + + public boolean isRequired() { + return getMinimum()>0; + } } class ReverseStringComparator implements Comparator { 1.1.2.3 +3 -13 jakarta-commons/cli/src/java/org/apache/commons/cli2/option/Attic/DefaultOption.java Index: DefaultOption.java =================================================================== RCS file: /home/cvs/jakarta-commons/cli/src/java/org/apache/commons/cli2/option/Attic/DefaultOption.java,v retrieving revision 1.1.2.2 retrieving revision 1.1.2.3 diff -u -r1.1.2.2 -r1.1.2.3 --- DefaultOption.java 14 Apr 2004 18:31:16 -0000 1.1.2.2 +++ DefaultOption.java 20 Apr 2004 20:59:19 -0000 1.1.2.3 @@ -53,7 +53,6 @@ private final String preferredName; private final Set aliases; private final Set burstAliases; - private final boolean required; private final Set triggers; private final Set prefixes; @@ -89,7 +88,7 @@ final Argument argument, final Group children, final int id) { - super(argument, children, description, id); + super(argument, children, description, id, required); this.shortPrefix = shortPrefix; this.burstEnabled = burstEnabled; @@ -111,7 +110,6 @@ this.burstAliases = Collections.unmodifiableSet(new HashSet(burstAliases)); } - this.required = required; final Set triggers = new HashSet(); triggers.add(preferredName); @@ -181,7 +179,7 @@ public void validate(WriteableCommandLine commandLine) throws OptionException { - if (required && !commandLine.hasOption(this)) { + if (isRequired() && !commandLine.hasOption(this)) { throw new OptionException(this); } @@ -195,7 +193,7 @@ // do we display optionality final boolean optional = - !required && helpSettings.contains(DisplaySetting.DISPLAY_OPTIONAL); + !isRequired() && helpSettings.contains(DisplaySetting.DISPLAY_OPTIONAL); final boolean displayAliases = helpSettings.contains(DisplaySetting.DISPLAY_ALIASES); @@ -229,13 +227,5 @@ public String getPreferredName() { return preferredName; - } - - /** - * Indicates whether this option is required to be present. - * @return true iff the CommandLine will be invalid without this Option - */ - public boolean isRequired() { - return this.required; } } 1.1.2.3 +3 -5 jakarta-commons/cli/src/java/org/apache/commons/cli2/option/Attic/Switch.java Index: Switch.java =================================================================== RCS file: /home/cvs/jakarta-commons/cli/src/java/org/apache/commons/cli2/option/Attic/Switch.java,v retrieving revision 1.1.2.2 retrieving revision 1.1.2.3 diff -u -r1.1.2.2 -r1.1.2.3 --- Switch.java 14 Apr 2004 18:31:16 -0000 1.1.2.2 +++ Switch.java 20 Apr 2004 20:59:19 -0000 1.1.2.3 @@ -48,7 +48,6 @@ private final String enabledPrefix; private final String disabledPrefix; - private final boolean required; private final Set triggers; private final String preferredName; private final Set aliases; @@ -76,7 +75,7 @@ final Argument argument, final Group children, final int id) { - super(argument, children, description, id); + super(argument, children, description, id, required); if (enabledPrefix == null) { throw new IllegalArgumentException("enabledPrefix must be supplied"); @@ -96,7 +95,6 @@ this.enabledPrefix = enabledPrefix; this.disabledPrefix = disabledPrefix; - this.required = required; this.preferredName = preferredName; if (preferredName == null || preferredName.length() < 1) { @@ -160,7 +158,7 @@ public void validate(WriteableCommandLine commandLine) throws OptionException { - if (required && !commandLine.hasOption(this)) { + if (isRequired() && !commandLine.hasOption(this)) { throw new OptionException(this); } @@ -174,7 +172,7 @@ // do we display optionality final boolean optional = - !required && helpSettings.contains(DisplaySetting.DISPLAY_OPTIONAL); + !isRequired() && helpSettings.contains(DisplaySetting.DISPLAY_OPTIONAL); final boolean displayAliases = helpSettings.contains(DisplaySetting.DISPLAY_ALIASES); final boolean disabled = 1.1.2.3 +3 -2 jakarta-commons/cli/src/java/org/apache/commons/cli2/option/Attic/ParentImpl.java Index: ParentImpl.java =================================================================== RCS file: /home/cvs/jakarta-commons/cli/src/java/org/apache/commons/cli2/option/Attic/ParentImpl.java,v retrieving revision 1.1.2.2 retrieving revision 1.1.2.3 diff -u -r1.1.2.2 -r1.1.2.3 --- ParentImpl.java 14 Apr 2004 18:31:16 -0000 1.1.2.2 +++ ParentImpl.java 20 Apr 2004 20:59:19 -0000 1.1.2.3 @@ -48,8 +48,9 @@ final Argument argument, final Group children, final String description, - final int id) { - super(id); + final int id, + final boolean required) { + super(id,required); this.children = children; this.argument = argument; this.description = description; 1.1.2.3 +7 -1 jakarta-commons/cli/src/java/org/apache/commons/cli2/option/Attic/OptionImpl.java Index: OptionImpl.java =================================================================== RCS file: /home/cvs/jakarta-commons/cli/src/java/org/apache/commons/cli2/option/Attic/OptionImpl.java,v retrieving revision 1.1.2.2 retrieving revision 1.1.2.3 diff -u -r1.1.2.2 -r1.1.2.3 --- OptionImpl.java 14 Apr 2004 18:31:16 -0000 1.1.2.2 +++ OptionImpl.java 20 Apr 2004 20:59:19 -0000 1.1.2.3 @@ -27,13 +27,15 @@ public abstract class OptionImpl implements Option { private final int id; + private final boolean required; /** * Creates an OptionImpl with the specified id * @param id the unique id of this Option */ - public OptionImpl(final int id) { + public OptionImpl(final int id, final boolean required) { this.id = id; + this.required = required; } public boolean canProcess(final ListIterator arguments) { @@ -92,4 +94,8 @@ return null; } } + + public boolean isRequired() { + return required; + } } 1.1.2.3 +3 -7 jakarta-commons/cli/src/java/org/apache/commons/cli2/option/Attic/Command.java Index: Command.java =================================================================== RCS file: /home/cvs/jakarta-commons/cli/src/java/org/apache/commons/cli2/option/Attic/Command.java,v retrieving revision 1.1.2.2 retrieving revision 1.1.2.3 diff -u -r1.1.2.2 -r1.1.2.3 --- Command.java 14 Apr 2004 18:31:16 -0000 1.1.2.2 +++ Command.java 20 Apr 2004 20:59:19 -0000 1.1.2.3 @@ -44,9 +44,6 @@ /** The aliases for this command */ private final Set aliases; - /** Whether or not the command is required */ - private final boolean required; - /** All the names for this command */ private final Set triggers; @@ -79,7 +76,7 @@ final Group children, final int id) { - super(argument, children, description, id); + super(argument, children, description, id, required); // check the preferred name is valid if (preferredName == null || preferredName.length() < 1) { @@ -87,7 +84,6 @@ } this.preferredName = preferredName; - this.required = required; // gracefully and defensively handle aliases if (aliases == null) { @@ -132,7 +128,7 @@ public void validate(WriteableCommandLine commandLine) throws OptionException { - if (required && !commandLine.hasOption(this)) { + if (isRequired() && !commandLine.hasOption(this)) { throw new OptionException(this); } @@ -146,7 +142,7 @@ // do we display optionality final boolean optional = - !required && helpSettings.contains(DisplaySetting.DISPLAY_OPTIONAL); + !isRequired() && helpSettings.contains(DisplaySetting.DISPLAY_OPTIONAL); final boolean displayAliases = helpSettings.contains(DisplaySetting.DISPLAY_ALIASES); 1.1.2.3 +5 -7 jakarta-commons/cli/src/java/org/apache/commons/cli2/option/Attic/ArgumentImpl.java Index: ArgumentImpl.java =================================================================== RCS file: /home/cvs/jakarta-commons/cli/src/java/org/apache/commons/cli2/option/Attic/ArgumentImpl.java,v retrieving revision 1.1.2.2 retrieving revision 1.1.2.3 diff -u -r1.1.2.2 -r1.1.2.3 --- ArgumentImpl.java 14 Apr 2004 18:31:16 -0000 1.1.2.2 +++ ArgumentImpl.java 20 Apr 2004 20:59:19 -0000 1.1.2.3 @@ -106,7 +106,7 @@ final List defaultValues, final int id) { - super(id); + super(id,false); this.name = (name == null) ? "arg" : name; this.description = description; @@ -330,16 +330,10 @@ return Collections.singletonList(helpLine); } - /** - * @return Returns the maximum. - */ public int getMaximum() { return maximum; } - /** - * @return Returns the minimum. - */ public int getMinimum() { return minimum; } @@ -368,5 +362,9 @@ return token; } + } + + public boolean isRequired() { + return getMinimum()>0; } } No revision No revision 1.1.2.7 +25 -0 jakarta-commons/cli/src/java/org/apache/commons/cli2/Attic/Argument.java Index: Argument.java =================================================================== RCS file: /home/cvs/jakarta-commons/cli/src/java/org/apache/commons/cli2/Attic/Argument.java,v retrieving revision 1.1.2.6 retrieving revision 1.1.2.7 diff -u -r1.1.2.6 -r1.1.2.7 --- Argument.java 14 Apr 2004 18:31:15 -0000 1.1.2.6 +++ Argument.java 20 Apr 2004 20:59:19 -0000 1.1.2.7 @@ -68,4 +68,29 @@ */ void validate(final WriteableCommandLine commandLine, final Option option) throws OptionException; + + /** + * Indicates whether argument values must be present for the CommandLine to + * be valid. + * + * @see #getMinimum() + * @see #getMaximum() + * @return true iff the CommandLine will be invalid without at least one + * value + */ + boolean isRequired(); + + /** + * Retrieves the minimum number of values required for a valid Argument + * + * @return the minimum number of values + */ + int getMinimum(); + + /** + * Retrieves the maximum number of values acceptable for a valid Argument + * + * @return the maximum number of values + */ + int getMaximum(); } 1.1.2.6 +25 -0 jakarta-commons/cli/src/java/org/apache/commons/cli2/Attic/Group.java Index: Group.java =================================================================== RCS file: /home/cvs/jakarta-commons/cli/src/java/org/apache/commons/cli2/Attic/Group.java,v retrieving revision 1.1.2.5 retrieving revision 1.1.2.6 diff -u -r1.1.2.5 -r1.1.2.6 --- Group.java 14 Apr 2004 18:31:15 -0000 1.1.2.5 +++ Group.java 20 Apr 2004 20:59:19 -0000 1.1.2.6 @@ -36,4 +36,29 @@ final Set helpSettings, final Comparator comp, final String separator); + + /** + * Indicates whether group members must be present for the CommandLine to be + * valid. + * + * @see #getMinimum() + * @see #getMaximum() + * @return true iff the CommandLine will be invalid without at least one + * member option + */ + boolean isRequired(); + + /** + * Retrieves the minimum number of members required for a valid Group + * + * @return the minimum number of members + */ + int getMinimum(); + + /** + * Retrieves the maximum number of members acceptable for a valid Group + * + * @return the maximum number of members + */ + int getMaximum(); } 1.1.2.12 +6 -0 jakarta-commons/cli/src/java/org/apache/commons/cli2/Attic/Option.java Index: Option.java =================================================================== RCS file: /home/cvs/jakarta-commons/cli/src/java/org/apache/commons/cli2/Attic/Option.java,v retrieving revision 1.1.2.11 retrieving revision 1.1.2.12 diff -u -r1.1.2.11 -r1.1.2.12 --- Option.java 14 Apr 2004 18:31:15 -0000 1.1.2.11 +++ Option.java 20 Apr 2004 20:59:19 -0000 1.1.2.12 @@ -178,4 +178,10 @@ * @return the matching option or null. */ Option findOption(final String trigger); + + /** + * Indicates whether this option is required to be present. + * @return true iff the CommandLine will be invalid without this Option + */ + boolean isRequired(); }
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]