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/21 23:47:12 UTC

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

jkeyes      2003/05/21 14:47:12

  Modified:    cli/src/java/org/apache/commons/cli Tag: cli_1_x
                        OptionBuilder.java
  Log:
  . added javadoc
. fixed reset method, so the description is reset, should it be null or empty string
  
  Revision  Changes    Path
  No                   revision
  
  
  No                   revision
  
  
  1.15.2.3  +154 -5    jakarta-commons/cli/src/java/org/apache/commons/cli/OptionBuilder.java
  
  Index: OptionBuilder.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/cli/src/java/org/apache/commons/cli/OptionBuilder.java,v
  retrieving revision 1.15.2.2
  retrieving revision 1.15.2.3
  diff -u -r1.15.2.2 -r1.15.2.3
  --- OptionBuilder.java	20 May 2003 23:08:54 -0000	1.15.2.2
  +++ OptionBuilder.java	21 May 2003 21:47:12 -0000	1.15.2.3
  @@ -1,54 +1,189 @@
  +/*
  + * $Header$
  + * $Revision$
  + * $Date$
  + *
  + * ====================================================================
  + *
  + * The Apache Software License, Version 1.1
  + *
  + * Copyright (c) 1999-2001 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;
   
  +/**
  + * OptionBuilder creates Option instances based on the
  + * methods called by the client.  After each create is called
  + * the state is reset so no settings from previous calls will
  + * be preserved.
  + * 
  + * @author John Keyes
  + * @since 2.0
  + */
  +
   public class OptionBuilder {
   
  +	/** the name of the option */
       private String name;
  +    
  +    /** the long name of the option */
       private String longName;
  +    
  +    /** the textual description of the option */
       private String description;
  +    
  +    /** specifies whether the option is required, default false */
       private boolean required;
  +    
  +    /** the set of children this option has */
       private Set children;
   
  +	/**
  +	 * Creates OptionBuilder instances
  +	 * 
  +	 * @return
  +	 *     an OptionBuilder
  +	 */
   	public static OptionBuilder createBuilder() {
   		return new OptionBuilder();
   	}
   	
  -    /*public Option create( final String name ) {
  -        return create( name, null );
  -    }*/
  -
  -    public Option create() {// final String name, final String longName ) {
  +	/**
  +	 * Creates an Option instance, based on the state of the builder 
  +	 *
  +	 * @return 
  +	 *     an Option instance
  +	 */
  +    public Option create() {
           try {
               return new OptionImpl( this.name, this.longName, this.description, this.required, this.children );
           }
           finally {
  +        	// reset the state of the builder
               reset();
           }
       }
   
  +	/**
  +	 * Sets the name of the next Option instance to be created
  +	 *  
  +	 * @param name
  +	 *     the name of the Option
  +	 * 
  +	 * @return
  +	 *     the OptionBuilder
  +	 */
   	public OptionBuilder withName (String name) {
   		this.name = name;
   		return this;
   	}
   	
  +	/**
  +	 * Sets the long name of the next Option instance to be created
  +	 * 
  +	 * @param longName
  +	 *     the long name of the Option
  +	 * 
  +	 * @return
  +	 *     the OptionBuilder
  +	 */
   	public OptionBuilder withLongName (String longName) {
   		this.longName = longName;
   		return this;
   	}
   	
  +	/**
  +	 * Sets the description of the next Option instance to be created
  +	 * 
  +	 * @param description
  +	 *     the textual description of the option for use in the help text
  +	 * 
  +	 * @return
  +	 *     the OptionBuilder
  +	 */
       public OptionBuilder withDescription( String description ) {
           this.description = description;
           return this;
       }
   
   
  +	/**
  +	 * Sets whether the next Option instance created will be required
  +	 * 
  +	 * @param required
  +	 *     if true, the next Option must be present when the command line
  +	 *     is parsed, otherwise it does not
  +	 * 
  +	 * @return
  +	 *     the OptionBuilder
  +	 */
       public OptionBuilder withRequired(boolean required) {
           this.required = required;
           return this;
       }
   
  +	/**
  +	 * Adds the specified child to the next Option instance that will
  +	 * be created.
  +	 * 
  +	 * @param child
  +	 *     the child Option of the next Option
  +	 * 
  +	 * @return
  +	 *     the OptionBuilder
  +	 */
       public OptionBuilder withChild( final Option child ) {
           if(this.children == null) {
               this.children = new HashSet();
  @@ -57,6 +192,16 @@
           return this;
       }
   
  +	/**
  +	 * Adds the set of children to the next Option instance that will
  +	 * be created.
  +	 * 
  +	 * @param children
  +	 *     the set of child Options of the next Option
  +	 * 
  +	 * @return
  +	 *     the OptionBuilder
  +	 */
       public OptionBuilder withChildren( final Set children ) {
           if(this.children == null) {
               this.children = new HashSet();
  @@ -65,9 +210,13 @@
           return this;
       }
   
  +	/**
  +	 * Resets the state of the builder.
  +	 */
       private void reset() {
           this.name = null;
           this.longName = null;
  +        this.description = null;
           this.required = false;
           this.children = null;
       }
  
  
  

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