commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jke...@apache.org
Subject cvs commit: jakarta-commons/cli/src/java/org/apache/commons/cli2/impl GroupImpl.java
Date Sat, 06 Mar 2004 20:47:56 GMT
jkeyes      2004/03/06 12:47:56

  Modified:    cli/src/java/org/apache/commons/cli2/impl Tag:
                        RESEARCH_CLI_2_ROXSPRING GroupImpl.java
  Log:
  - housekeeping - do not create a new list to store the present options
  
  Revision  Changes    Path
  No                   revision
  No                   revision
  1.1.2.12  +18 -12    jakarta-commons/cli/src/java/org/apache/commons/cli2/impl/Attic/GroupImpl.java
  
  Index: GroupImpl.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/cli/src/java/org/apache/commons/cli2/impl/Attic/GroupImpl.java,v
  retrieving revision 1.1.2.11
  retrieving revision 1.1.2.12
  diff -u -r1.1.2.11 -r1.1.2.12
  --- GroupImpl.java	6 Mar 2004 20:14:36 -0000	1.1.2.11
  +++ GroupImpl.java	6 Mar 2004 20:47:56 -0000	1.1.2.12
  @@ -223,31 +223,37 @@
       public void validate(final WriteableCommandLine commandLine)
           throws OptionException {
   
  -        // initialize to 'maximum' size
  -        final List present = new ArrayList();
  +        // number of options found
  +        int present = 0;
  +        
  +        // reference to first unexpected option
  +        Option unexpected = null;
           
           for (final Iterator i = options.iterator(); i.hasNext();) {
  -            final Option option = (Option)i.next();
  +            final Option option = (Option) i.next();
               if (commandLine.hasOption(option)) {
  -                present.add(option);
  +                if (++present > maximum) {
  +                    unexpected = option;
  +                    break;
  +                }
                   option.validate(commandLine);
               }
           }
   
  -        // too few option
  -        if (present.size() < minimum) {
  -            throw new OptionException(this, "cli.error.missing.option");
  -        }
  -
           // too many options
  -        if (present.size() > maximum) {
  +        if (unexpected != null) {
               throw new OptionException(
                   this,
                   "cli.error.unexpected",
  -                ((Option)present.get(maximum)).getPreferredName());
  +                unexpected.getPreferredName());
  +        }
  +        
  +        // too few option
  +        if (present < minimum) {
  +            throw new OptionException(this, "cli.error.missing.option");
           }
   
  -        // try each anonymous argument
  +        // validate each anonymous argument
           for (final Iterator i = anonymous.iterator(); i.hasNext();) {
               final Option option = (Option)i.next();
               option.validate(commandLine);
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Mime
View raw message