commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bay...@apache.org
Subject svn commit: r639941 [3/17] - in /commons/proper/cli/trunk: ./ src/java/org/apache/commons/cli2/ src/java/org/apache/commons/cli2/builder/ src/java/org/apache/commons/cli2/commandline/ src/java/org/apache/commons/cli2/option/ src/java/org/apache/commons...
Date Sat, 22 Mar 2008 02:49:46 GMT
Modified: commons/proper/cli/trunk/src/java/org/apache/commons/cli2/commandline/DefaultingCommandLine.java
URL: http://svn.apache.org/viewvc/commons/proper/cli/trunk/src/java/org/apache/commons/cli2/commandline/DefaultingCommandLine.java?rev=639941&r1=639940&r2=639941&view=diff
==============================================================================
--- commons/proper/cli/trunk/src/java/org/apache/commons/cli2/commandline/DefaultingCommandLine.java (original)
+++ commons/proper/cli/trunk/src/java/org/apache/commons/cli2/commandline/DefaultingCommandLine.java Fri Mar 21 19:49:41 2008
@@ -1,172 +1 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.commons.cli2.commandline;
-
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Set;
-
-import org.apache.commons.cli2.CommandLine;
-import org.apache.commons.cli2.Option;
-
-/**
- * Manages a queue of default CommandLines. This CommandLine implementation is
- * backed by a queue of CommandLine instances which are queried in turn until a
- * suitable result is found.
- * 
- * CommandLine instances can either be added to the back of the queue or can be
- * pushed in at a specific position.
- * 
- * @see #appendCommandLine(CommandLine)
- * @see #insertCommandLine(int, CommandLine)
- */
-public class DefaultingCommandLine extends CommandLineImpl {
-
-    /**
-     * The list of default CommandLine instances
-     */
-    private final List commandLines = new ArrayList();
-
-    /**
-     * Adds a CommandLine instance to the back of the queue. The supplied
-     * CommandLine will be used as defaults when all other CommandLines produce
-     * no result
-     * 
-     * @param commandLine
-     *            the default values to use if all CommandLines
-     */
-    public void appendCommandLine(final CommandLine commandLine) {
-        commandLines.add(commandLine);
-    }
-    
-    /**
-     * Adds a CommandLine instance to a specified position in the queue.
-     * 
-     * @param index ths position at which to insert
-     * @param commandLine the CommandLine to insert
-     */
-    public void insertCommandLine(
-        final int index,
-        final CommandLine commandLine) {
-        commandLines.add(index, commandLine);
-    }
-    
-    /**
-     * Builds an iterator over the build in CommandLines.
-     * 
-     * @return an unmodifiable iterator
-     */
-    public Iterator commandLines(){
-    	return Collections.unmodifiableList(commandLines).iterator();
-    }
-
-    public Option getOption(String trigger) {
-        for (final Iterator i = commandLines.iterator(); i.hasNext();) {
-            final CommandLine commandLine = (CommandLine)i.next();
-            final Option actual = commandLine.getOption(trigger);
-            if (actual != null) {
-                return actual;
-            }
-        }
-        return null;
-    }
-
-    public List getOptions() {
-        final List options = new ArrayList();
-
-        final List temp = new ArrayList();
-        for (final Iterator i = commandLines.iterator(); i.hasNext();) {
-            final CommandLine commandLine = (CommandLine)i.next();
-            temp.clear();
-            temp.addAll(commandLine.getOptions());
-            temp.removeAll(options);
-            options.addAll(temp);
-        }
-
-        return Collections.unmodifiableList(options);
-    }
-
-    public Set getOptionTriggers() {
-        final Set all = new HashSet();
-        for (final Iterator i = commandLines.iterator(); i.hasNext();) {
-            final CommandLine commandLine = (CommandLine)i.next();
-            all.addAll(commandLine.getOptionTriggers());
-        }
-
-        return Collections.unmodifiableSet(all);
-    }
-
-    public boolean hasOption(Option option) {
-        for (final Iterator i = commandLines.iterator(); i.hasNext();) {
-            final CommandLine commandLine = (CommandLine)i.next();
-            if (commandLine.hasOption(option)) {
-                return true;
-            }
-        }
-        return false;
-    }
-
-    public List getValues(Option option, List defaultValues) {
-        for (final Iterator i = commandLines.iterator(); i.hasNext();) {
-            final CommandLine commandLine = (CommandLine)i.next();
-            final List actual = commandLine.getValues(option);
-            if (actual != null && !actual.isEmpty()) {
-                return actual;
-            }
-        }
-        if(defaultValues==null){
-        	return Collections.EMPTY_LIST;
-        }
-        else{
-        	return defaultValues;
-        }
-    }
-
-    public Boolean getSwitch(Option option, Boolean defaultValue) {
-        for (final Iterator i = commandLines.iterator(); i.hasNext();) {
-            final CommandLine commandLine = (CommandLine)i.next();
-            final Boolean actual = commandLine.getSwitch(option);
-            if (actual != null) {
-                return actual;
-            }
-        }
-        return defaultValue;
-    }
-
-    public String getProperty(String property, String defaultValue) {
-        for (final Iterator i = commandLines.iterator(); i.hasNext();) {
-            final CommandLine commandLine = (CommandLine)i.next();
-            final String actual = commandLine.getProperty(property);
-            if (actual != null) {
-                return actual;
-            }
-        }
-        return defaultValue;
-    }
-
-    public Set getProperties() {
-        final Set all = new HashSet();
-        for (final Iterator i = commandLines.iterator(); i.hasNext();) {
-            final CommandLine commandLine = (CommandLine)i.next();
-            all.addAll(commandLine.getProperties());
-        }
-        return Collections.unmodifiableSet(all);
-    }
-}
+/** * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements.  See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License.  You may obtain a copy of the License at * *     http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */package org.apache.commons.cli2.commandline;import java.util.ArrayList;import java.util.Collections;import java.util.HashSet;import java.util.Iterator;import java.util.List;import java.util.Set;import o
 rg.apache.commons.cli2.CommandLine;import org.apache.commons.cli2.Option;/** * Manages a queue of default CommandLines. This CommandLine implementation is * backed by a queue of CommandLine instances which are queried in turn until a * suitable result is found. * * CommandLine instances can either be added to the back of the queue or can be * pushed in at a specific position. * * @see #appendCommandLine(CommandLine) * @see #insertCommandLine(int, CommandLine) */public class DefaultingCommandLine extends CommandLineImpl {    /**     * The list of default CommandLine instances     */    private final List commandLines = new ArrayList();    /**     * Adds a CommandLine instance to the back of the queue. The supplied     * CommandLine will be used as defaults when all other CommandLines produce     * no result     *     * @param commandLine     *            the default values to use if all CommandLines     */    public void appendCommandLine(final CommandLine commandLine) {     
    commandLines.add(commandLine);    }    /**     * Adds a CommandLine instance to a specified position in the queue.     *     * @param index ths position at which to insert     * @param commandLine the CommandLine to insert     */    public void insertCommandLine(        final int index,        final CommandLine commandLine) {        commandLines.add(index, commandLine);    }    /**     * Builds an iterator over the build in CommandLines.     *     * @return an unmodifiable iterator     */    public Iterator commandLines(){    	return Collections.unmodifiableList(commandLines).iterator();    }    public Option getOption(String trigger) {        for (final Iterator i = commandLines.iterator(); i.hasNext();) {            final CommandLine commandLine = (CommandLine)i.next();            final Option actual = commandLine.getOption(trigger);            if (actual != null) {                return actual;            }        }        return null;    }    public List getOptions() 
 {        final List options = new ArrayList();        final List temp = new ArrayList();        for (final Iterator i = commandLines.iterator(); i.hasNext();) {            final CommandLine commandLine = (CommandLine)i.next();            temp.clear();            temp.addAll(commandLine.getOptions());            temp.removeAll(options);            options.addAll(temp);        }        return Collections.unmodifiableList(options);    }    public Set getOptionTriggers() {        final Set all = new HashSet();        for (final Iterator i = commandLines.iterator(); i.hasNext();) {            final CommandLine commandLine = (CommandLine)i.next();            all.addAll(commandLine.getOptionTriggers());        }        return Collections.unmodifiableSet(all);    }    public boolean hasOption(Option option) {        for (final Iterator i = commandLines.iterator(); i.hasNext();) {            final CommandLine commandLine = (CommandLine)i.next();            if (commandLine.hasOption(o
 ption)) {                return true;            }        }        return false;    }    public List getValues(Option option, List defaultValues) {        for (final Iterator i = commandLines.iterator(); i.hasNext();) {            final CommandLine commandLine = (CommandLine)i.next();            final List actual = commandLine.getValues(option);            if (actual != null && !actual.isEmpty()) {                return actual;            }        }        if(defaultValues==null){        	return Collections.EMPTY_LIST;        }        else{        	return defaultValues;        }    }    public Boolean getSwitch(Option option, Boolean defaultValue) {        for (final Iterator i = commandLines.iterator(); i.hasNext();) {            final CommandLine commandLine = (CommandLine)i.next();            final Boolean actual = commandLine.getSwitch(option);            if (actual != null) {                return actual;            }        }        return defaultValue;    }    public 
 String getProperty(String property, String defaultValue) {        for (final Iterator i = commandLines.iterator(); i.hasNext();) {            final CommandLine commandLine = (CommandLine)i.next();            final String actual = commandLine.getProperty(property);            if (actual != null) {                return actual;            }        }        return defaultValue;    }    public Set getProperties() {        final Set all = new HashSet();        for (final Iterator i = commandLines.iterator(); i.hasNext();) {            final CommandLine commandLine = (CommandLine)i.next();            all.addAll(commandLine.getProperties());        }        return Collections.unmodifiableSet(all);    }}
\ No newline at end of file

Modified: commons/proper/cli/trunk/src/java/org/apache/commons/cli2/commandline/Parser.java
URL: http://svn.apache.org/viewvc/commons/proper/cli/trunk/src/java/org/apache/commons/cli2/commandline/Parser.java?rev=639941&r1=639940&r2=639941&view=diff
==============================================================================
--- commons/proper/cli/trunk/src/java/org/apache/commons/cli2/commandline/Parser.java (original)
+++ commons/proper/cli/trunk/src/java/org/apache/commons/cli2/commandline/Parser.java Fri Mar 21 19:49:41 2008
@@ -1,176 +1 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.commons.cli2.commandline;
-
-import java.util.LinkedList;
-import java.util.List;
-import java.util.ListIterator;
-
-import org.apache.commons.cli2.CommandLine;
-import org.apache.commons.cli2.Group;
-import org.apache.commons.cli2.Option;
-import org.apache.commons.cli2.OptionException;
-import org.apache.commons.cli2.WriteableCommandLine;
-import org.apache.commons.cli2.resource.ResourceConstants;
-import org.apache.commons.cli2.util.HelpFormatter;
-
-/**
- * A class that implements the <code>Parser</code> interface can parse a
- * String array according to the {@link Group}specified and return a
- * {@link CommandLine}.
- *
- * @author John Keyes (john at integralsource.com)
- */
-public class Parser {
-    private HelpFormatter helpFormatter = new HelpFormatter();
-    private Option helpOption = null;
-    private String helpTrigger = null;
-    private Group group = null;
-
-    /**
-     * Parse the arguments according to the specified options and properties.
-     *
-     * @param arguments
-     *            the command line arguments
-     *
-     * @return the list of atomic option and value tokens
-     * @throws OptionException
-     *             if there are any problems encountered while parsing the
-     *             command line tokens.
-     */
-    public CommandLine parse(final String[] arguments)
-        throws OptionException {
-        // build a mutable list for the arguments
-        final List argumentList = new LinkedList();
-
-        // copy the arguments into the new list
-        for (int i = 0; i < arguments.length; i++) {
-            final String argument = arguments[i];
-
-            // ensure non intern'd strings are used 
-            // so that == comparisons work as expected
-            argumentList.add(new String(argument));
-        }
-
-        // wet up a command line for this group
-        final WriteableCommandLine commandLine = new WriteableCommandLineImpl(group, argumentList);
-
-        // pick up any defaults from the model
-        group.defaults(commandLine);
-
-        // process the options as far as possible
-        final ListIterator iterator = argumentList.listIterator();
-        Object previous = null;
-
-        while (group.canProcess(commandLine, iterator)) {
-            // peek at the next item and backtrack
-            final Object next = iterator.next();
-            iterator.previous();
-
-            // if we have just tried to process this instance
-            if (next == previous) {
-                // abort
-                break;
-            }
-
-            // remember previous
-            previous = next;
-
-            group.process(commandLine, iterator);
-        }
-
-        // if there are more arguments we have a problem
-        if (iterator.hasNext()) {
-            final String arg = (String) iterator.next();
-            throw new OptionException(group, ResourceConstants.UNEXPECTED_TOKEN, arg);
-        }
-
-        // no need to validate if the help option is present
-        if (!commandLine.hasOption(helpOption) && !commandLine.hasOption(helpTrigger)) {
-            group.validate(commandLine);
-        }
-
-        return commandLine;
-    }
-
-    /**
-     * Parse the arguments according to the specified options and properties and
-     * displays the usage screen if the CommandLine is not valid or the help
-     * option was specified.
-     *
-     * @param arguments the command line arguments
-     * @return a valid CommandLine or null if the parse was unsuccessful
-     * @throws IOException if an error occurs while formatting help
-     */
-    public CommandLine parseAndHelp(final String[] arguments) {
-        helpFormatter.setGroup(group);
-
-        try {
-            // attempt to parse the command line
-            final CommandLine commandLine = parse(arguments);
-
-            if (!commandLine.hasOption(helpOption) && !commandLine.hasOption(helpTrigger)) {
-                return commandLine;
-            }
-        } catch (final OptionException oe) {
-            // display help regarding the exception
-            helpFormatter.setException(oe);
-        }
-
-        // print help
-        helpFormatter.print();
-
-        return null;
-    }
-
-    /**
-     * Sets the Group of options to parse against
-     * @param group the group of options to parse against
-     */
-    public void setGroup(final Group group) {
-        this.group = group;
-    }
-
-    /**
-     * Sets the HelpFormatter to use with the simplified parsing.
-     * @see #parseAndHelp(String[])
-     * @param helpFormatter the HelpFormatter to use with the simplified parsing
-     */
-    public void setHelpFormatter(final HelpFormatter helpFormatter) {
-        this.helpFormatter = helpFormatter;
-    }
-
-    /**
-     * Sets the help option to use with the simplified parsing.  For example
-     * <code>--help</code>, <code>-h</code> and <code>-?</code> are often used.
-     * @see #parseAndHelp(String[])
-     * @param helpOption the help Option
-     */
-    public void setHelpOption(final Option helpOption) {
-        this.helpOption = helpOption;
-    }
-
-    /**
-     * Sets the help option to use with the simplified parsing.  For example
-     * <code>--help</code>, <code>-h</code> and <code>-?</code> are often used.
-     * @see #parseAndHelp(String[])
-     * @param helpTrigger the trigger of the help Option
-     */
-    public void setHelpTrigger(final String helpTrigger) {
-        this.helpTrigger = helpTrigger;
-    }
-}
+/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements.  See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License.  You may obtain a copy of the License at * *     http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */package org.apache.commons.cli2.commandline;import java.util.LinkedList;import java.util.List;import java.util.ListIterator;import org.apache.commons.cli2.CommandLine;import org.apache.commons.cli2.Group
 ;import org.apache.commons.cli2.Option;import org.apache.commons.cli2.OptionException;import org.apache.commons.cli2.WriteableCommandLine;import org.apache.commons.cli2.resource.ResourceConstants;import org.apache.commons.cli2.util.HelpFormatter;/** * A class that implements the <code>Parser</code> interface can parse a * String array according to the {@link Group}specified and return a * {@link CommandLine}. * * @author John Keyes (john at integralsource.com) */public class Parser {    private HelpFormatter helpFormatter = new HelpFormatter();    private Option helpOption = null;    private String helpTrigger = null;    private Group group = null;    /**     * Parse the arguments according to the specified options and properties.     *     * @param arguments     *            the command line arguments     *     * @return the list of atomic option and value tokens     * @throws OptionException     *             if there are any problems encountered while parsing the     *   
           command line tokens.     */    public CommandLine parse(final String[] arguments)        throws OptionException {        // build a mutable list for the arguments        final List argumentList = new LinkedList();        // copy the arguments into the new list        for (int i = 0; i < arguments.length; i++) {            final String argument = arguments[i];            // ensure non intern'd strings are used            // so that == comparisons work as expected            argumentList.add(new String(argument));        }        // wet up a command line for this group        final WriteableCommandLine commandLine = new WriteableCommandLineImpl(group, argumentList);        // pick up any defaults from the model        group.defaults(commandLine);        // process the options as far as possible        final ListIterator iterator = argumentList.listIterator();        Object previous = null;        while (group.canProcess(commandLine, iterator)) {            // peek at
  the next item and backtrack            final Object next = iterator.next();            iterator.previous();            // if we have just tried to process this instance            if (next == previous) {                // abort                break;            }            // remember previous            previous = next;            group.process(commandLine, iterator);        }        // if there are more arguments we have a problem        if (iterator.hasNext()) {            final String arg = (String) iterator.next();            throw new OptionException(group, ResourceConstants.UNEXPECTED_TOKEN, arg);        }        // no need to validate if the help option is present        if (!commandLine.hasOption(helpOption) && !commandLine.hasOption(helpTrigger)) {            group.validate(commandLine);        }        return commandLine;    }    /**     * Parse the arguments according to the specified options and properties and     * displays the usage screen if the CommandLine 
 is not valid or the help     * option was specified.     *     * @param arguments the command line arguments     * @return a valid CommandLine or null if the parse was unsuccessful     * @throws IOException if an error occurs while formatting help     */    public CommandLine parseAndHelp(final String[] arguments) {        helpFormatter.setGroup(group);        try {            // attempt to parse the command line            final CommandLine commandLine = parse(arguments);            if (!commandLine.hasOption(helpOption) && !commandLine.hasOption(helpTrigger)) {                return commandLine;            }        } catch (final OptionException oe) {            // display help regarding the exception            helpFormatter.setException(oe);        }        // print help        helpFormatter.print();        return null;    }    /**     * Sets the Group of options to parse against     * @param group the group of options to parse against     */    public void setGroup(fina
 l Group group) {        this.group = group;    }    /**     * Sets the HelpFormatter to use with the simplified parsing.     * @see #parseAndHelp(String[])     * @param helpFormatter the HelpFormatter to use with the simplified parsing     */    public void setHelpFormatter(final HelpFormatter helpFormatter) {        this.helpFormatter = helpFormatter;    }    /**     * Sets the help option to use with the simplified parsing.  For example     * <code>--help</code>, <code>-h</code> and <code>-?</code> are often used.     * @see #parseAndHelp(String[])     * @param helpOption the help Option     */    public void setHelpOption(final Option helpOption) {        this.helpOption = helpOption;    }    /**     * Sets the help option to use with the simplified parsing.  For example     * <code>--help</code>, <code>-h</code> and <code>-?</code> are often used.     * @see #parseAndHelp(String[])     * @param helpTrigger the trigger of the help Option     */    public void setHelpTrigg
 er(final String helpTrigger) {        this.helpTrigger = helpTrigger;    }}
\ No newline at end of file

Modified: commons/proper/cli/trunk/src/java/org/apache/commons/cli2/commandline/PreferencesCommandLine.java
URL: http://svn.apache.org/viewvc/commons/proper/cli/trunk/src/java/org/apache/commons/cli2/commandline/PreferencesCommandLine.java?rev=639941&r1=639940&r2=639941&view=diff
==============================================================================
--- commons/proper/cli/trunk/src/java/org/apache/commons/cli2/commandline/PreferencesCommandLine.java (original)
+++ commons/proper/cli/trunk/src/java/org/apache/commons/cli2/commandline/PreferencesCommandLine.java Fri Mar 21 19:49:41 2008
@@ -1,170 +1 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.commons.cli2.commandline;
-
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collections;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Set;
-import java.util.StringTokenizer;
-import java.util.prefs.BackingStoreException;
-import java.util.prefs.Preferences;
-
-import org.apache.commons.cli2.Option;
-
-/**
- * A CommandLine implementation using the Preferences API, useful when
- * constructing a complex DefaultingCommandLine
- *
- * This implementation uses the children of a single preference node to populate
- * the CommandLine.  Options are keyed from their preferred name and presence in
- * the Preferences object is taken as presence in the CommandLine.  Argument
- * values are taken from the Preference value and are optionally separated using
- * the separator char defined, at construction time.  Switch values can be
- * specified using a simple value of <code>true</code> or <code>false</code>;
- * obviously this means that Switches with Arguments are not supported by this
- * implementation.
- *
- * @see java.util.prefs.Preferences
- * @see org.apache.commons.cli2.commandline.DefaultingCommandLine
- * @see org.apache.commons.cli2.Option#getPreferredName() 
- */
-public class PreferencesCommandLine extends CommandLineImpl {
-	
-	private static final char NUL = '\0';
-	private final Preferences preferences;
-	private final Option root;
-	private final char separator;
-	
-	/**
-     * Creates a new PreferencesCommandLine using the specified root Option and
-     * Preferences node.  Argument values will be separated using the char 0.
-     * 
-	 * @param root the CommandLine's root Option
-	 * @param preferences the Preferences node to get values from
-	 */
-	public PreferencesCommandLine(final Option root, final Preferences preferences){
-		this(root,preferences,NUL);
-	}
-	
-    /**
-     * Creates a new PreferencesCommandLine using the specified root Option,
-     * Preferences node and value separator.
-     * 
-     * @param root the CommandLine's root Option
-     * @param preferences the Preferences node to get values from
-     * @param separator the character to split argument values
-     */
-	public PreferencesCommandLine(final Option root, final Preferences preferences, final char separator){
-		this.root = root;
-		this.preferences = preferences;
-		this.separator = separator;
-	}
-	
-	public boolean hasOption(Option option) {
-		if(option==null){
-			return false;
-		}
-		else{
-			try {
-				return Arrays.asList(preferences.keys()).contains(option.getPreferredName());
-			} catch (BackingStoreException e) {
-				return false;
-			}
-		}
-	}
-
-	public Option getOption(String trigger) {
-		return root.findOption(trigger);
-	}
-
-	public List getValues(final Option option, final List defaultValues) {
-		final String value = preferences.get(option.getPreferredName(),null);
-		
-		if(value==null){
-			return defaultValues;
-		}
-		else if(separator>NUL){
-			final List values = new ArrayList();
-			final StringTokenizer tokens = new StringTokenizer(value,String.valueOf(separator));
-			
-			while(tokens.hasMoreTokens()){
-				values.add(tokens.nextToken());
-			}
-			
-			return values;
-		}
-		else{
-			return Collections.singletonList(value);
-		}
-	}
-
-	public Boolean getSwitch(final Option option, final Boolean defaultValue) {
-		final String value = preferences.get(option.getPreferredName(),null);
-		if("true".equals(value)){
-			return Boolean.TRUE;
-		}
-		else if("false".equals(value)){
-			return Boolean.FALSE;
-		}
-		else{
-			return defaultValue;
-		}
-	}
-	
-	public String getProperty(final String property, final String defaultValue) {
-		return preferences.get(property, defaultValue);
-	}
-
-	public Set getProperties() {
-		try {
-			return new HashSet(Arrays.asList(preferences.keys()));
-		} catch (BackingStoreException e) {
-			return Collections.EMPTY_SET;
-		}
-	}
-
-	public List getOptions() {
-		try {
-			final List options = new ArrayList();
-			final Iterator keys = Arrays.asList(preferences.keys()).iterator();
-			while (keys.hasNext()) {
-				final String trigger = (String) keys.next();
-				final Option option = root.findOption(trigger);
-				if (option != null) {
-					options.add(option);
-				}
-			}
-			return Collections.unmodifiableList(options);
-		} catch (BackingStoreException e) {
-			return Collections.EMPTY_LIST;
-		}
-	}
-
-	public Set getOptionTriggers() {
-		final Set triggers = new HashSet();
-		final Iterator options = getOptions().iterator();
-		while(options.hasNext()){
-			final Option option = (Option)options.next();
-			triggers.addAll(option.getTriggers());
-		}
-		return Collections.unmodifiableSet(triggers);
-	}
-}
+/** * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements.  See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License.  You may obtain a copy of the License at * *     http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */package org.apache.commons.cli2.commandline;import java.util.ArrayList;import java.util.Arrays;import java.util.Collections;import java.util.HashSet;import java.util.Iterator;import java.util.List;impor
 t java.util.Set;import java.util.StringTokenizer;import java.util.prefs.BackingStoreException;import java.util.prefs.Preferences;import org.apache.commons.cli2.Option;/** * A CommandLine implementation using the Preferences API, useful when * constructing a complex DefaultingCommandLine * * This implementation uses the children of a single preference node to populate * the CommandLine.  Options are keyed from their preferred name and presence in * the Preferences object is taken as presence in the CommandLine.  Argument * values are taken from the Preference value and are optionally separated using * the separator char defined, at construction time.  Switch values can be * specified using a simple value of <code>true</code> or <code>false</code>; * obviously this means that Switches with Arguments are not supported by this * implementation. * * @see java.util.prefs.Preferences * @see org.apache.commons.cli2.commandline.DefaultingCommandLine * @see org.apache.commons.cli2.Opt
 ion#getPreferredName() */public class PreferencesCommandLine extends CommandLineImpl {	private static final char NUL = '\0';	private final Preferences preferences;	private final Option root;	private final char separator;	/**     * Creates a new PreferencesCommandLine using the specified root Option and     * Preferences node.  Argument values will be separated using the char 0.     *	 * @param root the CommandLine's root Option	 * @param preferences the Preferences node to get values from	 */	public PreferencesCommandLine(final Option root, final Preferences preferences){		this(root,preferences,NUL);	}    /**     * Creates a new PreferencesCommandLine using the specified root Option,     * Preferences node and value separator.     *     * @param root the CommandLine's root Option     * @param preferences the Preferences node to get values from     * @param separator the character to split argument values     */	public PreferencesCommandLine(final Option root, final Preferenc
 es preferences, final char separator){		this.root = root;		this.preferences = preferences;		this.separator = separator;	}	public boolean hasOption(Option option) {		if(option==null){			return false;		}		else{			try {				return Arrays.asList(preferences.keys()).contains(option.getPreferredName());			} catch (BackingStoreException e) {				return false;			}		}	}	public Option getOption(String trigger) {		return root.findOption(trigger);	}	public List getValues(final Option option, final List defaultValues) {		final String value = preferences.get(option.getPreferredName(),null);		if(value==null){			return defaultValues;		}		else if(separator>NUL){			final List values = new ArrayList();			final StringTokenizer tokens = new StringTokenizer(value,String.valueOf(separator));			while(tokens.hasMoreTokens()){				values.add(tokens.nextToken());			}			return values;		}		else{			return Collections.singletonList(value);		}	}	public Boolean getSwitch(final Option option, final Boolean defa
 ultValue) {		final String value = preferences.get(option.getPreferredName(),null);		if("true".equals(value)){			return Boolean.TRUE;		}		else if("false".equals(value)){			return Boolean.FALSE;		}		else{			return defaultValue;		}	}	public String getProperty(final String property, final String defaultValue) {		return preferences.get(property, defaultValue);	}	public Set getProperties() {		try {			return new HashSet(Arrays.asList(preferences.keys()));		} catch (BackingStoreException e) {			return Collections.EMPTY_SET;		}	}	public List getOptions() {		try {			final List options = new ArrayList();			final Iterator keys = Arrays.asList(preferences.keys()).iterator();			while (keys.hasNext()) {				final String trigger = (String) keys.next();				final Option option = root.findOption(trigger);				if (option != null) {					options.add(option);				}			}			return Collections.unmodifiableList(options);		} catch (BackingStoreException e) {			return Collections.EMPTY_LIST;		}	}	public Set
  getOptionTriggers() {		final Set triggers = new HashSet();		final Iterator options = getOptions().iterator();		while(options.hasNext()){			final Option option = (Option)options.next();			triggers.addAll(option.getTriggers());		}		return Collections.unmodifiableSet(triggers);	}}
\ No newline at end of file

Modified: commons/proper/cli/trunk/src/java/org/apache/commons/cli2/commandline/PropertiesCommandLine.java
URL: http://svn.apache.org/viewvc/commons/proper/cli/trunk/src/java/org/apache/commons/cli2/commandline/PropertiesCommandLine.java?rev=639941&r1=639940&r2=639941&view=diff
==============================================================================
--- commons/proper/cli/trunk/src/java/org/apache/commons/cli2/commandline/PropertiesCommandLine.java (original)
+++ commons/proper/cli/trunk/src/java/org/apache/commons/cli2/commandline/PropertiesCommandLine.java Fri Mar 21 19:49:41 2008
@@ -1,155 +1 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.commons.cli2.commandline;
-
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Properties;
-import java.util.Set;
-import java.util.StringTokenizer;
-
-import org.apache.commons.cli2.Option;
-
-/**
- * A CommandLine implementation using a java Properties instance, useful for
- * constructing a complex DefaultingCommandLine
- *
- * Options are keyed from their property name and presence in the Properties
- * instance is taken as presence in the CommandLine.  Argument values are taken
- * from the property value and are optionally separated using the separator
- * char, defined at construction time.  Switch values can be specified using a
- * simple value of <code>true</code> or <code>false</code>; obviously this means
- * that Switches with Arguments are not supported by this implementation.
- *
- * @see java.util.Properties
- * @see org.apache.commons.cli2.commandline.DefaultingCommandLine
- * @see org.apache.commons.cli2.Option#getPreferredName() 
- */
-public class PropertiesCommandLine extends CommandLineImpl {
-	
-	private static final char NUL = '\0';
-	private final Properties properties;
-	private final Option root;
-	private final char separator;
-	
-    /**
-     * Creates a new PropertiesCommandLine using the specified root Option,
-     * Properties instance.  The character 0 is used as the value separator.
-     *
-     * @param root the CommandLine's root Option
-     * @param properties the Properties instance to get values from
-     */
-	public PropertiesCommandLine(final Option root, final Properties properties){
-		this(root,properties,NUL);
-	}
-	
-    /**
-     * Creates a new PropertiesCommandLine using the specified root Option,
-     * Properties instance and value separator.
-     *
-     * @param root the CommandLine's root Option
-     * @param properties the Properties instance to get values from
-     * @param separator the character to split argument values
-     */
-	public PropertiesCommandLine(final Option root, final Properties properties, final char separator){
-		this.root = root;
-		this.properties = properties;
-		this.separator = separator;
-	}
-	
-
-	public boolean hasOption(Option option) {
-		if(option==null){
-			return false;
-		}
-		else{
-			return properties.containsKey(option.getPreferredName());
-		}
-	}
-
-	public Option getOption(String trigger) {
-		return root.findOption(trigger);
-	}
-
-	public List getValues(final Option option, final List defaultValues) {
-		final String value = properties.getProperty(option.getPreferredName());
-		
-		if(value==null){
-			return defaultValues;
-		}
-		else if(separator>NUL){
-			final List values = new ArrayList();
-			final StringTokenizer tokens = new StringTokenizer(value,String.valueOf(separator));
-			
-			while(tokens.hasMoreTokens()){
-				values.add(tokens.nextToken());
-			}
-			
-			return values;
-		}
-		else{
-			return Collections.singletonList(value);
-		}
-	}
-
-	public Boolean getSwitch(final Option option, final Boolean defaultValue) {
-		final String value = properties.getProperty(option.getPreferredName());
-		if("true".equals(value)){
-			return Boolean.TRUE;
-		}
-		else if("false".equals(value)){
-			return Boolean.FALSE;
-		}
-		else{
-			return defaultValue;
-		}
-	}
-	
-	public String getProperty(final String property, final String defaultValue) {
-		return properties.getProperty(property,defaultValue);
-	}
-
-	public Set getProperties() {
-		return properties.keySet();
-	}
-
-	public List getOptions() {
-		final List options = new ArrayList();
-		final Iterator keys = properties.keySet().iterator();
-		while(keys.hasNext()){
-			final String trigger = (String)keys.next();
-			final Option option = root.findOption(trigger);
-			if(option!=null){
-				options.add(option);
-			}
-		}
-		return Collections.unmodifiableList(options);
-	}
-
-	public Set getOptionTriggers() {
-		final Set triggers = new HashSet();
-		final Iterator options = getOptions().iterator();
-		while(options.hasNext()){
-			final Option option = (Option)options.next();
-			triggers.addAll(option.getTriggers());
-		}
-		return Collections.unmodifiableSet(triggers);
-	}
-}
+/** * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements.  See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License.  You may obtain a copy of the License at * *     http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */package org.apache.commons.cli2.commandline;import java.util.ArrayList;import java.util.Collections;import java.util.HashSet;import java.util.Iterator;import java.util.List;import java.util.Properties;i
 mport java.util.Set;import java.util.StringTokenizer;import org.apache.commons.cli2.Option;/** * A CommandLine implementation using a java Properties instance, useful for * constructing a complex DefaultingCommandLine * * Options are keyed from their property name and presence in the Properties * instance is taken as presence in the CommandLine.  Argument values are taken * from the property value and are optionally separated using the separator * char, defined at construction time.  Switch values can be specified using a * simple value of <code>true</code> or <code>false</code>; obviously this means * that Switches with Arguments are not supported by this implementation. * * @see java.util.Properties * @see org.apache.commons.cli2.commandline.DefaultingCommandLine * @see org.apache.commons.cli2.Option#getPreferredName() */public class PropertiesCommandLine extends CommandLineImpl {	private static final char NUL = '\0';	private final Properties properties;	private final Opti
 on root;	private final char separator;    /**     * Creates a new PropertiesCommandLine using the specified root Option,     * Properties instance.  The character 0 is used as the value separator.     *     * @param root the CommandLine's root Option     * @param properties the Properties instance to get values from     */	public PropertiesCommandLine(final Option root, final Properties properties){		this(root,properties,NUL);	}    /**     * Creates a new PropertiesCommandLine using the specified root Option,     * Properties instance and value separator.     *     * @param root the CommandLine's root Option     * @param properties the Properties instance to get values from     * @param separator the character to split argument values     */	public PropertiesCommandLine(final Option root, final Properties properties, final char separator){		this.root = root;		this.properties = properties;		this.separator = separator;	}	public boolean hasOption(Option option) {		if(option==nu
 ll){			return false;		}		else{			return properties.containsKey(option.getPreferredName());		}	}	public Option getOption(String trigger) {		return root.findOption(trigger);	}	public List getValues(final Option option, final List defaultValues) {		final String value = properties.getProperty(option.getPreferredName());		if(value==null){			return defaultValues;		}		else if(separator>NUL){			final List values = new ArrayList();			final StringTokenizer tokens = new StringTokenizer(value,String.valueOf(separator));			while(tokens.hasMoreTokens()){				values.add(tokens.nextToken());			}			return values;		}		else{			return Collections.singletonList(value);		}	}	public Boolean getSwitch(final Option option, final Boolean defaultValue) {		final String value = properties.getProperty(option.getPreferredName());		if("true".equals(value)){			return Boolean.TRUE;		}		else if("false".equals(value)){			return Boolean.FALSE;		}		else{			return defaultValue;		}	}	public String getProperty(final
  String property, final String defaultValue) {		return properties.getProperty(property,defaultValue);	}	public Set getProperties() {		return properties.keySet();	}	public List getOptions() {		final List options = new ArrayList();		final Iterator keys = properties.keySet().iterator();		while(keys.hasNext()){			final String trigger = (String)keys.next();			final Option option = root.findOption(trigger);			if(option!=null){				options.add(option);			}		}		return Collections.unmodifiableList(options);	}	public Set getOptionTriggers() {		final Set triggers = new HashSet();		final Iterator options = getOptions().iterator();		while(options.hasNext()){			final Option option = (Option)options.next();			triggers.addAll(option.getTriggers());		}		return Collections.unmodifiableSet(triggers);	}}
\ No newline at end of file

Modified: commons/proper/cli/trunk/src/java/org/apache/commons/cli2/commandline/WriteableCommandLineImpl.java
URL: http://svn.apache.org/viewvc/commons/proper/cli/trunk/src/java/org/apache/commons/cli2/commandline/WriteableCommandLineImpl.java?rev=639941&r1=639940&r2=639941&view=diff
==============================================================================
--- commons/proper/cli/trunk/src/java/org/apache/commons/cli2/commandline/WriteableCommandLineImpl.java (original)
+++ commons/proper/cli/trunk/src/java/org/apache/commons/cli2/commandline/WriteableCommandLineImpl.java Fri Mar 21 19:49:41 2008
@@ -1,226 +1 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.commons.cli2.commandline;
-
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-import java.util.Properties;
-import java.util.Set;
-
-import org.apache.commons.cli2.Argument;
-import org.apache.commons.cli2.Option;
-import org.apache.commons.cli2.WriteableCommandLine;
-import org.apache.commons.cli2.resource.ResourceConstants;
-import org.apache.commons.cli2.resource.ResourceHelper;
-
-/**
- * A WriteableCommandLine implementation allowing Options to write their
- * processed information to a CommandLine.
- */
-public class WriteableCommandLineImpl
-    extends CommandLineImpl implements WriteableCommandLine {
-    private final Properties properties = new Properties();
-    private final List options = new ArrayList();
-    private final Map nameToOption = new HashMap();
-    private final Map values = new HashMap();
-    private final Map switches = new HashMap();
-    private final Map defaultValues = new HashMap();
-    private final Map defaultSwitches = new HashMap();
-    private final List normalised;
-    private final Set prefixes;
-
-    /**
-     * Creates a new WriteableCommandLineImpl rooted on the specified Option, to
-     * hold the parsed arguments.
-     *
-     * @param rootOption the CommandLine's root Option
-     * @param arguments the arguments this CommandLine represents
-     */
-    public WriteableCommandLineImpl(final Option rootOption,
-                                    final List arguments) {
-        this.prefixes = rootOption.getPrefixes();
-        this.normalised = arguments;
-    }
-
-    public void addOption(Option option) {
-        options.add(option);
-        nameToOption.put(option.getPreferredName(), option);
-
-        for (Iterator i = option.getTriggers().iterator(); i.hasNext();) {
-            nameToOption.put(i.next(), option);
-        }
-    }
-
-    public void addValue(final Option option,
-                         final Object value) {
-        if (option instanceof Argument) {
-            addOption(option);
-        }
-
-        List valueList = (List) values.get(option);
-
-        if (valueList == null) {
-            valueList = new ArrayList();
-            values.put(option, valueList);
-        }
-
-        valueList.add(value);
-    }
-
-    public void addSwitch(final Option option,
-                          final boolean value) {
-        addOption(option);
-
-        if (switches.containsKey(option)) {
-            throw new IllegalStateException(ResourceHelper.getResourceHelper().getMessage(ResourceConstants.SWITCH_ALREADY_SET));
-        } else {
-            switches.put(option, value ? Boolean.TRUE : Boolean.FALSE);
-        }
-    }
-
-    public boolean hasOption(final Option option) {
-        final boolean present = options.contains(option);
-
-        return present;
-    }
-
-    public Option getOption(final String trigger) {
-        return (Option) nameToOption.get(trigger);
-    }
-
-    public List getValues(final Option option,
-                          final List defaultValues) {
-        // First grab the command line values
-        List valueList = (List) values.get(option);
-
-        // Secondly try the defaults supplied to the method
-        if ((valueList == null) || valueList.isEmpty()) {
-            valueList = defaultValues;
-        }
-
-        // Thirdly try the option's default values
-        if ((valueList == null) || valueList.isEmpty()) {
-            valueList = (List) this.defaultValues.get(option);
-        }
-
-        // Finally use an empty list
-        if (valueList == null) {
-            valueList = Collections.EMPTY_LIST;
-        }
-
-        return valueList;
-    }
-
-    public Boolean getSwitch(final Option option,
-                             final Boolean defaultValue) {
-        // First grab the command line values
-        Boolean bool = (Boolean) switches.get(option);
-
-        // Secondly try the defaults supplied to the method
-        if (bool == null) {
-            bool = defaultValue;
-        }
-
-        // Thirdly try the option's default values
-        if (bool == null) {
-            bool = (Boolean) this.defaultSwitches.get(option);
-        }
-
-        return bool;
-    }
-
-    public void addProperty(final String property,
-                            final String value) {
-        properties.setProperty(property, value);
-    }
-
-    public String getProperty(final String property,
-                              final String defaultValue) {
-        return properties.getProperty(property, defaultValue);
-    }
-
-    public Set getProperties() {
-        return Collections.unmodifiableSet(properties.keySet());
-    }
-
-    public boolean looksLikeOption(final String trigger) {
-        for (final Iterator i = prefixes.iterator(); i.hasNext();) {
-            final String prefix = (String) i.next();
-
-            if (trigger.startsWith(prefix)) {
-                return true;
-            }
-        }
-
-        return false;
-    }
-
-    public String toString() {
-        final StringBuffer buffer = new StringBuffer();
-
-        // need to add group header
-        for (final Iterator i = normalised.iterator(); i.hasNext();) {
-            final String arg = (String) i.next();
-
-            if (arg.indexOf(' ') >= 0) {
-                buffer.append("\"").append(arg).append("\"");
-            } else {
-                buffer.append(arg);
-            }
-
-            if (i.hasNext()) {
-                buffer.append(' ');
-            }
-        }
-
-        return buffer.toString();
-    }
-
-    public List getOptions() {
-        return Collections.unmodifiableList(options);
-    }
-
-    public Set getOptionTriggers() {
-        return Collections.unmodifiableSet(nameToOption.keySet());
-    }
-
-    public void setDefaultValues(final Option option,
-                                 final List defaults) {
-        if (defaults == null) {
-            defaultValues.remove(option);
-        } else {
-            defaultValues.put(option, defaults);
-        }
-    }
-
-    public void setDefaultSwitch(final Option option,
-                                 final Boolean defaultSwitch) {
-        if (defaultSwitch == null) {
-            defaultSwitches.remove(option);
-        } else {
-            defaultSwitches.put(option, defaultSwitch);
-        }
-    }
-
-    public List getNormalised() {
-        return Collections.unmodifiableList(normalised);
-    }
-}
+/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements.  See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License.  You may obtain a copy of the License at * *     http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */package org.apache.commons.cli2.commandline;import java.util.ArrayList;import java.util.Collections;import java.util.HashMap;import java.util.Iterator;import java.util.List;import java.util.Map;import ja
 va.util.Properties;import java.util.Set;import org.apache.commons.cli2.Argument;import org.apache.commons.cli2.Option;import org.apache.commons.cli2.WriteableCommandLine;import org.apache.commons.cli2.resource.ResourceConstants;import org.apache.commons.cli2.resource.ResourceHelper;/** * A WriteableCommandLine implementation allowing Options to write their * processed information to a CommandLine. */public class WriteableCommandLineImpl    extends CommandLineImpl implements WriteableCommandLine {    private final Properties properties = new Properties();    private final List options = new ArrayList();    private final Map nameToOption = new HashMap();    private final Map values = new HashMap();    private final Map switches = new HashMap();    private final Map defaultValues = new HashMap();    private final Map defaultSwitches = new HashMap();    private final List normalised;    private final Set prefixes;    /**     * Creates a new WriteableCommandLineImpl rooted on the
  specified Option, to     * hold the parsed arguments.     *     * @param rootOption the CommandLine's root Option     * @param arguments the arguments this CommandLine represents     */    public WriteableCommandLineImpl(final Option rootOption,                                    final List arguments) {        this.prefixes = rootOption.getPrefixes();        this.normalised = arguments;    }    public void addOption(Option option) {        options.add(option);        nameToOption.put(option.getPreferredName(), option);        for (Iterator i = option.getTriggers().iterator(); i.hasNext();) {            nameToOption.put(i.next(), option);        }    }    public void addValue(final Option option,                         final Object value) {        if (option instanceof Argument) {            addOption(option);        }        List valueList = (List) values.get(option);        if (valueList == null) {            valueList = new ArrayList();            values.put(option, valu
 eList);        }        valueList.add(value);    }    public void addSwitch(final Option option,                          final boolean value) {        addOption(option);        if (switches.containsKey(option)) {            throw new IllegalStateException(ResourceHelper.getResourceHelper().getMessage(ResourceConstants.SWITCH_ALREADY_SET));        } else {            switches.put(option, value ? Boolean.TRUE : Boolean.FALSE);        }    }    public boolean hasOption(final Option option) {        final boolean present = options.contains(option);        return present;    }    public Option getOption(final String trigger) {        return (Option) nameToOption.get(trigger);    }    public List getValues(final Option option,                          final List defaultValues) {        // First grab the command line values        List valueList = (List) values.get(option);        // Secondly try the defaults supplied to the method        if ((valueList == null) || valueList.isEmp
 ty()) {            valueList = defaultValues;        }        // Thirdly try the option's default values        if ((valueList == null) || valueList.isEmpty()) {            valueList = (List) this.defaultValues.get(option);        }        // Finally use an empty list        if (valueList == null) {            valueList = Collections.EMPTY_LIST;        }        return valueList;    }    public Boolean getSwitch(final Option option,                             final Boolean defaultValue) {        // First grab the command line values        Boolean bool = (Boolean) switches.get(option);        // Secondly try the defaults supplied to the method        if (bool == null) {            bool = defaultValue;        }        // Thirdly try the option's default values        if (bool == null) {            bool = (Boolean) this.defaultSwitches.get(option);        }        return bool;    }    public void addProperty(final String property,                            final String value)
  {        properties.setProperty(property, value);    }    public String getProperty(final String property,                              final String defaultValue) {        return properties.getProperty(property, defaultValue);    }    public Set getProperties() {        return Collections.unmodifiableSet(properties.keySet());    }    public boolean looksLikeOption(final String trigger) {        for (final Iterator i = prefixes.iterator(); i.hasNext();) {            final String prefix = (String) i.next();            if (trigger.startsWith(prefix)) {                return true;            }        }        return false;    }    public String toString() {        final StringBuffer buffer = new StringBuffer();        // need to add group header        for (final Iterator i = normalised.iterator(); i.hasNext();) {            final String arg = (String) i.next();            if (arg.indexOf(' ') >= 0) {                buffer.append("\"").append(arg).append("\"");            } els
 e {                buffer.append(arg);            }            if (i.hasNext()) {                buffer.append(' ');            }        }        return buffer.toString();    }    public List getOptions() {        return Collections.unmodifiableList(options);    }    public Set getOptionTriggers() {        return Collections.unmodifiableSet(nameToOption.keySet());    }    public void setDefaultValues(final Option option,                                 final List defaults) {        if (defaults == null) {            defaultValues.remove(option);        } else {            defaultValues.put(option, defaults);        }    }    public void setDefaultSwitch(final Option option,                                 final Boolean defaultSwitch) {        if (defaultSwitch == null) {            defaultSwitches.remove(option);        } else {            defaultSwitches.put(option, defaultSwitch);        }    }    public List getNormalised() {        return Collections.unmodifiableList(nor
 malised);    }}
\ No newline at end of file

Modified: commons/proper/cli/trunk/src/java/org/apache/commons/cli2/option/ArgumentImpl.java
URL: http://svn.apache.org/viewvc/commons/proper/cli/trunk/src/java/org/apache/commons/cli2/option/ArgumentImpl.java?rev=639941&r1=639940&r2=639941&view=diff
==============================================================================
--- commons/proper/cli/trunk/src/java/org/apache/commons/cli2/option/ArgumentImpl.java (original)
+++ commons/proper/cli/trunk/src/java/org/apache/commons/cli2/option/ArgumentImpl.java Fri Mar 21 19:49:41 2008
@@ -1,374 +1 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.commons.cli2.option;
-
-import java.util.Collections;
-import java.util.Comparator;
-import java.util.List;
-import java.util.ListIterator;
-import java.util.Set;
-import java.util.StringTokenizer;
-
-import org.apache.commons.cli2.Argument;
-import org.apache.commons.cli2.DisplaySetting;
-import org.apache.commons.cli2.HelpLine;
-import org.apache.commons.cli2.Option;
-import org.apache.commons.cli2.OptionException;
-import org.apache.commons.cli2.WriteableCommandLine;
-import org.apache.commons.cli2.resource.ResourceConstants;
-import org.apache.commons.cli2.resource.ResourceHelper;
-import org.apache.commons.cli2.validation.InvalidArgumentException;
-import org.apache.commons.cli2.validation.Validator;
-
-/**
- * An implementation of an Argument.
- */
-public class ArgumentImpl
-    extends OptionImpl implements Argument {
-    private static final char NUL = '\0';
-
-    /**
-     * The default value for the initial separator char.
-     */
-    public static final char DEFAULT_INITIAL_SEPARATOR = NUL;
-
-    /**
-     * The default value for the subsequent separator char.
-     */
-    public static final char DEFAULT_SUBSEQUENT_SEPARATOR = NUL;
-
-    /**
-     * The default token to indicate that remaining arguments should be consumed
-     * as values.
-     */
-    public static final String DEFAULT_CONSUME_REMAINING = "--";
-    private final String name;
-    private final String description;
-    private final int minimum;
-    private final int maximum;
-    private final char initialSeparator;
-    private final char subsequentSeparator;
-    private final boolean subsequentSplit;
-    private final Validator validator;
-    private final String consumeRemaining;
-    private final List defaultValues;
-    private final ResourceHelper resources = ResourceHelper.getResourceHelper();
-
-    /**
-     * Creates a new Argument instance.
-     *
-     * @param name
-     *            The name of the argument
-     * @param description
-     *            A description of the argument
-     * @param minimum
-     *            The minimum number of values needed to be valid
-     * @param maximum
-     *            The maximum number of values allowed to be valid
-     * @param initialSeparator
-     *            The char separating option from value
-     * @param subsequentSeparator
-     *            The char separating values from each other
-     * @param validator
-     *            The object responsible for validating the values
-     * @param consumeRemaining
-     *            The String used for the "consuming option" group
-     * @param valueDefaults
-     *            The values to be used if none are specified.
-     * @param id
-     *            The id of the option, 0 implies automatic assignment.
-     *
-     * @see OptionImpl#OptionImpl(int,boolean)
-     */
-    public ArgumentImpl(final String name,
-                        final String description,
-                        final int minimum,
-                        final int maximum,
-                        final char initialSeparator,
-                        final char subsequentSeparator,
-                        final Validator validator,
-                        final String consumeRemaining,
-                        final List valueDefaults,
-                        final int id) {
-        super(id, false);
-
-        this.name = (name == null) ? "arg" : name;
-        this.description = description;
-        this.minimum = minimum;
-        this.maximum = maximum;
-        this.initialSeparator = initialSeparator;
-        this.subsequentSeparator = subsequentSeparator;
-        this.subsequentSplit = subsequentSeparator != NUL;
-        this.validator = validator;
-        this.consumeRemaining = consumeRemaining;
-        this.defaultValues = valueDefaults;
-
-        if (minimum > maximum) {
-            throw new IllegalArgumentException(resources.getMessage(ResourceConstants.ARGUMENT_MIN_EXCEEDS_MAX));
-        }
-
-        if ((valueDefaults != null) && (valueDefaults.size() > 0)) {
-            if (valueDefaults.size() < minimum) {
-                throw new IllegalArgumentException(resources.getMessage(ResourceConstants.ARGUMENT_TOO_FEW_DEFAULTS));
-            }
-
-            if (valueDefaults.size() > maximum) {
-                throw new IllegalArgumentException(resources.getMessage(ResourceConstants.ARGUMENT_TOO_MANY_DEFAULTS));
-            }
-        }
-    }
-
-    public String getPreferredName() {
-        return name;
-    }
-
-    public void processValues(final WriteableCommandLine commandLine,
-                              final ListIterator arguments,
-                              final Option option)
-        throws OptionException {
-        int argumentCount = commandLine.getValues(option, Collections.EMPTY_LIST).size();
-
-        while (arguments.hasNext() && (argumentCount < maximum)) {
-            final String allValuesQuoted = (String) arguments.next();
-            final String allValues = stripBoundaryQuotes(allValuesQuoted);
-
-            // should we ignore things that look like options?
-            if (allValuesQuoted.equals(consumeRemaining)) {
-                while (arguments.hasNext() && (argumentCount < maximum)) {
-                    ++argumentCount;
-                    commandLine.addValue(option, arguments.next());
-                }
-            }
-            // does it look like an option?
-            else if (commandLine.looksLikeOption(allValuesQuoted)) {
-                arguments.previous();
-
-                break;
-            }
-            // should we split the string up?
-            else if (subsequentSplit) {
-                final StringTokenizer values =
-                    new StringTokenizer(allValues, String.valueOf(subsequentSeparator));
-
-                arguments.remove();
-
-                while (values.hasMoreTokens() && (argumentCount < maximum)) {
-                    ++argumentCount;
-
-                    final String token = values.nextToken();
-                    commandLine.addValue(option, token);
-                    arguments.add(token);
-                }
-
-                if (values.hasMoreTokens()) {
-                    throw new OptionException(option, ResourceConstants.ARGUMENT_UNEXPECTED_VALUE,
-                                              values.nextToken());
-                }
-            }
-            // it must be a value as it is
-            else {
-                ++argumentCount;
-                commandLine.addValue(option, allValues);
-            }
-        }
-    }
-
-    public boolean canProcess(final WriteableCommandLine commandLine,
-                              final String arg) {
-        return true;
-    }
-
-    public Set getPrefixes() {
-        return Collections.EMPTY_SET;
-    }
-
-    public void process(WriteableCommandLine commandLine,
-                        ListIterator args)
-        throws OptionException {
-        processValues(commandLine, args, this);
-    }
-
-    public char getInitialSeparator() {
-        return this.initialSeparator;
-    }
-
-    public char getSubsequentSeparator() {
-        return this.subsequentSeparator;
-    }
-
-    public Set getTriggers() {
-        return Collections.EMPTY_SET;
-    }
-
-    public String getConsumeRemaining() {
-    	return this.consumeRemaining;
-    }
-    
-    public List getDefaultValues() {
-    	return this.defaultValues;
-    }
-    
-    public Validator getValidator() {
-    	return this.validator;
-    }
-    
-    public void validate(final WriteableCommandLine commandLine)
-        throws OptionException {
-        validate(commandLine, this);
-    }
-
-    public void validate(final WriteableCommandLine commandLine,
-                         final Option option)
-        throws OptionException {
-        final List values = commandLine.getValues(option);
-
-        if (values.size() < minimum) {
-            throw new OptionException(option, ResourceConstants.ARGUMENT_MISSING_VALUES);
-        }
-
-        if (values.size() > maximum) {
-            throw new OptionException(option, ResourceConstants.ARGUMENT_UNEXPECTED_VALUE,
-                                      (String) values.get(maximum));
-        }
-
-        if (validator != null) {
-            try {
-                validator.validate(values);
-            } catch (InvalidArgumentException ive) {
-                throw new OptionException(option, ResourceConstants.ARGUMENT_UNEXPECTED_VALUE,
-                                          ive.getMessage());
-            }
-        }
-    }
-
-    public void appendUsage(final StringBuffer buffer,
-                            final Set helpSettings,
-                            final Comparator comp) {
-        // do we display the outer optionality
-        final boolean optional = helpSettings.contains(DisplaySetting.DISPLAY_OPTIONAL);
-
-        // allow numbering if multiple args
-        final boolean numbered =
-            (maximum > 1) && helpSettings.contains(DisplaySetting.DISPLAY_ARGUMENT_NUMBERED);
-
-        final boolean bracketed = helpSettings.contains(DisplaySetting.DISPLAY_ARGUMENT_BRACKETED);
-
-        // if infinite args are allowed then crop the list
-        final int max = (maximum == Integer.MAX_VALUE) ? 2 : maximum;
-
-        int i = 0;
-
-        // for each argument
-        while (i < max) {
-            // if we're past the first add a space
-            if (i > 0) {
-                buffer.append(' ');
-            }
-
-            // if the next arg is optional
-            if ((i >= minimum) && (optional || (i > 0))) {
-                buffer.append('[');
-            }
-
-            if (bracketed) {
-                buffer.append('<');
-            }
-
-            // add name
-            buffer.append(name);
-            ++i;
-
-            // if numbering
-            if (numbered) {
-                buffer.append(i);
-            }
-
-            if (bracketed) {
-                buffer.append('>');
-            }
-        }
-
-        // if infinite args are allowed
-        if (maximum == Integer.MAX_VALUE) {
-            // append elipsis
-            buffer.append(" ...");
-        }
-
-        // for each argument
-        while (i > 0) {
-            --i;
-
-            // if the next arg is optional
-            if ((i >= minimum) && (optional || (i > 0))) {
-                buffer.append(']');
-            }
-        }
-    }
-
-    public String getDescription() {
-        return description;
-    }
-
-    public List helpLines(final int depth,
-                          final Set helpSettings,
-                          final Comparator comp) {
-        final HelpLine helpLine = new HelpLineImpl(this, depth);
-
-        return Collections.singletonList(helpLine);
-    }
-
-    public int getMaximum() {
-        return maximum;
-    }
-
-    public int getMinimum() {
-        return minimum;
-    }
-
-    /**
-     * If there are any leading or trailing quotes remove them from the
-     * specified token.
-     *
-     * @param token
-     *            the token to strip leading and trailing quotes
-     *
-     * @return String the possibly modified token
-     */
-    public String stripBoundaryQuotes(String token) {
-        if (!token.startsWith("\"") || !token.endsWith("\"")) {
-            return token;
-        }
-
-        token = token.substring(1, token.length() - 1);
-
-        return token;
-    }
-
-    public boolean isRequired() {
-        return getMinimum() > 0;
-    }
-
-    public void defaults(final WriteableCommandLine commandLine) {
-        super.defaults(commandLine);
-        defaultValues(commandLine, this);
-    }
-
-    public void defaultValues(final WriteableCommandLine commandLine,
-                              final Option option) {
-        commandLine.setDefaultValues(option, defaultValues);
-    }
-}
+/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements.  See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License.  You may obtain a copy of the License at * *     http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */package org.apache.commons.cli2.option;import java.util.Collections;import java.util.Comparator;import java.util.List;import java.util.ListIterator;import java.util.Set;import java.util.StringTokenizer;i
 mport org.apache.commons.cli2.Argument;import org.apache.commons.cli2.DisplaySetting;import org.apache.commons.cli2.HelpLine;import org.apache.commons.cli2.Option;import org.apache.commons.cli2.OptionException;import org.apache.commons.cli2.WriteableCommandLine;import org.apache.commons.cli2.resource.ResourceConstants;import org.apache.commons.cli2.resource.ResourceHelper;import org.apache.commons.cli2.validation.InvalidArgumentException;import org.apache.commons.cli2.validation.Validator;/** * An implementation of an Argument. */public class ArgumentImpl    extends OptionImpl implements Argument {    private static final char NUL = '\0';    /**     * The default value for the initial separator char.     */    public static final char DEFAULT_INITIAL_SEPARATOR = NUL;    /**     * The default value for the subsequent separator char.     */    public static final char DEFAULT_SUBSEQUENT_SEPARATOR = NUL;    /**     * The default token to indicate that remaining arguments should
  be consumed     * as values.     */    public static final String DEFAULT_CONSUME_REMAINING = "--";    private final String name;    private final String description;    private final int minimum;    private final int maximum;    private final char initialSeparator;    private final char subsequentSeparator;    private final boolean subsequentSplit;    private final Validator validator;    private final String consumeRemaining;    private final List defaultValues;    private final ResourceHelper resources = ResourceHelper.getResourceHelper();    /**     * Creates a new Argument instance.     *     * @param name     *            The name of the argument     * @param description     *            A description of the argument     * @param minimum     *            The minimum number of values needed to be valid     * @param maximum     *            The maximum number of values allowed to be valid     * @param initialSeparator     *            The char separating option from val
 ue     * @param subsequentSeparator     *            The char separating values from each other     * @param validator     *            The object responsible for validating the values     * @param consumeRemaining     *            The String used for the "consuming option" group     * @param valueDefaults     *            The values to be used if none are specified.     * @param id     *            The id of the option, 0 implies automatic assignment.     *     * @see OptionImpl#OptionImpl(int,boolean)     */    public ArgumentImpl(final String name,                        final String description,                        final int minimum,                        final int maximum,                        final char initialSeparator,                        final char subsequentSeparator,                        final Validator validator,                        final String consumeRemaining,                        final List valueDefaults,                        final int id) {
         super(id, false);        this.name = (name == null) ? "arg" : name;        this.description = description;        this.minimum = minimum;        this.maximum = maximum;        this.initialSeparator = initialSeparator;        this.subsequentSeparator = subsequentSeparator;        this.subsequentSplit = subsequentSeparator != NUL;        this.validator = validator;        this.consumeRemaining = consumeRemaining;        this.defaultValues = valueDefaults;        if (minimum > maximum) {            throw new IllegalArgumentException(resources.getMessage(ResourceConstants.ARGUMENT_MIN_EXCEEDS_MAX));        }        if ((valueDefaults != null) && (valueDefaults.size() > 0)) {            if (valueDefaults.size() < minimum) {                throw new IllegalArgumentException(resources.getMessage(ResourceConstants.ARGUMENT_TOO_FEW_DEFAULTS));            }            if (valueDefaults.size() > maximum) {                throw new IllegalArgumentException(resources.getMessage(R
 esourceConstants.ARGUMENT_TOO_MANY_DEFAULTS));            }        }    }    public String getPreferredName() {        return name;    }    public void processValues(final WriteableCommandLine commandLine,                              final ListIterator arguments,                              final Option option)        throws OptionException {        int argumentCount = commandLine.getValues(option, Collections.EMPTY_LIST).size();        while (arguments.hasNext() && (argumentCount < maximum)) {            final String allValuesQuoted = (String) arguments.next();            final String allValues = stripBoundaryQuotes(allValuesQuoted);            // should we ignore things that look like options?            if (allValuesQuoted.equals(consumeRemaining)) {                while (arguments.hasNext() && (argumentCount < maximum)) {                    ++argumentCount;                    commandLine.addValue(option, arguments.next());                }            }            // do
 es it look like an option?            else if (commandLine.looksLikeOption(allValuesQuoted)) {                arguments.previous();                break;            }            // should we split the string up?            else if (subsequentSplit) {                final StringTokenizer values =                    new StringTokenizer(allValues, String.valueOf(subsequentSeparator));                arguments.remove();                while (values.hasMoreTokens() && (argumentCount < maximum)) {                    ++argumentCount;                    final String token = values.nextToken();                    commandLine.addValue(option, token);                    arguments.add(token);                }                if (values.hasMoreTokens()) {                    throw new OptionException(option, ResourceConstants.ARGUMENT_UNEXPECTED_VALUE,                                              values.nextToken());                }            }            // it must be a value as it is  
           else {                ++argumentCount;                commandLine.addValue(option, allValues);            }        }    }    public boolean canProcess(final WriteableCommandLine commandLine,                              final String arg) {        return true;    }    public Set getPrefixes() {        return Collections.EMPTY_SET;    }    public void process(WriteableCommandLine commandLine,                        ListIterator args)        throws OptionException {        processValues(commandLine, args, this);    }    public char getInitialSeparator() {        return this.initialSeparator;    }    public char getSubsequentSeparator() {        return this.subsequentSeparator;    }    public Set getTriggers() {        return Collections.EMPTY_SET;    }    public String getConsumeRemaining() {    	return this.consumeRemaining;    }    public List getDefaultValues() {    	return this.defaultValues;    }    public Validator getValidator() {    	return this.validator;    
 }    public void validate(final WriteableCommandLine commandLine)        throws OptionException {        validate(commandLine, this);    }    public void validate(final WriteableCommandLine commandLine,                         final Option option)        throws OptionException {        final List values = commandLine.getValues(option);        if (values.size() < minimum) {            throw new OptionException(option, ResourceConstants.ARGUMENT_MISSING_VALUES);        }        if (values.size() > maximum) {            throw new OptionException(option, ResourceConstants.ARGUMENT_UNEXPECTED_VALUE,                                      (String) values.get(maximum));        }        if (validator != null) {            try {                validator.validate(values);            } catch (InvalidArgumentException ive) {                throw new OptionException(option, ResourceConstants.ARGUMENT_UNEXPECTED_VALUE,                                          ive.getMessage());            }
         }    }    public void appendUsage(final StringBuffer buffer,                            final Set helpSettings,                            final Comparator comp) {        // do we display the outer optionality        final boolean optional = helpSettings.contains(DisplaySetting.DISPLAY_OPTIONAL);        // allow numbering if multiple args        final boolean numbered =            (maximum > 1) && helpSettings.contains(DisplaySetting.DISPLAY_ARGUMENT_NUMBERED);        final boolean bracketed = helpSettings.contains(DisplaySetting.DISPLAY_ARGUMENT_BRACKETED);        // if infinite args are allowed then crop the list        final int max = (maximum == Integer.MAX_VALUE) ? 2 : maximum;        int i = 0;        // for each argument        while (i < max) {            // if we're past the first add a space            if (i > 0) {                buffer.append(' ');            }            // if the next arg is optional            if ((i >= minimum) && (optional || (i > 0))
 ) {                buffer.append('[');            }            if (bracketed) {                buffer.append('<');            }            // add name            buffer.append(name);            ++i;            // if numbering            if (numbered) {                buffer.append(i);            }            if (bracketed) {                buffer.append('>');            }        }        // if infinite args are allowed        if (maximum == Integer.MAX_VALUE) {            // append elipsis            buffer.append(" ...");        }        // for each argument        while (i > 0) {            --i;            // if the next arg is optional            if ((i >= minimum) && (optional || (i > 0))) {                buffer.append(']');            }        }    }    public String getDescription() {        return description;    }    public List helpLines(final int depth,                          final Set helpSettings,                          final Comparator comp) {        final 
 HelpLine helpLine = new HelpLineImpl(this, depth);        return Collections.singletonList(helpLine);    }    public int getMaximum() {        return maximum;    }    public int getMinimum() {        return minimum;    }    /**     * If there are any leading or trailing quotes remove them from the     * specified token.     *     * @param token     *            the token to strip leading and trailing quotes     *     * @return String the possibly modified token     */    public String stripBoundaryQuotes(String token) {        if (!token.startsWith("\"") || !token.endsWith("\"")) {            return token;        }        token = token.substring(1, token.length() - 1);        return token;    }    public boolean isRequired() {        return getMinimum() > 0;    }    public void defaults(final WriteableCommandLine commandLine) {        super.defaults(commandLine);        defaultValues(commandLine, this);    }    public void defaultValues(final WriteableCommandLine commandLine
 ,                              final Option option) {        commandLine.setDefaultValues(option, defaultValues);    }}
\ No newline at end of file



Mime
View raw message