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/24 23:54:16 UTC
cvs commit: jakarta-commons/cli/src/java/org/apache/commons/cli Argument.java AnonymousArgumentImpl.java ArgumentImpl.java
jkeyes 2003/05/24 14:54:15
Modified: cli/src/java/org/apache/commons/cli Tag: cli_1_x
Argument.java AnonymousArgumentImpl.java
ArgumentImpl.java
Log:
added Javadoc
added license
replaced tabs with spaces
Revision Changes Path
No revision
No revision
1.1.2.3 +23 -28 jakarta-commons/cli/src/java/org/apache/commons/cli/Attic/Argument.java
Index: Argument.java
===================================================================
RCS file: /home/cvs/jakarta-commons/cli/src/java/org/apache/commons/cli/Attic/Argument.java,v
retrieving revision 1.1.2.2
retrieving revision 1.1.2.3
diff -u -r1.1.2.2 -r1.1.2.3
--- Argument.java 22 May 2003 23:11:35 -0000 1.1.2.2
+++ Argument.java 24 May 2003 21:54:15 -0000 1.1.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
@@ -69,51 +69,46 @@
*/
public interface Argument extends Option {
- /**
- * Returns the Class type of the argument value(s)
- * For example, Integer.class
- *
- * @return
- * the Class type
- */
- public Class getValueType();
-
+ /**
+ * Returns the Class type of the argument value(s)
+ * For example, Integer.class
+ *
+ * @return the Class type
+ */
+ Class getValueType();
+
/**
* Returns the value separator of the argument values.
* For example, if the value is 'a,b,c' and the value separator
* is ',' then there are three values 'a', 'b' and 'c'.
*
- * @return
- * the character that is used as the value separator
+ * @return the character that is used as the value separator
*/
- public char getValueSeparator();
-
+ char getValueSeparator();
+
/**
* Returns the name of the value to be used in help text.
* For example, if the argument was -date and the value
* name could be 'DD/MM/YYYY' which would be displayed in
* the help text, rather than the default 'arg'.
*
- * @return
- * the name to be displayed in the help text
+ * @return the name to be displayed in the help text
*/
- public String getValueName();
-
+ String getValueName();
+
/**
* Returns the number of values that this argument is permitted
* to have.
*
- * @return
- * the number of argument values
+ * @return the number of argument values
*/
- public int getSize();
-
+ int getSize();
+
/**
* Returns whether the values of this argument are optional.
* If they are optional the argument is effectively an Option.
*
- * @return
- * whether the values of this argument are optional
+ * @return whether the values of this argument are optional
*/
- public boolean hasOptionalValues();
+ boolean hasOptionalValues();
}
1.1.2.2 +204 -69 jakarta-commons/cli/src/java/org/apache/commons/cli/Attic/AnonymousArgumentImpl.java
Index: AnonymousArgumentImpl.java
===================================================================
RCS file: /home/cvs/jakarta-commons/cli/src/java/org/apache/commons/cli/Attic/AnonymousArgumentImpl.java,v
retrieving revision 1.1.2.1
retrieving revision 1.1.2.2
diff -u -r1.1.2.1 -r1.1.2.2
--- AnonymousArgumentImpl.java 19 May 2003 20:57:51 -0000 1.1.2.1
+++ AnonymousArgumentImpl.java 24 May 2003 21:54:15 -0000 1.1.2.2
@@ -1,80 +1,215 @@
/*
- * Created on Feb 26, 2003
+ * $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/>;.
*
- * To change this generated comment go to
- * Window>Preferences>Java>Code Generation>Code Template
*/
package org.apache.commons.cli;
import java.util.Set;
/**
- * @author jkeyes
+ * AnonyousArgumentImpl is a special Argument that consumes trailing
+ * argument values. This Argument can also have children, this is to
+ * support <i>CVS like</i> command lines.
+ *
+ * @author John Keyes
+ * @since 2.0
+ *
+ * @task The use and behaviour of anonymous Arguments needs to
+ * be reviewed. There are many unsupported methods in this
+ * class and some of them possibly should be.
*/
class AnonymousArgumentImpl implements Argument {
-
- private String valueName;
- private Set children;
-
- AnonymousArgumentImpl( final String name ) {
- this.valueName = name;
- }
-
- AnonymousArgumentImpl( final String name, final Set children ) {
- this.valueName = name;
- this.children = children;
- }
-
- public int getSize() {
- return 0;
- }
-
- public String getValueName() {
- return this.valueName;
- }
-
- public char getValueSeparator() {
- throw new UnsupportedOperationException("cannot get value separator of anonymous option");
- }
-
- public Class getValueType() {
- throw new UnsupportedOperationException("cannot get type of anonymous option");
- }
-
- public boolean hasOptionalValues() {
- throw new UnsupportedOperationException("anonymous argument cannot have optional values");
- }
-
- public void addChild( Option child ) {
- throw new UnsupportedOperationException("cannot add a child to anonymous option");
- }
-
- public void addChildren( Set children ) {
- this.children = children;
- }
-
- public Set getChildren( ) {
- return this.children;
- }
-
- public boolean hasChildren() {
- return (children != null && this.children.size() > 0);
- }
-
- public String getDescription( ) {
- throw new UnsupportedOperationException("anonymous argument cannot have a description");
- }
-
- public String getName() {
- throw new UnsupportedOperationException("anonymous argument cannot have a name");
- }
-
- public String getLongName() {
- throw new UnsupportedOperationException("anonymous argument cannot have a long name");
- }
-
- public boolean isRequired() {
- throw new UnsupportedOperationException("anonymous argument cannot be required (yet)");
- }
-}
+ /** the name of the value for help text */
+ private String valueName;
+
+ /** the arguments children */
+ private Set children;
+
+ /**
+ * Creates an anonymous Argument with the specified name.
+ *
+ * @param name
+ * the textual description of the anonymous argument
+ */
+ AnonymousArgumentImpl(final String name) {
+ this.valueName = name;
+ }
+
+ /**
+ * Creates an anonymous Argument with the specified name and
+ * children.
+ *
+ * @param name
+ * the textual description of the anonymous argument
+ *
+ * @param children
+ * the child Options
+ */
+ AnonymousArgumentImpl(final String name, final Set children) {
+ this.valueName = name;
+ this.children = children;
+ }
+
+ /**
+ * @task implement this method
+ * Returns the number of values for this Argument.
+ *
+ * @return the number of values
+ */
+ public int getSize() {
+ return 0;
+ }
+
+ /**
+ * @task this should be implemented by the getDescription
+ * method
+ *
+ * Returns the textual description of this Argument
+ *
+ * @return the textual description
+ */
+ public String getValueName() {
+ return this.valueName;
+ }
+
+ /**
+ * Throws an UnsupportedOperationException as anonymous
+ * Arguments cannot have character separators.
+ */
+ public char getValueSeparator() {
+ throw new UnsupportedOperationException("cannot get value separator of anonymous option");
+ }
+
+ /**
+ * Throws an UnsupportedOperationException as anonymous
+ * Arguments cannot have a type.
+ */
+ public Class getValueType() {
+ throw new UnsupportedOperationException("cannot get type of anonymous option");
+ }
+
+ /**
+ * Throws an UnsupportedOperationException as anonymous
+ * Arguments cannot have optional values.
+ */
+ public boolean hasOptionalValues() {
+ throw new UnsupportedOperationException("anonymous argument cannot have optional values");
+ }
+
+ /**
+ * @see Option.addChild()
+ */
+ public void addChild(Option child) {
+ throw new UnsupportedOperationException("cannot add a child to anonymous option");
+ }
+
+ /**
+ * @see Option#addChildren(java.util.Set)
+ */
+ public void addChildren(Set children) {
+ this.children = children;
+ }
+
+ /**
+ * @see Option#getChildren()
+ */
+ public Set getChildren() {
+ return this.children;
+ }
+
+ /**
+ * @see Option#hasChildren()
+ */
+ public boolean hasChildren() {
+ return (children != null && this.children.size() > 0);
+ }
+
+ /**
+ * Throws an UnsupportedOperationException as anonymous
+ * Arguments cannot have a description.
+ */
+ public String getDescription() {
+ throw new UnsupportedOperationException("anonymous argument cannot have a description");
+ }
+
+ /**
+ * Throws an UnsupportedOperationException as anonymous
+ * Arguments cannot have a name.
+ */
+ public String getName() {
+ throw new UnsupportedOperationException("anonymous argument cannot have a name");
+ }
+
+ /**
+ * Throws an UnsupportedOperationException as anonymous
+ * Arguments cannot have a long name.
+ */
+ public String getLongName() {
+ throw new UnsupportedOperationException("anonymous argument cannot have a long name");
+ }
+
+ /**
+ * Throws an UnsupportedOperationException as anonymous
+ * Arguments cannot have be required.
+ */
+ public boolean isRequired() {
+ throw new UnsupportedOperationException("anonymous argument cannot be required (yet)");
+ }
+}
1.1.2.2 +381 -29 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.1
retrieving revision 1.1.2.2
diff -u -r1.1.2.1 -r1.1.2.2
--- ArgumentImpl.java 19 May 2003 20:57:51 -0000 1.1.2.1
+++ ArgumentImpl.java 24 May 2003 21:54:15 -0000 1.1.2.2
@@ -1,71 +1,423 @@
+/*
+ * $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;
+/**
+ * Implementation of the Argument interface.
+ *
+ * @author John Keyes
+ */
class ArgumentImpl extends OptionImpl implements Argument {
+ /** the number of values */
private final int size;
+
+ /** the value separator */
private final char valueSeparator;
+
+ /** the name of the value */
private final String valueName;
+
+ /** the type of the value(s) */
private final Class type;
+
+ /** 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) );
- }
-
+ 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) );
- }
-
+ 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) );
- }
+ 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
+ * 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)
+ *
+ * @param hasOptionalValues
+ * whether this Argument has optional values
+ *
+ * @param children
+ * the child Options of this Argument
+ */
+ public ArgumentImpl(
+ String name,
+ String longName,
+ String description,
+ boolean required,
+ int size,
+ Class type,
+ char valueSeparator,
+ String valueName,
+ boolean hasOptionalValues,
+ Set children) {
- public ArgumentImpl(String name, String longName, String description, boolean required) {
- this( name, longName, description, required, 1, null, (char)0, "arg", false, new HashSet(0) );
- }
-
- 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) );
- }
-
- 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) );
- }
-
- 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) );
- }
-
- public ArgumentImpl(String name, String longName, String description, boolean required, int size, Class type, char valueSeparator, String valueName, boolean hasOptionalValues, Set children) {
super(name, longName, description, required, children);
-
+
this.size = size;
this.type = type;
- this.valueSeparator= valueSeparator;
+ this.valueSeparator = valueSeparator;
this.valueName = valueName;
this.hasOptionalValues = hasOptionalValues;
}
+ /**
+ * @see Argument#getSize()
+ */
public int getSize() {
return this.size;
}
+ /**
+ * @see Argument#getValueSeparator()
+ */
public char getValueSeparator() {
return this.valueSeparator;
}
+ /**
+ * @see Argument#getValueName()
+ */
public String getValueName() {
return this.valueName;
}
+ /**
+ * @see Argument#getValueType()
+ */
public Class getValueType() {
return this.type;
}
-
+
+ /**
+ * @see Argument#hasOptionalValues()
+ */
public boolean hasOptionalValues() {
- return this.hasOptionalValues;
+ return this.hasOptionalValues;
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org