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/cli CommandLineImpl.java
Date Sat, 24 May 2003 21:04:00 GMT
jkeyes      2003/05/24 14:04:00

  Modified:    cli/src/java/org/apache/commons/cli Tag: cli_1_x
                        CommandLineImpl.java
  Log:
  added Javadoc
  added license
  replaced tabs with spaces
  
  Revision  Changes    Path
  No                   revision
  
  
  No                   revision
  
  
  1.1.2.3   +189 -74   jakarta-commons/cli/src/java/org/apache/commons/cli/Attic/CommandLineImpl.java
  
  Index: CommandLineImpl.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/cli/src/java/org/apache/commons/cli/Attic/CommandLineImpl.java,v
  retrieving revision 1.1.2.2
  retrieving revision 1.1.2.3
  diff -u -r1.1.2.2 -r1.1.2.3
  --- CommandLineImpl.java	24 May 2003 17:25:03 -0000	1.1.2.2
  +++ CommandLineImpl.java	24 May 2003 21:04:00 -0000	1.1.2.3
  @@ -1,3 +1,63 @@
  +/*
  + * $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.ArrayList;
  @@ -9,98 +69,153 @@
   
   import org.apache.commons.cli.util.TypeHandler;
   
  +/**
  + * This the implementation of the CommandLine and the 
  + * CommandLineCreator interfaces.
  + * 
  + * @author John Keyes
  + */
   class CommandLineImpl implements CommandLine, CommandLineCreator {
   
  -    Map cache = new HashMap(11);
  -    Map typeCache = new HashMap(11);
  -    
  -    List anonymous = new ArrayList();
  -	List unprocessed;
  -	
  -    public CommandLineImpl() {
  -    }
  -
  -	public List getUnprocessed() {
  -		return unprocessed;
  -	}
  -	
  -	public void setUnprocessed( List tokens ) {
  -		unprocessed = tokens;
  -	}
  -	
  -    public void addOption( Option option ) {
  -		if( option.getName() != null ) {
  -        	cache.put( "-" + option.getName(), null );
  -    	}
  -    	if( option.getLongName() != null ) {
  -        	cache.put( "--" + option.getLongName(), null );
  -    	}
  -    }
  -
  -    public void addArgument( Argument argument, List values ) {
  -    	if( argument instanceof AnonymousArgumentImpl ) {
  -    		this.anonymous.clear();
  -    		this.anonymous.addAll(values);
  -    		return;
  -    	}
  -		
  -		if( argument.getName() != null ) {
  -			typeCache.put( "-" + argument.getName(), argument.getValueType());
  -			cache.put( "-" + argument.getName(), values );
  -		}
  -
  -		if( argument.getLongName() != null ) {
  -			typeCache.put( "--" + argument.getLongName(), argument.getValueType());
  -			cache.put( "--" + argument.getLongName(), values );
  -		}
  -    }
  -
  -	public boolean hasOption( String id ) {
  -		return cache.containsKey( id );
  -	}
  -
  -	public boolean hasArgument( String id ) {
  -		return cache.containsKey( id ) && cache.get( id ) != null;
  -	}
  -
  -    public List getValues( String id ) {
  -        return (List)cache.get( id );
  -    }
  -
  -    public String getValue( String id ) {
  -        List values = (List)cache.get(id);
  -        return (values!=null && values.size()>0) ? (String)values.get(0) : null;
  +    /** the store of Options and Arguments */
  +    private Map cache = new HashMap(11);
  +
  +    /** the store of Class types for the Arguments */
  +    private Map typeCache = new HashMap(11);
  +
  +    /** the list of values for the anonymous argument */
  +    private List anonymous = new ArrayList();
  +
  +    /** the list of unprocessed values */
  +    private List unprocessed;
  +
  +    /** the Java properties */
  +    private Properties properties = new Properties();
  +
  +    /**
  +     * @see CommandLine#getUnprocessed()
  +     */
  +    public List getUnprocessed() {
  +        return unprocessed;
  +    }
  +
  +    /**
  +     * @see CommandLineCreator#setUnprocessed(java.util.List)
  +     */
  +    public void setUnprocessed(List tokens) {
  +        unprocessed = tokens;
  +    }
  +
  +    /**
  +     * @see CommandLineCreator#addOption(Option)
  +     */
  +    public void addOption(Option option) {
  +        if (option.getName() != null) {
  +            cache.put("-" + option.getName(), null);
  +        }
  +        if (option.getLongName() != null) {
  +            cache.put("--" + option.getLongName(), null);
  +        }
       }
   
  -    public String getValue( String id, String def ) {
  +    /**
  +     * @see CommandLineCreator#addArgument(Argument)
  +     */
  +    public void addArgument(Argument argument, List values) {
  +        if (argument instanceof AnonymousArgumentImpl) {
  +            this.anonymous.clear();
  +            this.anonymous.addAll(values);
  +            return;
  +        }
  +
  +        if (argument.getName() != null) {
  +            typeCache.put("-" + argument.getName(), argument.getValueType());
  +            cache.put("-" + argument.getName(), values);
  +        }
  +
  +        if (argument.getLongName() != null) {
  +            typeCache.put(
  +                "--" + argument.getLongName(),
  +                argument.getValueType());
  +            cache.put("--" + argument.getLongName(), values);
  +        }
  +    }
  +
  +    /**
  +     * @see CommandLine#hasOption(java.lang.String)
  +     */
  +    public boolean hasOption(String id) {
  +        return cache.containsKey(id);
  +    }
  +
  +    /**
  +     * @see CommandLine#hasArgument(java.lang.String)
  +     */
  +    public boolean hasArgument(String id) {
  +        return cache.containsKey(id) && cache.get(id) != null;
  +    }
  +
  +    /**
  +     * @see CommandLine#getValues(java.lang.String)
  +     */
  +    public List getValues(String id) {
  +        return (List) cache.get(id);
  +    }
  +
  +    /**
  +     * @see CommandLine#getValue(java.lang.String)
  +     */
  +    public String getValue(String id) {
  +        List values = (List) cache.get(id);
  +        return (values != null && values.size() > 0)
  +            ? (String) values.get(0)
  +            : null;
  +    }
  +
  +    /**
  +     * @see CommandLine#getValue(java.lang.String, java.lang.String)
  +     */
  +    public String getValue(String id, String def) {
           return (getValue(id) == null) ? getValue(id) : def;
       }
   
  -    public Object getValueAsObject( String id ) {
  +    /**
  +     * @see CommandLine#getValueAsObject(java.lang.String)
  +     */
  +    public Object getValueAsObject(String id) {
           if (!cache.containsKey(id)) {
               return null;
           }
   
  -        return TypeHandler.createValue(getValue(id), 
  -                                       (Class)typeCache.get(id));
  +        return TypeHandler.createValue(getValue(id), (Class) typeCache.get(id));
       }
   
  -	Properties properties;
  -	    
  +    /**
  +     * @see CommandLine#getProperties()
  +     */
       public Properties getProperties() {
  -    	return properties;
  +        return properties;
       }
  -    
  -    public void setProperties( Properties properties ) {
  -    	this.properties = properties;
  +
  +    /**
  +     * @see CommandLineCreator#setProperties(java.util.Properties)
  +     */
  +    public void setProperties(Properties properties) {
  +        this.properties = properties;
       }
  -    
  +
  +    /**
  +     * @see CommandLine#iterator()
  +     */
       public Iterator iterator() {
  -    	return cache.keySet().iterator();
  +        return cache.keySet().iterator();
       }
   
  -	public List getAnonymousValues() {
  -		return anonymous;
  -	}
  +    /**
  +     * @see CommandLine#getAnonymousValues()
  +     */
  +    public List getAnonymousValues() {
  +        return anonymous;
  +    }
   
   }
  
  
  

---------------------------------------------------------------------
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