jkeyes 2003/10/31 14:12:54
Modified: cli/src/java/org/apache/commons/cli2 DefaultOption.java
Log:
- removed TABs
Revision Changes Path
1.5 +216 -208
jakarta-commons-sandbox/cli/src/java/org/apache/commons/cli2/DefaultOption.java
Index: DefaultOption.java
===================================================================
RCS file:
/home/cvs/jakarta-commons-sandbox/cli/src/java/org/apache/commons/cli2/DefaultOption.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- DefaultOption.java 29 Oct 2003 17:32:12 -0000 1.4
+++ DefaultOption.java 31 Oct 2003 22:12:54 -0000 1.5
@@ -1,62 +1,50 @@
/*
- * $Header$
- * $Revision$
+ * $Header$
+ * $Revision$
* $Date$
- *
+ *
* ====================================================================
- *
+ *
* The Apache Software License, Version 1.1
- *
- * Copyright (c) 2003 The Apache Software Foundation. All rights
- * reserved.
- *
+ *
+ * Copyright (c) 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 [EMAIL PROTECTED]
- *
- * 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 GroupImpl.
- *
- * 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.
+ * 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 [EMAIL PROTECTED]
+ * 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 GroupImpl.
+ *
+ * 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/>.
- *
+ *
+ * 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.cli2;
@@ -75,175 +63,195 @@
public static final String DEFAULT_LONG_PREFIX = "--";
public static final boolean DEFAULT_BURST_ENABLED = true;
- private final String preferredName;
- private final Set aliases;
- private final Set burstAliases;
- private final boolean required;
- private final Set triggers = new HashSet();
-
- private final String shortPrefix;
- private final String longPrefix;
- private final boolean burstEnabled;
-
- private final int burstLength;
-
- protected DefaultOption(
- final String shortPrefix,
- final String longPrefix,
- final boolean burstEnabled,
- final String preferredName,
- final String description,
- final Set aliases,
- final Set burstAliases,
- final boolean required,
- final Argument argument,
- final Group children,
+ private final String preferredName;
+ private final Set aliases;
+ private final Set burstAliases;
+ private final boolean required;
+ private final Set triggers = new HashSet();
+
+ private final String shortPrefix;
+ private final String longPrefix;
+ private final boolean burstEnabled;
+
+ private final int burstLength;
+
+ protected DefaultOption(
+ final String shortPrefix,
+ final String longPrefix,
+ final boolean burstEnabled,
+ final String preferredName,
+ final String description,
+ final Set aliases,
+ final Set burstAliases,
+ final boolean required,
+ final Argument argument,
+ final Group children,
final int id) {
- super(argument, children, description, id);
+ super(argument, children, description, id);
- this.longPrefix = longPrefix;
- this.shortPrefix = shortPrefix;
- this.burstEnabled = burstEnabled;
-
- this.burstLength = shortPrefix.length() + 1;
-
- this.preferredName = preferredName;
- if (aliases == null) {
- this.aliases = Collections.EMPTY_SET;
- } else {
- this.aliases = aliases;
- }
-
- if (burstAliases == null) {
- this.burstAliases = Collections.EMPTY_SET;
- } else {
- this.burstAliases = burstAliases;
- }
- this.required = required;
-
- this.triggers.add(preferredName);
- this.triggers.addAll(this.aliases);
- this.triggers.addAll(this.burstAliases);
- }
-
- /* (non-Javadoc)
+ this.longPrefix = longPrefix;
+ this.shortPrefix = shortPrefix;
+ this.burstEnabled = burstEnabled;
+
+ this.burstLength = shortPrefix.length() + 1;
+
+ this.preferredName = preferredName;
+ if (aliases == null) {
+ this.aliases = Collections.EMPTY_SET;
+ }
+ else {
+ this.aliases = aliases;
+ }
+
+ if (burstAliases == null) {
+ this.burstAliases = Collections.EMPTY_SET;
+ }
+ else {
+ this.burstAliases = burstAliases;
+ }
+ this.required = required;
+
+ this.triggers.add(preferredName);
+ this.triggers.addAll(this.aliases);
+ this.triggers.addAll(this.burstAliases);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
* @see org.apache.commons.cli3.Option#canProcess(java.lang.String)
*/
- public boolean canProcess(final String argument) {
- return argument != null
- && (super.canProcess(argument)
- || (argument.length() >= burstLength
- && burstAliases.contains(argument.substring(0,
burstLength))));
- }
-
- /* (non-Javadoc)
- * @see
org.apache.commons.cli2.Parent#processParent(org.apache.commons.cli2.CommandLine,
java.util.ListIterator)
- */
- public void processParent(CommandLine commandLine, ListIterator arguments)
- throws OptionException {
-
- final String argument = (String) arguments.next();
-
- if (triggers.contains(argument)) {
- commandLine.addOption(this);
- arguments.set(preferredName);
- } else if (burstEnabled && argument.length() >= burstLength) {
- final String burst = argument.substring(0, burstLength);
-
- if (burstAliases.contains(burst)) {
- commandLine.addOption(this);
-
- //HMM test bursting all vs bursting one by one.
- arguments.set(preferredName);
-
- if(getArgument()==null){
- arguments.add(shortPrefix + argument.substring(burstLength));
+ public boolean canProcess(final String argument) {
+ return argument != null
+ && (super.canProcess(argument)
+ || (argument.length() >= burstLength
+ && burstAliases.contains(argument.substring(0, burstLength))));
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
org.apache.commons.cli2.Parent#processParent(org.apache.commons.cli2.CommandLine,
+ * java.util.ListIterator)
+ */
+ public void processParent(CommandLine commandLine, ListIterator arguments)
+ throws OptionException {
+
+ final String argument = (String) arguments.next();
+
+ if (triggers.contains(argument)) {
+ commandLine.addOption(this);
+ arguments.set(preferredName);
+ }
+ else if (burstEnabled && argument.length() >= burstLength) {
+ final String burst = argument.substring(0, burstLength);
+
+ if (burstAliases.contains(burst)) {
+ commandLine.addOption(this);
+
+ //HMM test bursting all vs bursting one by one.
+ arguments.set(preferredName);
+
+ if (getArgument() == null) {
+ arguments.add(
+ shortPrefix + argument.substring(burstLength));
}
- else{
+ else {
arguments.add(argument.substring(burstLength));
}
-
- arguments.previous();
- } else {
- throw new BurstException(this, argument);
- }
- } else {
- throw new UnexpectedOptionException(this, argument);
- }
- }
- /* (non-Javadoc)
+ arguments.previous();
+ }
+ else {
+ throw new BurstException(this, argument);
+ }
+ }
+ else {
+ throw new UnexpectedOptionException(this, argument);
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ *
* @see org.apache.commons.cli2.Option#triggers()
*/
- public Set triggers() {
- return triggers;
- }
- /* (non-Javadoc)
+ public Set triggers() {
+ return triggers;
+ }
+ /*
+ * (non-Javadoc)
+ *
* @see org.apache.commons.cli2.Option#prefixes()
*/
- public Set prefixes() {
- final Set prefixes = new HashSet(super.prefixes());
+ public Set prefixes() {
+ final Set prefixes = new HashSet(super.prefixes());
- prefixes.add(shortPrefix);
- prefixes.add(longPrefix);
+ prefixes.add(shortPrefix);
+ prefixes.add(longPrefix);
- return prefixes;
- }
+ return prefixes;
+ }
- /* (non-Javadoc)
+ /*
+ * (non-Javadoc)
+ *
* @see
org.apache.commons.cli2.Option#validate(org.apache.commons.cli2.CommandLine)
*/
- public void validate(CommandLine commandLine) throws OptionException {
- if (required && !commandLine.hasOption(this)) {
- throw new MissingOptionException(this);
- }
-
- super.validate(commandLine);
- }
-
- /* (non-Javadoc)
- * @see org.apache.commons.cli2.Option#appendUsage(java.lang.StringBuffer,
java.util.Set, java.util.Comparator)
- */
- public void appendUsage(
- final StringBuffer buffer,
- final Set helpSettings,
- final Comparator comp) {
-
- // do we display optionality
- final boolean optional =
- !required &&
helpSettings.contains(HelpSetting.DISPLAY_OPTIONAL);
- final boolean displayAliases =
- helpSettings.contains(HelpSetting.DISPLAY_ALIASES);
-
- if (optional) {
- buffer.append('[');
- }
- buffer.append(preferredName);
-
- if (displayAliases && !aliases.isEmpty()) {
- buffer.append(" (");
-
- final List list = new ArrayList(aliases);
- Collections.sort(list);
-
- for (final Iterator i = list.iterator(); i.hasNext();) {
- final String alias = (String) i.next();
- buffer.append(alias);
- if (i.hasNext()) {
- buffer.append(',');
- }
- }
- buffer.append(')');
- }
-
- super.appendUsage(buffer, helpSettings, comp);
-
- if (optional) {
- buffer.append(']');
- }
- }
-
- public String getPreferredName() {
- return preferredName;
- }
+ public void validate(CommandLine commandLine) throws OptionException {
+ if (required && !commandLine.hasOption(this)) {
+ throw new MissingOptionException(this);
+ }
+
+ super.validate(commandLine);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.apache.commons.cli2.Option#appendUsage(java.lang.StringBuffer,
+ * java.util.Set, java.util.Comparator)
+ */
+ public void appendUsage(
+ final StringBuffer buffer,
+ final Set helpSettings,
+ final Comparator comp) {
+
+ // do we display optionality
+ final boolean optional =
+ !required && helpSettings.contains(HelpSetting.DISPLAY_OPTIONAL);
+ final boolean displayAliases =
+ helpSettings.contains(HelpSetting.DISPLAY_ALIASES);
+
+ if (optional) {
+ buffer.append('[');
+ }
+ buffer.append(preferredName);
+
+ if (displayAliases && !aliases.isEmpty()) {
+ buffer.append(" (");
+
+ final List list = new ArrayList(aliases);
+ Collections.sort(list);
+
+ for (final Iterator i = list.iterator(); i.hasNext();) {
+ final String alias = (String) i.next();
+ buffer.append(alias);
+ if (i.hasNext()) {
+ buffer.append(',');
+ }
+ }
+ buffer.append(')');
+ }
+
+ super.appendUsage(buffer, helpSettings, comp);
+
+ if (optional) {
+ buffer.append(']');
+ }
+ }
+
+ public String getPreferredName() {
+ return preferredName;
+ }
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]