You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by jk...@apache.org on 2003/05/25 00:20:54 UTC

cvs commit: jakarta-commons/cli/src/test/org/apache/commons/cli CommandLineParserTest.java

jkeyes      2003/05/24 15:20:54

  Modified:    cli/src/java/org/apache/commons/cli Tag: cli_1_x Option.java
                        OptionImpl.java ArgumentImpl.java
               cli/src/test/org/apache/commons/cli Tag: cli_1_x
                        CommandLineParserTest.java
  Log:
  removed unnecessary ctors
modified test that did not use the builders
  
  Revision  Changes    Path
  No                   revision
  
  
  No                   revision
  
  
  1.20.2.3  +20 -26    jakarta-commons/cli/src/java/org/apache/commons/cli/Option.java
  
  Index: Option.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/cli/src/java/org/apache/commons/cli/Option.java,v
  retrieving revision 1.20.2.2
  retrieving revision 1.20.2.3
  diff -u -r1.20.2.2 -r1.20.2.3
  --- Option.java	23 May 2003 22:35:58 -0000	1.20.2.2
  +++ Option.java	24 May 2003 22:20:53 -0000	1.20.2.3
  @@ -7,7 +7,7 @@
    *
    * The Apache Software License, Version 1.1
    *
  - * Copyright (c) 1999-2001 The Apache Software Foundation.  All rights
  + * Copyright (c) 1999-2003 The Apache Software Foundation.  All rights
    * reserved.
    *
    * Redistribution and use in source and binary forms, with or without
  @@ -70,31 +70,28 @@
    * @since 2.0
    */
   public interface Option {
  -	
  -	/**
  -	 * Returns the name of the Option
  -	 * 
  -	 * @return
  -	 *     the Option name
  -	 */
  +
  +    /**
  +     * Returns the name of the Option
  +     * 
  +     * @return the Option name
  +     */
       String getName();
  -    
  +
       /**
        * Returns the long name of the Option
        * 
  -     * @return
  -     *     the Option long name
  +     * @return the Option long name
        */
       String getLongName();
  -    
  +
       /**
        * Returns the description of the Option
        * 
  -     * @return
  -     *     the textual description of the Option
  +     * @return the textual description of the Option
        */
       String getDescription();
  -    
  +
       /**
        * Adds the specified Option as a child.  For example,
        * if there is an Option '-time' and it has three
  @@ -108,40 +105,37 @@
        *     a child Option
        */
       void addChild(Option childOption);
  -    
  +
       /**
        * Adds the specified Set of Options as children.
        * 
        * @param children
        *     child Options
        * 
  -     * @see org.apache.commons.cli.Option.addChild(org.apache.commons.cli.Option)
  +     * @see Option.addChild(cli.Option)
        */
       void addChildren(Set children);
  -    
  +
       /**
        * Returns whether this Option has any child Options
        * 
  -     * @return
  -     *     true if this Option has children, otherwise false
  +     * @return true if this Option has children, otherwise false
        */
       boolean hasChildren();
  -    
  +
       /**
        * Returns whether this Option must be present in the command
        * line arguments.
        * 
  -     * @return
  -     *     true if the Option must be present in the arguments,
  +     * @return true if the Option must be present in the arguments,
        *     otherwise false
        */
       boolean isRequired();
  -    
  +
       /**
        * Returns the children of the Option
        * 
  -     * @return
  -     *     the Set of children, if there are no children 
  +     * @return the Set of children, if there are no children 
        *     return null
        */
       Set getChildren();
  
  
  
  1.1.2.2   +127 -38   jakarta-commons/cli/src/java/org/apache/commons/cli/Attic/OptionImpl.java
  
  Index: OptionImpl.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/cli/src/java/org/apache/commons/cli/Attic/OptionImpl.java,v
  retrieving revision 1.1.2.1
  retrieving revision 1.1.2.2
  diff -u -r1.1.2.1 -r1.1.2.2
  --- OptionImpl.java	19 May 2003 20:57:51 -0000	1.1.2.1
  +++ OptionImpl.java	24 May 2003 22:20:53 -0000	1.1.2.2
  @@ -1,49 +1,114 @@
  +/*
  + * $Header$
  + * $Revision$
  + * $Date$
  + *
  + * ====================================================================
  + *
  + * The Apache Software License, Version 1.1
  + *
  + * Copyright (c) 1999-2003 The Apache Software Foundation.  All rights
  + * reserved.
  + *
  + * Redistribution and use in source and binary forms, with or without
  + * modification, are permitted provided that the following conditions
  + * are met:
  + *
  + * 1. Redistributions of source code must retain the above copyright
  + *    notice, this list of conditions and the following disclaimer.
  + *
  + * 2. Redistributions in binary form must reproduce the above copyright
  + *    notice, this list of conditions and the following disclaimer in
  + *    the documentation and/or other materials provided with the
  + *    distribution.
  + *
  + * 3. The end-user documentation included with the redistribution, if
  + *    any, must include the following acknowlegement:
  + *       "This product includes software developed by the
  + *        Apache Software Foundation (http://www.apache.org/)."
  + *    Alternately, this acknowlegement may appear in the software itself,
  + *    if and wherever such third-party acknowlegements normally appear.
  + *
  + * 4. The names "The Jakarta Project", "Commons", and "Apache Software
  + *    Foundation" must not be used to endorse or promote products derived
  + *    from this software without prior written permission. For written
  + *    permission, please contact apache@apache.org.
  + *
  + * 5. Products derived from this software may not be called "Apache"
  + *    nor may "Apache" appear in their names without prior written
  + *    permission of the Apache Group.
  + *
  + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
  + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  + * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
  + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
  + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
  + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  + * SUCH DAMAGE.
  + * ====================================================================
  + *
  + * This software consists of voluntary contributions made by many
  + * individuals on behalf of the Apache Software Foundation.  For more
  + * information on the Apache Software Foundation, please see
  + * <http://www.apache.org/>;.
  + *
  + */
   package org.apache.commons.cli;
   
   import java.util.Set;
   import java.util.HashSet;
   
  +/**
  + * An implementation of the Option interface.
  + * 
  + * @author John Keyes
  + */
   class OptionImpl implements Option {
   
  +    /** the name of the option */
       private String name;
  -    private String longName;
  -    private String description;
  -    private boolean required;
  -    private Set children;
   
  -    OptionImpl(final String name) {
  -        this.name = name;
  -        this.longName = null;
  -        this.description = null;
  -        this.required = false;
  -        this.children = new HashSet(0);
  -    }
  +    /** the long name of the option */
  +    private String longName;
   
  -    OptionImpl(final String name, final String longName) {
  -        this.name = name;
  -        this.longName = longName;
  -        this.description = null;
  -        this.required = false;
  -        this.children = new HashSet(0);
  -    }
  +    /** the description of the option */
  +    private String description;
   
  -    /*OptionImpl(final String name, final String longName, final String description) {
  -        this.name = name;
  -        this.longName = longName;
  -        this.description = description;
  -        this.required = false;
  -        this.children = new HashSet(0);
  -    }
  +    /** is the option required */
  +    private boolean required;
   
  -    OptionImpl(final String name, final String longName, final String description, final boolean required) {
  -        this.name = name;
  -        this.longName = longName;
  -        this.description = description;
  -        this.required = required;
  -        this.children = new HashSet(0);
  -    }*/
  +    /** the child Options */
  +    private Set children;
   
  -    OptionImpl(final String name, final String longName, final String description, final boolean required, final Set children) {
  +    /**
  +     * Creates an Option
  +     * 
  +     * @param name
  +     *     the name
  +     * 
  +     * @param longName
  +     *     the long name
  +     * 
  +     * @param description
  +     *     the description
  +     * 
  +     * @param required
  +     *     whether this Option is required
  +     * 
  +     * @param children
  +     *     the child Options
  +     */
  +    OptionImpl(
  +        final String name,
  +        final String longName,
  +        final String description,
  +        final boolean required,
  +        final Set children) {
           this.name = name;
           this.longName = longName;
           this.description = description;
  @@ -51,36 +116,60 @@
           this.children = (children != null) ? children : new HashSet(0);
       }
   
  +    /**
  +     * @see Option#getName()
  +     */
       public String getName() {
           return this.name;
       }
   
  +    /**
  +     * @see Option#getLongName()
  +     */
       public String getLongName() {
           return this.longName;
       }
   
  +    /**
  +     * @see Option#getDescription()
  +     */
       public String getDescription() {
           return this.description;
       }
   
  +    /**
  +     * @see Option#addChild(Option)
  +     */
       public void addChild(Option option) {
  -        this.children.add( option );
  +        this.children.add(option);
       }
   
  +    /**
  +     * @see Option#addChildren(java.util.Set)
  +     */
       public void addChildren(Set children) {
  -        this.children.addAll( children );
  +        this.children.addAll(children);
       }
   
  +    /**
  +     * @see Option#isRequired()
  +     */
       public boolean isRequired() {
           return this.required;
       }
   
  +    /**
  +     * @see Option#getChildren()
  +     */
       public Set getChildren() {
           return this.children;
       }
   
  -	public boolean hasChildren() {
  -		return (children != null && this.children.size() > 0);
  -	}
  +    /**
  +     * @see Option#hasChildren()
  +     */
  +    public boolean hasChildren() {
  +        return (children != null && this.children.size() > 0);
  +    }
   
   }
  
  
  
  1.1.2.3   +3 -250    jakarta-commons/cli/src/java/org/apache/commons/cli/Attic/ArgumentImpl.java
  
  Index: ArgumentImpl.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/cli/src/java/org/apache/commons/cli/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	24 May 2003 21:54:15 -0000	1.1.2.2
  +++ ArgumentImpl.java	24 May 2003 22:20:53 -0000	1.1.2.3
  @@ -61,7 +61,6 @@
   package org.apache.commons.cli;
   
   import java.util.Set;
  -import java.util.HashSet;
   
   /**
    * Implementation of the Argument interface.
  @@ -84,252 +83,6 @@
   
       /** whether this argument has optional values */
       private final boolean hasOptionalValues;
  -
  -    /**
  -     * Creates an Argument with the specified name.
  -     * 
  -     * @param name
  -     *     the name
  -     */
  -    public ArgumentImpl(String name) {
  -        this(
  -            name,
  -            null,
  -            null,
  -            false,
  -            1,
  -            null,
  -            (char) 0,
  -            "arg",
  -            false,
  -            new HashSet(0));
  -    }
  -
  -    /**
  -     * Creates an Argument with the specified name and long name.
  -     * 
  -     * @param name
  -     *     the name
  -     * 
  -     * @param longName
  -     *     the longName
  -     */
  -    public ArgumentImpl(String name, String longName) {
  -        this(
  -            name,
  -            longName,
  -            null,
  -            false,
  -            1,
  -            null,
  -            (char) 0,
  -            "arg",
  -            false,
  -            new HashSet(0));
  -    }
  -
  -    /**
  -     * Creates an Argument with the specified name, long name
  -     * and description.
  -     * 
  -     * @param name
  -     *     the name
  -     * 
  -     * @param longName
  -     *     the longName
  -     * 
  -     * @param description
  -     *     the textual description used in the help text
  -     */
  -    public ArgumentImpl(String name, String longName, String description) {
  -        this(
  -            name,
  -            longName,
  -            description,
  -            false,
  -            1,
  -            null,
  -            (char) 0,
  -            "arg",
  -            false,
  -            new HashSet(0));
  -    }
  -
  -    /**
  -     * Creates an Argument with the specified name, long name
  -     * description and whether it is required.
  -     * 
  -     * @param name
  -     *     the name
  -     * 
  -     * @param longName
  -     *     the longName
  -     * 
  -     * @param description
  -     *     the textual description used in the help text
  -     * 
  -     * @param required
  -     *     whether this Argument is required
  -     */
  -    public ArgumentImpl(
  -        String name,
  -        String longName,
  -        String description,
  -        boolean required) {
  -
  -        this(
  -            name,
  -            longName,
  -            description,
  -            required,
  -            1,
  -            null,
  -            (char) 0,
  -            "arg",
  -            false,
  -            new HashSet(0));
  -    }
  -
  -    /**
  -     * Creates an Argument with the specified name, long name
  -     * description and whether it is required.
  -     * 
  -     * @param name
  -     *     the name
  -     * 
  -     * @param longName
  -     *     the longName
  -     * 
  -     * @param description
  -     *     the textual description used in the help text
  -     * 
  -     * @param required
  -     *     whether this Argument is required
  -     * 
  -     * @param type
  -     *     the type of the Argument value
  -     * 
  -     * @param valueSeparator
  -     *     the character that separates values
  -     */
  -    public ArgumentImpl(
  -        String name,
  -        String longName,
  -        String description,
  -        boolean required,
  -        Class type,
  -        char valueSeparator) {
  -
  -        this(
  -            name,
  -            longName,
  -            description,
  -            required,
  -            1,
  -            type,
  -            valueSeparator,
  -            "arg",
  -            false,
  -            new HashSet(0));
  -    }
  -
  -    /**
  -     * Creates an Argument with the specified name, long name
  -     * description and whether it is required.
  -     * 
  -     * @param name
  -     *     the name
  -     * 
  -     * @param longName
  -     *     the longName
  -     * 
  -     * @param description
  -     *     the textual description used in the help text
  -     * 
  -     * @param required
  -     *     whether this Argument is required
  -     * 
  -     * @param type
  -     *     the type of the Argument value
  -     * 
  -     * @param valueSeparator
  -     *     the character that separates values
  -     * 
  -     * @param valueName
  -     *     the help text for the value(s)
  -     */
  -    public ArgumentImpl(
  -        String name,
  -        String longName,
  -        String description,
  -        boolean required,
  -        Class type,
  -        char valueSeparator,
  -        String valueName) {
  -
  -        this(
  -            name,
  -            longName,
  -            description,
  -            required,
  -            1,
  -            type,
  -            valueSeparator,
  -            valueName,
  -            false,
  -            new HashSet(0));
  -    }
  -
  -    /**
  -     * Creates an Argument with the specified name, long name
  -     * description and whether it is required.
  -     * 
  -     * @param name
  -     *     the name
  -     * 
  -     * @param longName
  -     *     the longName
  -     * 
  -     * @param description
  -     *     the textual description used in the help text
  -     * 
  -     * @param required
  -     *     whether this Argument is required
  -     * 
  -     * @param size
  -     *     the number of values for this Argument
  -     * 
  -     * @param type
  -     *     the type of the Argument value
  -     * 
  -     * @param valueSeparator
  -     *     the character that separates values
  -     * 
  -     * @param valueName
  -     *     the help text for the value(s)
  -     */
  -    public ArgumentImpl(
  -        String name,
  -        String longName,
  -        String description,
  -        boolean required,
  -        int size,
  -        Class type,
  -        char valueSeparator,
  -        String valueName) {
  -
  -        this(
  -            name,
  -            longName,
  -            description,
  -            required,
  -            1,
  -            type,
  -            valueSeparator,
  -            valueName,
  -            false,
  -            new HashSet(0));
  -    }
   
       /**
        * Creates an Argument with the specified name, long name
  
  
  
  No                   revision
  
  
  No                   revision
  
  
  1.1.2.3   +31 -11    jakarta-commons/cli/src/test/org/apache/commons/cli/Attic/CommandLineParserTest.java
  
  Index: CommandLineParserTest.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/cli/src/test/org/apache/commons/cli/Attic/CommandLineParserTest.java,v
  retrieving revision 1.1.2.2
  retrieving revision 1.1.2.3
  diff -u -r1.1.2.2 -r1.1.2.3
  --- CommandLineParserTest.java	20 May 2003 23:08:54 -0000	1.1.2.2
  +++ CommandLineParserTest.java	24 May 2003 22:20:54 -0000	1.1.2.3
  @@ -17,8 +17,11 @@
   	}
   
       public void testBasicShort() throws Exception {
  -        Option create = new OptionImpl( "c" );
  -        Argument file = new ArgumentImpl( "f" );
  +        OptionBuilder obuilder = OptionBuilder.createBuilder();
  +        ArgumentBuilder abuilder = ArgumentBuilder.createBuilder();
  +        
  +        Option create = obuilder.withName("c").create();
  +        Argument file = abuilder.withName("f").create();
           
           Options opts = new Options();
           opts.add(create);
  @@ -74,9 +77,9 @@
           assertTrue("file.txt option should not have been found", !cmdline.hasOption( "file.txt" ));
           assertEquals("incorrect value for -f", "file.txt", cmdline.getValue( "-f" ));
   
  -        Argument listener = new ArgumentImpl( "listener" );
  -        Argument buildfile = new ArgumentImpl( "buildfile" );
  -        
  +        Argument listener = abuilder.withName("listener").create();
  +        Argument buildfile = abuilder.withName("buildfile").create();
  +
           opts = new Options();
           opts.add(listener);
           opts.add(buildfile);
  @@ -106,8 +109,15 @@
       }
   
       public void testBasicLong() throws Exception {
  -        Option create = new OptionImpl( "c", "create" );
  -        Argument file = new ArgumentImpl( "f", "file" );
  +        OptionBuilder obuilder = OptionBuilder.createBuilder();
  +        ArgumentBuilder abuilder = ArgumentBuilder.createBuilder();
  +        
  +        Option create = obuilder.withName("c")
  +                                .withLongName("create")
  +                                .create();
  +        Argument file = abuilder.withName("f")
  +                                .withLongName("file")
  +                                .create();
           
           Options opts = new Options();
           opts.add(create);
  @@ -169,8 +179,15 @@
       }
   
       public void testMixedLongShort() throws Exception {
  -        Option create = new OptionImpl( "c", "create" );
  -        Argument file = new ArgumentImpl( "f", "file" );
  +        OptionBuilder obuilder = OptionBuilder.createBuilder();
  +        ArgumentBuilder abuilder = ArgumentBuilder.createBuilder();
  +        
  +        Option create = obuilder.withName("c")
  +                                .withLongName("create")
  +                                .create();
  +        Argument file = abuilder.withName("f")
  +                                .withLongName("file")
  +                                .create();
           
           Options opts = new Options();
           opts.add(create);
  @@ -341,8 +358,11 @@
       }
   
   	public void testIterator() throws Exception {
  -		Option create = new OptionImpl( "c" );
  -		Argument file = new ArgumentImpl( "f" );
  +        OptionBuilder obuilder = OptionBuilder.createBuilder();
  +        ArgumentBuilder abuilder = ArgumentBuilder.createBuilder();
  +        
  +        Option create = obuilder.withName("c").create();
  +        Argument file = abuilder.withName("f").create();
           
   		Options opts = new Options();
   		opts.add(create);
  
  
  

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