Commits

John Paulett  committed 6d00f02

Use JARs for external projects instead of having their source code in the project.

json JAR obtained from http://mvnrepository.com/artifact/org.json/json/20090211

  • Participants
  • Parent commits c84c2ad

Comments (0)

Files changed (95)

File Source/com/martiansoftware/jsap/.cvsignore

-examples

File Source/com/martiansoftware/jsap/CommandLineTokenizer.java

-/*
- * Copyright (c) 2002-2004, Martian Software, Inc.
- * This file is made available under the LGPL as described in the accompanying
- * LICENSE.TXT file.
- */
-
-package com.martiansoftware.jsap;
-
-import java.util.List;
-/**
- * <p>A utility class to parse a command line contained in a single String into
- * an array of argument tokens, much as the JVM (or more accurately, your
- * operating system) does before calling your programs' <code>public static
- * void main(String[] args)</code>
- * methods.</p>
- *
- * <p>This class has been developed to parse the command line in the same way
- * that MS Windows 2000 does.  Arguments containing spaces should be enclosed
- * in quotes. Quotes that should be in the argument string should be escaped
- * with a preceding backslash ('\') character.  Backslash characters that
- * should be in the argument string should also be escaped with a preceding
- * backslash character.</p>
- *
- * Whenever <code>JSAP.parse(String)</code> is called, the specified String is
- * tokenized by this class, then forwarded to <code>JSAP.parse(String[])</code>
- * for further processing.
- *
- * @author <a href="http://www.martiansoftware.com/contact.html">Marty Lamb</a>
- * @see com.martiansoftware.jsap.JSAP#parse(String)
- * @see com.martiansoftware.jsap.JSAP#parse(String[])
- */
-public class CommandLineTokenizer {
-
-    /**
-     * Hide the constructor.
-     */
-    private CommandLineTokenizer() {
-    }
-
-    /**
-     * Goofy internal utility to avoid duplicated code.  If the specified
-     * StringBuffer is not empty, its contents are appended to the resulting
-     * array (temporarily stored in the specified ArrayList).  The StringBuffer
-     * is then emptied in order to begin storing the next argument.
-     * @param resultBuffer the List temporarily storing the resulting
-     * argument array.
-     * @param buf the StringBuffer storing the current argument.
-     */
-    private static void appendToBuffer(
-        List resultBuffer,
-        StringBuffer buf) {
-        if (buf.length() > 0) {
-            resultBuffer.add(buf.toString());
-            buf.setLength(0);
-        }
-    }
-
-    /**
-     * Parses the specified command line into an array of individual arguments.
-     * Arguments containing spaces should be enclosed in quotes.
-     * Quotes that should be in the argument string should be escaped with a
-     * preceding backslash ('\') character.  Backslash characters that should
-     * be in the argument string should also be escaped with a preceding
-     * backslash character.
-     * @param commandLine the command line to parse
-     * @return an argument array representing the specified command line.
-     */
-    public static String[] tokenize(String commandLine) {
-        List resultBuffer = new java.util.ArrayList();
-
-        if (commandLine != null) {
-            int z = commandLine.length();
-            boolean insideQuotes = false;
-            StringBuffer buf = new StringBuffer();
-
-            for (int i = 0; i < z; ++i) {
-                char c = commandLine.charAt(i);
-                if (c == '"') {
-                    appendToBuffer(resultBuffer, buf);
-                    insideQuotes = !insideQuotes;
-                } else if (c == '\\') {
-                    if ((z > i + 1)
-                        && ((commandLine.charAt(i + 1) == '"')
-                            || (commandLine.charAt(i + 1) == '\\'))) {
-                        buf.append(commandLine.charAt(i + 1));
-                        ++i;
-                    } else {
-                        buf.append("\\");
-                    }
-                } else {
-                    if (insideQuotes) {
-                        buf.append(c);
-                    } else {
-                        if (Character.isWhitespace(c)) {
-                            appendToBuffer(resultBuffer, buf);
-                        } else {
-                            buf.append(c);
-                        }
-                    }
-                }
-            }
-            appendToBuffer(resultBuffer, buf);
-
-        }
-
-        String[] result = new String[resultBuffer.size()];
-        return ((String[]) resultBuffer.toArray(result));
-    }
-
-}

File Source/com/martiansoftware/jsap/DefaultSource.java

-/*
- * Copyright (c) 2002-2004, Martian Software, Inc.
- * This file is made available under the LGPL as described in the accompanying
- * LICENSE.TXT file.
- */
-
-package com.martiansoftware.jsap;
-
-/**
- * An interface describing an object as being able to produce a set of default
- * values.
- * @author <a href="http://www.martiansoftware.com/contact.html">Marty Lamb</a>
- * @see com.martiansoftware.jsap.Defaults
- */
-public interface DefaultSource {
-
-    /**
-     * Returns a set of default values given the configuration described by the
-     * specified IDMap.  Any encountered exceptions are stored in the specified
-     * JSAPResult.
-     * @param idMap an IDMap containing JSAP configuration information.
-     * @param exceptionMap the ExceptionMap object within which any Exceptions
-     * will be returned.
-     * @return a set of default values given the configuration described by the
-     * specified IDMap.
-     * @see com.martiansoftware.jsap.ExceptionMap#addException(String,Exception)
-     */
-    Defaults getDefaults(IDMap idMap, ExceptionMap exceptionMap);
-
-}

File Source/com/martiansoftware/jsap/Defaults.java

-/*
- * Copyright (c) 2002-2004, Martian Software, Inc.
- * This file is made available under the LGPL as described in the accompanying
- * LICENSE.TXT file.
- */
-
-package com.martiansoftware.jsap;
-
-import java.util.HashMap;
-import java.util.Iterator;
-
-/**
- * Stores a collection of default values, associated with their respective
- * parameters by the parameters' unique IDs.
- *
- * @author <a href="http://www.martiansoftware.com/contact.html">Marty Lamb</a>
- */
-public class Defaults {
-
-    /**
-     * Hashmap associating arrays of Strings (containing default values) with
-     * parameter IDs.
-     */
-    private HashMap defaults = null;
-
-    /**
-     *  Creates a new, empty Defaults object.
-     */
-    public Defaults() {
-        defaults = new HashMap();
-    }
-
-    /**
-     * Sets a single default value for the parameter with the specified ID.
-     * This replaces any default values currently associated with the specified
-     * parameter if any exist.
-     * @param paramID the unique ID of the parameter for which the specified
-     * value is the default.
-     * @param defaultValue the new default value for the specified parameter.
-     */
-    public void setDefault(String paramID, String defaultValue) {
-        String[] newArray = new String[1];
-        newArray[0] = defaultValue;
-        setDefault(paramID, newArray);
-    }
-
-    /**
-     * Sets an array of default values for the parameter with the specified ID.
-     * These replace any default values currently associated with the specified
-     * parameter if any exist.
-     * @param paramID the unique ID of the parameter for which the specified
-     * values are the defaults.
-     * @param defaultValue the new default values for the specified parameter.
-     */
-    public void setDefault(String paramID, String[] defaultValue) {
-        defaults.put(paramID, defaultValue);
-    }
-
-    /**
-     * Adds a single default value to any that might already be defined for the
-     * parameter with the the specified ID.
-     * @param paramID the unique ID of the parameter for which the specified
-     * value is an additional default.
-     * @param defaultValue the default value to add to the specified parameter.
-     */
-    public void addDefault(String paramID, String defaultValue) {
-        String[] newArray = new String[1];
-        newArray[0] = defaultValue;
-        addDefault(paramID, newArray);
-    }
-
-    /**
-     * Adds an array of default values to any that might already be defined for
-     * the parameter with the the specified ID.
-     * @param paramID the unique ID of the parameter for which the specified
-     * value is an additional default.
-     * @param defaultValue the default values to add to the specified parameter.
-     */
-    public void addDefault(String paramID, String[] defaultValue) {
-        String[] curDefault = getDefault(paramID);
-        if (curDefault == null) {
-            curDefault = new String[0];
-        }
-        String[] newDefault =
-            new String[curDefault.length + defaultValue.length];
-        int index = 0;
-        for (int i = 0; i < curDefault.length; ++i) {
-            newDefault[index] = curDefault[i];
-            ++index;
-        }
-        for (int i = 0; i < defaultValue.length; ++i) {
-            newDefault[index] = defaultValue[i];
-            ++index;
-        }
-        setDefault(paramID, newDefault);
-    }
-
-    /**
-     * Sets a single default value for the parameter with the specified ID if
-     * and only if the specified parameter currently has no default values.
-     * @param paramID the unique ID of the parameter for which the specified
-     * value is the default.
-     * @param defaultValue the new default value for the specified parameter.
-     */
-    protected void setDefaultIfNeeded(String paramID, String defaultValue) {
-        if (!defaults.containsKey(paramID)) {
-            setDefault(paramID, defaultValue);
-        }
-    }
-
-    /**
-     * Sets an array of default values for the parameter with the specified ID
-     * if and only if the specified parameter currently has no default values.
-     * @param paramID the unique ID of the parameter for which the specified
-     * value is the default.
-     * @param defaultValue the new default values for the specified parameter.
-     */
-    protected void setDefaultIfNeeded(String paramID, String[] defaultValue) {
-        if (!defaults.containsKey(paramID)) {
-            setDefault(paramID, defaultValue);
-        }
-    }
-
-    /**
-     * Returns an array of the default values defined for the parameter with
-     * the specified ID, or null if no default values are defined.
-     * @param paramID the unique ID of the parameter for which default values
-     * are desired.
-     * @return an array of the default values defined for the parameter with
-     * the specified ID, or null if no default values are defined.
-     */
-    public String[] getDefault(String paramID) {
-        return ((String[]) defaults.get(paramID));
-    }
-
-    /**
-     * Returns an Iterator over the unique IDs of all parameters with defaults
-     * defined in this Defaults object.
-     * @return an Iterator over the unique IDs of all parameters with defaults
-     * defined in this Defaults object.
-     * @see java.util.Iterator
-     */
-    public Iterator idIterator() {
-        return (defaults.keySet().iterator());
-    }
-
-}

File Source/com/martiansoftware/jsap/ExceptionMap.java

-/*
- * Copyright (c) 2002-2004, Martian Software, Inc.
- * This file is made available under the LGPL as described in the accompanying
- * LICENSE.TXT file.
- */
-
-package com.martiansoftware.jsap;
-
-/**
- * A class for aggregating exceptions thrown by JSAP's parsing process.  This
- * class is necessary as it is desirable to have information regarding ALL of
- * the reasons for a failed parse rather than just the FIRST reason.
- * @author <a href="http://www.martiansoftware.com/contact.html">Marty Lamb</a>
- */
-public interface ExceptionMap {
-
-    /**
-     * Adds the specified exception to the exception map.  Exceptions are
-     * keyed by the ID of the parameters with which they are associated.
-     * "General" exceptions not associated with a particular parameter have a
-     * null key.
-     * @param id the unique ID of the parameter with which the specified values
-     * are associated.
-     * @param exception the exception to associate with the specified key.
-     */
-    void addException(String id, Exception exception);
-
-    /**
-     * Returns the first exception associated with the specified parameter ID.
-     * "General" exceptions can be retrieved with a null id.  If no exceptions
-     * are associated with the specified parameter ID, null is returned.
-     * @param id the unique ID of the parameter for which the first exception
-     * is requested
-     * @return the first exception associated with the specified ID, or null if
-     * no exceptions are associated with the specified ID.
-     */
-    Exception getException(String id);
-
-    /**
-     * Returns an array of ALL exceptions associated with the specified
-     * parameter ID. If no exceptions are associated with the specified
-     * parameter ID, an empty (zero-length) array is returned.
-     * @param id the unique ID of the parameter for which the exceptions are
-     * requested.
-     * @return an array of ALL exceptions associated with the specified
-     * parameter ID,
-     * or an empty (zero-length) array if no exceptions are associated with the
-     * specified parameter ID.
-     */
-    Exception[] getExceptionArray(String id);
-
-}

File Source/com/martiansoftware/jsap/Flagged.java

-/*
- * Copyright (c) 2002-2004, Martian Software, Inc.
- * This file is made available under the LGPL as described in the accompanying
- * LICENSE.TXT file.
- */
-
-package com.martiansoftware.jsap;
-
-/**
- * <p>Marks an argument as being "flagged" - that is, as having its value on the
- * command line preceded by an indicator.  Flagged arguments can be preceded by
- * a "short flag," a hyphen followed by a single character, or a "long flag,"
- * two hyphens followed by a word.</p>
- *
- * <p>For example, a short flag 'i' marking an option as meaning "input file"
- * might result in a command line that contains the substring "-i myfile.txt" or
- * "-i=myfile.txt", whereas the same option with a long flag of "inputfile"
- * might contain a substring such as "--inputfile myfile.txt" or
- * "--inputfile=myfile.txt"</p>
- *
- * Note that the setter methods setShortFlag() and setLongFlag() are not
- * part of this Interface.  This is because including them would prevent the
- * setShortFlag() and setLongFlag() methods in FlaggedOption and Switch from
- * returning references to themselves, which is inconvenient and inconsistent
- * with the rest of the API.
- *
- * @author <a href="http://www.martiansoftware.com/contact.html">Marty Lamb</a>
- * @see com.martiansoftware.jsap.Switch
- * @see com.martiansoftware.jsap.FlaggedOption
- */
-public interface Flagged {
-
-    //    /**
-    //     *  Sets the short flag for this object.
-    //     *  @param shortFlag the new short flag for this object.
-    //     *  @return the modified Flagged object.
-    //     */
-    //    Flagged setShortFlag(char shortFlag);
-
-    /**
-     *  Returns the short flag for this object in the form of a char.
-     *  @return the short flag for this object in the form of a char.
-     */
-    char getShortFlag();
-
-    /**
-     *  Returns the short flag for this object in the form of a Character.
-     *  @return the short flag for this object in the form of a Character.
-     */
-    Character getShortFlagCharacter();
-
-    //    /**
-    //     *  Sets the long flag for this object.
-    //     *  @param longFlag the new long flag for this object.
-    //     *  @return the modified Flagged object.
-    //     */
-    //    Flagged setLongFlag(String longFlag);
-
-    /**
-     *  Returns the long flag for this object.
-     *  @return the long flag for this object.
-     */
-    String getLongFlag();
-
-}

File Source/com/martiansoftware/jsap/FlaggedOption.java

-/*
- * Copyright (c) 2002-2004, Martian Software, Inc.
- * This file is made available under the LGPL as described in the accompanying
- * LICENSE.TXT file.
- */
-
-package com.martiansoftware.jsap;
-
-/**
- * An option that implements the Flagged interface.  A flagged option is
- * preceded by a short flag or a long flag; i.e. "-n 5" or "--number 5".
- * FlaggedOptions also provide an additional features over unflagged
- * options, namely the ability to be declared more than once in a command line
- * (e.g., "-n 5 -n 10").  This is not possible with unflagged options, as they
- * are never declared.
- * @author <a href="http://www.martiansoftware.com/contact.html">Marty Lamb</a>
- * @see com.martiansoftware.jsap.Flagged
- * @see com.martiansoftware.jsap.Option
- */
-public class FlaggedOption extends Option implements Flagged {
-
-    /**
-     * The current short flag for this FlaggedOption.  Default is
-     * JSAP.NO_SHORTFLAG.
-     */
-    private char shortFlag = JSAP.NO_SHORTFLAG;
-
-    /**
-     * The current long flag for this FlaggedOption.  Default is
-     * JSAP.NO_LONGLAG.
-     */
-    private String longFlag = JSAP.NO_LONGFLAG;
-
-    /**
-     * If true, this FlaggedOption may be declared more than once on a
-     * command line.
-     * Default is JSAP.NO_MULTIPLEDECLARATIONS.
-     */
-    private boolean allowMultipleDeclarations = JSAP.NO_MULTIPLEDECLARATIONS;
-
-    /**
-     * Creates a new FlaggedOption with the specified unique ID.
-     * @param id the unique ID for this FlaggedOption.
-     */
-    public FlaggedOption(String id) {
-        super(id);
-    }
-
-    /**
-     * A shortcut constructor that creates a new FlaggedOption and configures
-     * its most commonly used settings, including help.
-     * @param id the unique ID for this FlaggedOption.
-     * @param stringParser the StringParser this FlaggedOption should use.
-     * @param defaultValue the default value for this FlaggedOption (may be
-     * null).
-     * @param required if true, this FlaggedOption is required.
-     * @param shortFlag the short flag for this option (may be set to
-     * JSAP.NO_SHORTFLAG for none).
-     * @param longFlag the long flag for this option (may be set to
-     * JSAP.NO_LONGFLAG for none).
-     * @param help the help text for this option (may be set to {@link JSAP#NO_HELP} for none).
-     */
-    public FlaggedOption(
-        String id,
-        StringParser stringParser,
-        String defaultValue,
-        boolean required,
-        char shortFlag,
-        String longFlag,
-		String help) {
-        this(id);
-        setStringParser(stringParser);
-        setDefault(defaultValue);
-        setShortFlag(shortFlag);
-        setLongFlag(longFlag);
-        setRequired(required);
-        setHelp(help);
-    }
-
-    /**
-     * A shortcut constructor that creates a new FlaggedOption and configures
-     * its most commonly used settings.
-     * @param id the unique ID for this FlaggedOption.
-     * @param stringParser the StringParser this FlaggedOption should use.
-     * @param defaultValue the default value for this FlaggedOption (may be
-     * null).
-     * @param required if true, this FlaggedOption is required.
-     * @param shortFlag the short flag for this option (may be set to
-     * JSAP.NO_SHORTFLAG for none).
-     * @param longFlag the long flag for this option (may be set to
-     * JSAP.NO_LONGFLAG for none).
-     */
-    public FlaggedOption(
-        String id,
-        StringParser stringParser,
-        String defaultValue,
-        boolean required,
-        char shortFlag,
-        String longFlag) {
-        this(id, stringParser, defaultValue, required, shortFlag, longFlag, JSAP.NO_HELP);
-    }
-
-
-    /**
-     * Sets the short flag for this FlaggedOption.  To use no short flag at all,
-     * set the value to JSAP.NO_SHORTFLAG.
-     * @param shortFlag the short flag for this FlaggedOption.
-     * @return the modified FlaggedOption
-     */
-    public FlaggedOption setShortFlag(char shortFlag) {
-        enforceParameterLock();
-        this.shortFlag = shortFlag;
-        return (this);
-    }
-
-    /**
-     * Returns the short flag for this FlaggedOption.  If this FlaggedOption
-     * has no short flag, the
-     * return value will be equal to JSAP.NO_SHORTFLAG.
-     * @return the short flag for this FlaggedOption.  If this FlaggedOption
-     * has no short flag, the
-     * return value will be equal to JSAP.NO_SHORTFLAG.
-     */
-    public char getShortFlag() {
-        return (shortFlag);
-    }
-
-    /**
-     * Returns the short flag for this FlaggedOption.  If this FlaggedOption
-     * has no short flag, the
-     * return value will be null.
-     * @return the short flag for this FlaggedOption.  If this FlaggedOption
-     * has no short flag, the
-     * return value will be null.
-     */
-    public Character getShortFlagCharacter() {
-        return (
-            (shortFlag == JSAP.NO_SHORTFLAG) ? null : new Character(shortFlag));
-    }
-
-    /**
-     * Sets the long flag for this FlaggedOption.  To use no long flag at all,
-     * set the value to JSAP.NO_LONGFLAG.
-     * @param longFlag the long flag for this FlaggedOption.
-     * @return the modified FlaggedOption
-     */
-    public FlaggedOption setLongFlag(String longFlag) {
-        enforceParameterLock();
-        this.longFlag = longFlag;
-        return (this);
-    }
-
-    /**
-     * Sets the name that will be displayed when getSyntax() is called
-     * @param usageName the name to use, or null if the id should be used (default)
-     * @return the modified FlaggedOption
-     */
-    public FlaggedOption setUsageName(String usageName) {
-    	_setUsageName(usageName);
-    	return (this);
-    }
-    
-    /**
-     * Returns the long flag for this FlaggedOption.  If this FlaggedOption has
-     * no long flag, the return
-     * value will be equal to JSAP.NO_LONGFLAG.
-     * @return the long flag for this FlaggedOption.  If this FlaggedOption has
-     * no long flag, the return
-     * value will be equal to JSAP.NO_LONGFLAG.
-     */
-    public String getLongFlag() {
-        return (longFlag);
-    }
-
-    /**
-     * <p>Sets this FlaggedOption to allow or disallow multiple declarations.
-     * If multiple declarations are allowed,
-     * the flag may be specified multiple times on the command line (e.g.,
-     * "-n 5 -n 10").  All of the results
-     * are aggregated in the resulting JSAPResult.</p>
-     *
-     * <p>Default behavior is to disallow multiple declarations.</p>
-     * @param allowMultipleDeclarations if true, multiple declarations are
-     * allowed.
-     * @return the modified FlaggedOption
-     */
-    public FlaggedOption setAllowMultipleDeclarations(
-        boolean allowMultipleDeclarations) {
-        enforceParameterLock();
-        this.allowMultipleDeclarations = allowMultipleDeclarations;
-        return (this);
-    }
-
-    /**
-     * Returns a boolean indicating whether multiple declarations are allowed
-     * for this FlaggedOption.
-     * @return a boolean indicating whether multiple declarations are allowed
-     * for this FlaggedOption.
-     * @see #setAllowMultipleDeclarations(boolean)
-     */
-    public boolean allowMultipleDeclarations() {
-        return (allowMultipleDeclarations);
-    }
-
-    /**
-     * Returns syntax instructions for this FlaggedOption.
-     * @return syntax instructions for this FlaggedOption based upon its current
-     * configuration.
-     */
-    @Override
-    public String getSyntax() {
-        StringBuffer result = new StringBuffer();
-        if (!required()) {
-            result.append("[");
-        }
-
-        if ((getLongFlag() != JSAP.NO_LONGFLAG)
-            || (getShortFlag() != JSAP.NO_SHORTFLAG)) {
-            if (getLongFlag() == JSAP.NO_LONGFLAG) {
-                result.append("-" + getShortFlag() + JSAP.SYNTAX_SPACECHAR);
-            } else if (getShortFlag() == JSAP.NO_SHORTFLAG) {
-                result.append("--" + getLongFlag() + JSAP.SYNTAX_SPACECHAR);
-            } else {
-                result.append(
-                    "(-" + getShortFlag() + "|--" + getLongFlag() + ")" + JSAP.SYNTAX_SPACECHAR);
-            }
-        }
-        String un = getUsageName();
-        char sep = this.getListSeparator();
-        if (this.isList()) {
-            result.append(
-                un + "1" + sep + un + "2" + sep + "..." + sep + un + "N ");
-        } else {
-            result.append("<" + getUsageName() + ">");
-        }
-        if (!required()) {
-            result.append("]");
-        }
-        return (result.toString());
-    }
-
-    /**
-     * Sets whether this FlaggedOption is a list.  Default behavior is
-     * JSAP.NOT_LIST.
-     * @param isList if true, this Option is a list.
-     * @return the modified FlaggedOption
-     */
-    public FlaggedOption setList(boolean isList) {
-        super.internalSetList(isList);
-        return (this);
-    }
-
-    /**
-     * Sets the list separator character for this FlaggedOption.  The default
-     * list separator is JSAP.DEFAULT_LISTSEPARATOR.
-     * @param listSeparator the list separator for this Option.
-     * @return the modified FlaggedOption
-     */
-    public FlaggedOption setListSeparator(char listSeparator) {
-        super.internalSetListSeparator(listSeparator);
-        return (this);
-    }
-
-    /**
-     * Sets whether this FlaggedOption is required.  Default is
-     * JSAP.NOT_REQUIRED.
-     * @param required if true, this Option will be required.
-     * @return the modified FlaggedOption
-     */
-    public FlaggedOption setRequired(boolean required) {
-        super.internalSetRequired(required);
-        return (this);
-    }
-
-    /**
-     * Sets one or more default values for this parameter.  This method
-     * should be used whenever a parameter has more than one default
-     * value.
-     * @param defaultValues the default values for this parameter.
-     * @see #setDefault(String)
-     */
-    public FlaggedOption setDefault(String[] defaultValues) {
-    	_setDefault(defaultValues);
-    	return (this);
-    }
-    
-    /**
-     * Sets a default value for this parameter.  The default is specified
-     * as a String, and is parsed as a single value specified on the
-     * command line.  In other words, default values for "list"
-     * parameters or parameters allowing multiple declarations should be
-     * set using setDefault(String[]), as JSAP
-     * would otherwise treat the entire list of values as a single value.
-     *
-     * @param defaultValue the default value for this parameter.
-     * @see #setDefault(String)
-     */
-    public FlaggedOption setDefault(String defaultValue) {
-    	_setDefault(defaultValue);
-    	return (this);
-    }    
-    
-    /**
-     * Sets the StringParser to which this FlaggedOption's parse() method
-     * should delegate.
-     * @param stringParser the StringParser to which this Option's parse()
-     * method should delegate.
-     * @see com.martiansoftware.jsap.StringParser
-     * @return the modified FlaggedOption
-     */
-    public FlaggedOption setStringParser(StringParser stringParser) {
-        super.internalSetStringParser(stringParser);
-        return (this);
-    }
-}

File Source/com/martiansoftware/jsap/IDMap.java

-/*
- * Copyright (c) 2002-2004, Martian Software, Inc.
- * This file is made available under the LGPL as described in the accompanying
- * LICENSE.TXT file.
- */
-
-package com.martiansoftware.jsap;
-
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-
-/**
- * A utility class to allow lookups of parameter IDs by short flag or long flag.
- * This class is used by DefaultSource in order to populate Defaults objects.
- *
- * @author <a href="http://www.martiansoftware.com/contact.html">Marty Lamb</a>
- * @see com.martiansoftware.jsap.Flagged
- * @see com.martiansoftware.jsap.DefaultSource
- * @see com.martiansoftware.jsap.Defaults
- */
-public class IDMap {
-
-    /**
-     * A list of the unique IDs of all the parameters stored in this IDMap.
-     */
-    private List ids = null;
-
-    /**
-     * A Map associating short flags with parameter IDs.
-     */
-    private Map byShortFlag = null;
-
-    /**
-     * A Map associating long flags with parameter IDs.
-     */
-    private Map byLongFlag = null;
-
-    /**
-     * Creates a new IDMap.
-     * @param ids a List of the unique IDs of all the parameters to store
-     * in this IDMap.
-     * @param byShortFlag a Map with keys equal to the short flags of the
-     * parameters (as Character objects),
-     * and values equal to the unique IDs of the parameters associated with
-     * those short flags.
-     * @param byLongFlag a Map with keys equal to the long flags of the
-     * parameters (as Strings),
-     * and values equal to the unique IDs of the parameters associated with
-     * those short flags.
-     */
-    public IDMap(List ids, Map byShortFlag, Map byLongFlag) {
-        this.ids = new java.util.ArrayList(ids);
-        this.byShortFlag = new java.util.HashMap(byShortFlag);
-        this.byLongFlag = new java.util.HashMap(byLongFlag);
-    }
-
-    /**
-     * Returns an Iterator over all parameter IDs stored in this IDMap.
-     * @return an Iterator over all parameter IDs stored in this IDMap.
-     * @see java.util.Iterator
-     */
-    public Iterator idIterator() {
-        return (ids.iterator());
-    }
-
-    /**
-     * Returns true if the specified ID is stored in this IDMap, false if not.
-     * @param id the id to search for in this IDMap
-     * @return true if the specified ID is stored in this IDMap, false if not.
-     */
-    public boolean idExists(String id) {
-        return (ids.contains(id));
-    }
-
-    /**
-     * Returns the unique ID of the parameter with the specified short flag, or
-     * null if the specified short flag is not defined in this IDMap.
-     * @param c the short flag to search for in this IDMap.
-     * @return the unique ID of the parameter with the specified short flag, or
-     * null if the specified short flag is not defined in this IDMap.
-     */
-    public String getIDByShortFlag(Character c) {
-        return ((String) byShortFlag.get(c));
-    }
-
-    /**
-     * Returns the unique ID of the parameter with the specified short flag, or
-     * null if the specified short flag is not defined in this IDMap.
-     * @param c the short flag to search for in this IDMap.
-     * @return the unique ID of the parameter with the specified short flag, or
-     * null if the specified short flag is not defined in this IDMap.
-     */
-    public String getIDByShortFlag(char c) {
-        return (getIDByShortFlag(new Character(c)));
-    }
-
-    /**
-     * Returns the unique ID of the parameter with the specified long flag, or
-     * null if the specified long flag is not defined in this IDMap.
-     * @param s the long flag to search for in this IDMap.
-     * @return the unique ID of the parameter with the specified long flag, or
-     * null if the specified long flag is not defined in this IDMap.
-     */
-    public String getIDByLongFlag(String s) {
-        return ((String) byLongFlag.get(s));
-    }
-}

File Source/com/martiansoftware/jsap/IllegalMultipleDeclarationException.java

-/*
- * Copyright (c) 2002-2004, Martian Software, Inc.
- * This file is made available under the LGPL as described in the accompanying
- * LICENSE.TXT file.
- */
-
-package com.martiansoftware.jsap;
-
-/**
- * An exception indicating that a parameter has illegally been declared multiple
- * times.
- *
- * @see
- *  com.martiansoftware.jsap.FlaggedOption#setAllowMultipleDeclarations(boolean)
- * @author <a href="http://www.martiansoftware.com/contact.html">Marty Lamb</a>
- * @see com.martiansoftware.jsap.Flagged
- * @see com.martiansoftware.jsap.Option
- */
-public class IllegalMultipleDeclarationException extends JSAPException {
-
-    /**
-     * The unique ID of the parameter that was illegally declared more than
-     * once.
-     */
-    private String id = null;
-
-    /**
-     * Creates a new IllegalMultipleDeclarationException referencing the
-     * specified parameter.
-     * @param paramID the unique ID of the parameter that was illegally declared
-     * more than once.
-     */
-    public IllegalMultipleDeclarationException(String paramID) {
-        super("Parameter '" + paramID + "' cannot be declared more than once.");
-        this.id = paramID;
-    }
-
-    /**
-     * Returns the unique ID of the parameter that was illegally declared more
-     * than once.
-     * @return the unique ID of the parameter that was illegally declared more
-     * than once.
-     */
-    public String getID() {
-        return (this.id);
-    }
-
-}

File Source/com/martiansoftware/jsap/JSAP.java

-/*
- * Copyright (c) 2002-2004, Martian Software, Inc.
- * This file is made available under the LGPL as described in the accompanying
- * LICENSE.TXT file.
- */
-
-package com.martiansoftware.jsap;
-
-import java.io.IOException;
-import java.net.URL;
-import java.util.Map;
-import java.util.List;
-import java.util.Iterator;
-
-import com.martiansoftware.jsap.stringparsers.BigDecimalStringParser;
-import com.martiansoftware.jsap.stringparsers.BigIntegerStringParser;
-import com.martiansoftware.jsap.stringparsers.BooleanStringParser;
-import com.martiansoftware.jsap.stringparsers.ByteStringParser;
-import com.martiansoftware.jsap.stringparsers.CharacterStringParser;
-import com.martiansoftware.jsap.stringparsers.ClassStringParser;
-import com.martiansoftware.jsap.stringparsers.ColorStringParser;
-import com.martiansoftware.jsap.stringparsers.DoubleStringParser;
-import com.martiansoftware.jsap.stringparsers.FloatStringParser;
-import com.martiansoftware.jsap.stringparsers.InetAddressStringParser;
-import com.martiansoftware.jsap.stringparsers.IntSizeStringParser;
-import com.martiansoftware.jsap.stringparsers.IntegerStringParser;
-import com.martiansoftware.jsap.stringparsers.LongSizeStringParser;
-import com.martiansoftware.jsap.stringparsers.LongStringParser;
-import com.martiansoftware.jsap.stringparsers.PackageStringParser;
-import com.martiansoftware.jsap.stringparsers.ShortStringParser;
-import com.martiansoftware.jsap.stringparsers.StringStringParser;
-import com.martiansoftware.jsap.stringparsers.URLStringParser;
-import com.martiansoftware.jsap.xml.JSAPConfig;
-import com.martiansoftware.util.StringUtils;
-
-/**
- * The core class of the JSAP (Java Simple Argument Parser) API.
- *
- * <p>A JSAP is responsible for converting an array of Strings, typically
- * received from a  command line in the main class' main() method, into a
- * collection of Objects that are retrievable by a unique ID assigned by the
- * developer.</p>
- *
- * <p>Before a JSAP parses a command line, it is configured with the Switches,
- * FlaggedOptions, and UnflaggedOptions it will accept.  As a result, the
- * developer can rest assured that if no Exceptions are thrown by the JSAP's
- * parse() method, the entire command line was parsed successfully.</p>
- *
- * <p>For example, to parse a command line with the syntax "[--verbose]
- * {-n|--number} Mynumber", the following code could be used:</p.
- *
- * <code><pre>
- * JSAP myJSAP = new JSAP();
- * myJSAP.registerParameter( new Switch( "verboseSwitch", JSAP.NO_SHORTFLAG,
- * "verbose" ) );
- * myJSAP.registerParameter( new FlaggedOption( "numberOption", new
- * IntegerStringParser(), JSAP.NO_DEFAULT,
- * JSAP.NOT_REQUIRED, 'n', "number" ) );
- * JSAPResult result = myJSAP.parse(args);
- * </pre></code>
- *
- * <p>The results of the parse could then be obtained with:</p>
- *
- * <code><pre>
- * int n = result.getInt("numberOption");
- * boolean isVerbose = result.getBoolean("verboseSwitch");
- * </pre></code>
- *
- * <h3>Generating a JSAP from ANT</h3>
- * <p>If you don't want to register all your parameters manually as shown
- * above, the JSAP API provides a custom ANT task that will generate a
- * custom JSAP subclass to suit your needs.  See
- * com.martiansoftware.jsap.ant.JSAPAntTask for details.</p>
- * <p>See the accompanying documentation for examples and further information.
- *
- * @author <a href="http://www.martiansoftware.com/contact.html">Marty Lamb</a>
- * @author Klaus Berg (bug fixes in help generation)
- * @author Wolfram Esser (contributed code for custom line separators in help)
- * @see com.martiansoftware.jsap.ant.JSAPAntTask
- */
-public class JSAP {
-
-    /**
-     * Map of this JSAP's AbstractParameters keyed on their unique ID.
-     */
-    private Map paramsByID = null;
-
-    /**
-     * Map of this JSAP's AbstractParameters keyed on their short flag.
-     */
-    private Map paramsByShortFlag = null;
-
-    /**
-     * Map of this JSAP's AbstractParameters keyed on their long flag.
-     */
-    private Map paramsByLongFlag = null;
-
-    /**
-     * List of this JSAP's UnflaggedOptions, in order of declaration.
-     */
-    private List unflaggedOptions = null;
-
-    /**
-     * List of all of this JSAP's AbstractParameters, in order of
-     * declaration.
-     */
-    private List paramsByDeclarationOrder = null;
-
-    /**
-     * List of all of this JSAP's DefaultSources, in order of declaration.
-     */
-    private List defaultSources = null;
-
-    /**
-     * If not null, overrides the automatic usage info.
-     */
-    private String usage = null;
-
-    /**
-     * If not null, overrides the automatic help info.
-     */
-    private String help = null;
-
-    /**
-     * Does not have a short flag.
-     *
-     * @see com.martiansoftware.jsap.FlaggedOption
-     * @see com.martiansoftware.jsap.UnflaggedOption
-     */
-    public static final char NO_SHORTFLAG = '\0';
-
-    /**
-     * Does not have a long flag.
-     *
-     * @see com.martiansoftware.jsap.FlaggedOption
-     * @see com.martiansoftware.jsap.UnflaggedOption
-     */
-    public static final String NO_LONGFLAG = null;
-
-    /**
-     * The default separator for list parameters (equivalent to
-     * java.io.File.pathSeparatorChar)
-     *
-     * @see FlaggedOption#setListSeparator(char)
-     */
-    public static final char DEFAULT_LISTSEPARATOR =
-        java.io.File.pathSeparatorChar;
-
-    /**
-     * The default separator between parameters in generated help (a newline
-     * by default)
-     */
-    public static final String DEFAULT_PARAM_HELP_SEPARATOR = "\n";
-    
-    /**
-     * The parameter is required.
-     *
-     * @see FlaggedOption#setRequired(boolean)
-     */
-    public static final boolean REQUIRED = true;
-
-    /**
-     * The parameter is not required.
-     *
-     * @see FlaggedOption#setRequired(boolean)
-     */
-    public static final boolean NOT_REQUIRED = false;
-
-    /**
-     * The parameter is a list.
-     *
-     * @see FlaggedOption#setList(boolean)
-     */
-    public static final boolean LIST = true;
-
-    /**
-     * The parameter is not a list.
-     *
-     * @see FlaggedOption#setList(boolean)
-     */
-    public static final boolean NOT_LIST = false;
-
-    /**
-     * The parameter allows multiple declarations.
-     *
-     * @see FlaggedOption#setAllowMultipleDeclarations(boolean)
-     */
-    public static final boolean MULTIPLEDECLARATIONS = true;
-
-    /**
-     * The parameter does not allow multiple declarations.
-     *
-     * @see FlaggedOption#setAllowMultipleDeclarations(boolean)
-     */
-    public static final boolean NO_MULTIPLEDECLARATIONS = false;
-
-    /**
-     * The parameter consumes the command line.
-     *
-     * @see com.martiansoftware.jsap.UnflaggedOption#setGreedy(boolean)
-     */
-    public static final boolean GREEDY = true;
-
-    /**
-     * The parameter does not consume the command line.
-     *
-     * @see com.martiansoftware.jsap.UnflaggedOption#setGreedy(boolean)
-     */
-    public static final boolean NOT_GREEDY = false;
-
-    /** The parameter has no default value.
-     */
-    public static final String NO_DEFAULT = null;
-
-    /**
-     * The parameter has no help text.
-     *
-     * @see com.martiansoftware.jsap.Parameter#setHelp(String)
-     */
-    public static final String NO_HELP = null;
-
-    /** 
-     * The only instance of a {@link com.martiansoftware.jsap.stringparsers.BigDecimalStringParser}.
-     */
-    
-    public static final BigDecimalStringParser BIGDECIMAL_PARSER = BigDecimalStringParser.getParser();
-    
-    /** 
-     * The only instance of a {@link com.martiansoftware.jsap.stringparsers.BigIntegerStringParser}.
-     */
-    
-    public static final BigIntegerStringParser BIGINTEGER_PARSER = BigIntegerStringParser.getParser();
-    
-    /** 
-     * The only instance of a {@link com.martiansoftware.jsap.stringparsers.BooleanStringParser}.
-     */
-    
-    public static final BooleanStringParser BOOLEAN_PARSER = BooleanStringParser.getParser();
-    
-    /** 
-     * The only instance of a {@link com.martiansoftware.jsap.stringparsers.ByteStringParser}.
-     */
-    
-    public static final ByteStringParser BYTE_PARSER = ByteStringParser.getParser();
-    
-    
-    /** 
-     * The only instance of a {@link com.martiansoftware.jsap.stringparsers.CharacterStringParser}.
-     */
-    
-    public static final CharacterStringParser CHARACTER_PARSER = CharacterStringParser.getParser();
-    
-    /** 
-     * The only instance of a {@link com.martiansoftware.jsap.stringparsers.ClassStringParser}.
-     */
-    
-    public static final ClassStringParser CLASS_PARSER = ClassStringParser.getParser();
-
-    
-    /** 
-     * The only instance of a {@link com.martiansoftware.jsap.stringparsers.ColorStringParser}.
-     */
-    
-    public static final ColorStringParser COLOR_PARSER = ColorStringParser.getParser();
-
-    
-    /** 
-     * The only instance of a {@link com.martiansoftware.jsap.stringparsers.DoubleStringParser}.
-     */
-    
-    public static final DoubleStringParser DOUBLE_PARSER = DoubleStringParser.getParser();
-
-    
-    /** 
-     * The only instance of a {@link com.martiansoftware.jsap.stringparsers.FloatStringParser}.
-     */
-    
-    public static final FloatStringParser FLOAT_PARSER = FloatStringParser.getParser();
-
-    /** 
-     * The only instance of a {@link com.martiansoftware.jsap.stringparsers.InetAddressStringParser}.
-     */
-    
-    public static final InetAddressStringParser INETADDRESS_PARSER = InetAddressStringParser.getParser();
-
-    /** 
-     * The only instance of a {@link com.martiansoftware.jsap.stringparsers.IntegerStringParser}.
-     */
-    
-    public static final IntegerStringParser INTEGER_PARSER = IntegerStringParser.getParser();
-
-    /** 
-     * The only instance of a {@link com.martiansoftware.jsap.stringparsers.IntSizeStringParser}.
-     */
-    
-    public static final IntSizeStringParser INTSIZE_PARSER = IntSizeStringParser.getParser();
-
-    /** 
-     * The only instance of a {@link com.martiansoftware.jsap.stringparsers.LongSizeStringParser}.
-     */
-    
-    public static final LongSizeStringParser LONGSIZE_PARSER = LongSizeStringParser.getParser();
-
-    /** 
-     * The only instance of a {@link com.martiansoftware.jsap.stringparsers.LongStringParser}.
-     */
-    
-    public static final LongStringParser LONG_PARSER = LongStringParser.getParser();
-
-    /** 
-     * The only instance of a {@link com.martiansoftware.jsap.stringparsers.PackageStringParser}.
-     */
-    
-    public static final PackageStringParser PACKAGE_PARSER = PackageStringParser.getParser();
-
-    /** 
-     * The only instance of a {@link com.martiansoftware.jsap.stringparsers.ShortStringParser}.
-     */
-    
-    public static final ShortStringParser SHORT_PARSER = ShortStringParser.getParser();
-
-    /** 
-     * The only instance of a {@link com.martiansoftware.jsap.stringparsers.StringStringParser}.
-     */
-    
-    public static final StringStringParser STRING_PARSER = StringStringParser.getParser();
-
-    /** 
-     * The only instance of a {@link com.martiansoftware.jsap.stringparsers.URLStringParser}.
-     */
-    
-    public static final URLStringParser URL_PARSER = URLStringParser.getParser();
-
-    /**
-     * The default screen width used for formatting help.
-     */
-    public static final int DEFAULT_SCREENWIDTH = 80;
-
-    /**
-     * Temporary fix for bad console encodings screwing up non-breaking spaces.
-     */
-    static char SYNTAX_SPACECHAR = ' ';
-    
-    static {
-    	if (Boolean.valueOf(System.getProperty("com.martiansoftware.jsap.usenbsp", "false")).booleanValue()) {
-    		SYNTAX_SPACECHAR = '\u00a0';
-    	}
-    }
-    
-    /**
-     * Creates a new JSAP with an empty configuration.  It must be configured
-     * with registerParameter() before its parse() methods may be called.
-     */
-    public JSAP() {
-    	init();
-    }
-    
-    /**
-     * Creates a new JSAP configured as specified in the referenced xml.
-     * @param jsapXML reference to xml representation of the JSAP configuration
-     * @throws IOException if an I/O error occurs
-     * @throws JSAPException if the configuration is not valid
-     */
-    public JSAP(URL jsapXML) throws IOException, JSAPException {
-    	init();
-    	JSAPConfig.configure(this, jsapXML);
-    }
-
-    /**
-     * Creates a new JSAP configured as specified in the referenced xml.
-     * @param resourceName name of the resource (accessible via this JSAP's classloader)
-     * containing the xml representation of the JSAP configuration
-     * @throws IOException if an I/O error occurs
-     * @throws JSAPException if the configuration is not valid
-     */
-    public JSAP(String resourceName) throws IOException, JSAPException {
-    	this(JSAP.class.getClassLoader().getResource(resourceName));
-    }
-    
-    private void init() {
-        paramsByID = new java.util.HashMap();
-        paramsByShortFlag = new java.util.HashMap();
-        paramsByLongFlag = new java.util.HashMap();
-        unflaggedOptions = new java.util.ArrayList();
-        paramsByDeclarationOrder = new java.util.ArrayList();
-        defaultSources = new java.util.ArrayList();    	
-    }
-    
-    /**
-     * Sets the usage string manually, overriding the automatically-
-     * generated String.  To remove the override, call setUsage(null).
-     * @param usage the manually-set usage string.
-     */
-    public void setUsage(String usage) {
-        this.usage = usage;
-    }
-
-    /**
-     * Sets the help string manually, overriding the automatically-
-     * generated String.  To remove the override, call setHelp(null).
-     * @param help the manualy-set help string.
-     */
-    public void setHelp(String help) {
-        this.help = help;
-    }
-
-    /**
-     * A shortcut method for calling getHelp(80, "\n").
-     * @see #getHelp(int,String)
-     * @return the same as gethelp(80, "\n")
-     */
-    public String getHelp() {
-        return (getHelp(DEFAULT_SCREENWIDTH, DEFAULT_PARAM_HELP_SEPARATOR));
-    }
-
-    /**
-     * A shortcut method for calling getHelp(screenWidth, "\n").
-     * @param screenWidth the screen width for which to format the help.
-     * @see #getHelp(int,String)
-     * @return the same as gethelp(screenWidth, "\n")
-     */
-    public String getHelp(int screenWidth) {
-    	return (getHelp(screenWidth, DEFAULT_PARAM_HELP_SEPARATOR));
-    }
-    
-    /**
-     * If the help text has been manually set, this method simply
-     * returns it, ignoring the screenWidth parameter.  Otherwise,
-     * an automatically-formatted help message is returned, tailored
-     * to the specified screen width.
-     * @param screenWidth the screen width (in characters) for which
-     * the help text will be formatted.  If zero, help will not be
-     * line-wrapped.
-     * @return complete help text for this JSAP.
-     */
-    public String getHelp(int screenWidth, String paramSeparator) {
-        String result = help;
-        if (result == null) {
-            StringBuffer buf = new StringBuffer();
-
-            // We'll wrap at screenWidth - 8
-            int wrapWidth = screenWidth - 8;
-
-            // now loop through all the params again and display their help info
-            for (Iterator i = paramsByDeclarationOrder.iterator();
-                i.hasNext();) {
-                Parameter param = (Parameter) i.next();
-                StringBuffer defaultText = new StringBuffer();
-                String[] defaultValue = param.getDefault();
-                if ( !(param instanceof Switch) && defaultValue != null ) {
-                    defaultText.append(" (default: ");
-                    for(int j = 0; j < defaultValue.length; j++ ) {
-                        if (j > 0) defaultText.append( ", " );
-                        defaultText.append(defaultValue[ j ]);
-                    }
-                    defaultText.append(")");
-                }
-                Iterator helpInfo =
-                    StringUtils
-                        .wrapToList(param.getHelp() + defaultText, wrapWidth)
-                        .iterator();
-
-                buf.append("  "); // the two leading spaces
-                buf.append(param.getSyntax());
-                buf.append("\n");
-
-                while (helpInfo.hasNext()) {
-                    buf.append("        ");
-                    buf.append( helpInfo.next() );
-                    buf.append("\n");
-                }
-                if (i.hasNext()) {
-                    buf.append(paramSeparator);
-                }
-            }
-            result = buf.toString();
-        }
-        return (result);
-    }
-
-    /**
-     * Returns an automatically generated usage description based upon this
-     * JSAP's  current configuration.
-     *
-     * @return an automatically generated usage description based upon this
-     * JSAP's current configuration.
-     */
-    public String getUsage() {
-        String result = usage;
-        if (result == null) {
-            StringBuffer buf = new StringBuffer();
-            for (Iterator i = paramsByDeclarationOrder.iterator();
-                i.hasNext();) {
-                Parameter param = (Parameter) i.next();
-                if (buf.length() > 0) {
-                    buf.append(" ");
-                }
-                buf.append(param.getSyntax());
-            }
-            result = buf.toString();
-        }
-        return (result);
-    }
-
-    /**
-     * Returns an automatically generated usage description based upon this
-     * JSAP's  current configuration.  This returns exactly the same result
-     * as getUsage().
-     *
-     * @return an automatically generated usage description based upon this
-     * JSAP's current configuration.
-     */
-    @Override
-    public String toString() {
-        return (getUsage());
-    }
-
-    /**
-     * Returns an IDMap associating long and short flags with their associated
-     * parameters' IDs, and allowing the listing of IDs.  This is probably only
-     * useful for developers creating their own DefaultSource classes.
-     * @return an IDMap based upon this JSAP's current configuration.
-     */
-    public IDMap getIDMap() {
-        List ids = new java.util.ArrayList(paramsByDeclarationOrder.size());
-        for (Iterator i = paramsByDeclarationOrder.iterator(); i.hasNext();) {
-            Parameter param = (Parameter) i.next();
-            ids.add(param.getID());
-        }
-
-        Map byShortFlag = new java.util.HashMap();
-        for (Iterator i = paramsByShortFlag.keySet().iterator();
-          i.hasNext();) {
-            Character c = (Character) i.next();
-            byShortFlag.put(
-                c,
-                ((Parameter) paramsByShortFlag.get(c)).getID());
-        }
-
-        Map byLongFlag = new java.util.HashMap();
-        for (Iterator i = paramsByLongFlag.keySet().iterator(); i.hasNext();) {
-            String s = (String) i.next();
-            byLongFlag.put(
-                s,
-                ((Parameter) paramsByLongFlag.get(s)).getID());
-        }
-
-        return (new IDMap(ids, byShortFlag, byLongFlag));
-    }
-
-    /**
-     * Returns the requested Switch, FlaggedOption, or UnflaggedOption with the
-     * specified ID.  Depending upon what you intend to do with the result, it
-     * may be necessary to re-cast the result as a Switch, FlaggedOption, or
-     * UnflaggedOption as appropriate.
-     *
-     * @param id the ID of the requested Switch, FlaggedOption, or
-     * UnflaggedOption.
-     * @return the requested Switch, FlaggedOption, or UnflaggedOption, or null
-     * if no Parameter with the specified ID is defined in this JSAP.
-     */
-    public Parameter getByID(String id) {
-        return ((Parameter) paramsByID.get(id));
-    }
-
-    /**
-     * Returns the requested Switch or FlaggedOption with the specified long
-     * flag. Depending upon what you intend to do with the result, it may be
-     * necessary to re-cast the result as a Switch or FlaggedOption as
-     * appropriate.
-     *
-     * @param longFlag the long flag of the requested Switch or FlaggedOption.
-     * @return the requested Switch or FlaggedOption, or null if no Flagged
-     * object with the specified long flag is defined in this JSAP.
-     */
-    public Flagged getByLongFlag(String longFlag) {
-        return ((Flagged) paramsByLongFlag.get(longFlag));
-    }
-
-    /**
-     * Returns the requested Switch or FlaggedOption with the specified short
-     * flag. Depending upon what you intend to do with the result, it may be
-     * necessary to re-cast the result as a Switch or FlaggedOption as
-     * appropriate.
-     *
-     * @param shortFlag the short flag of the requested Switch or FlaggedOption.
-     * @return the requested Switch or FlaggedOption, or null if no Flagged
-     * object with the specified short flag is defined in this JSAP.
-     */
-    public Flagged getByShortFlag(Character shortFlag) {
-        return ((Flagged) paramsByShortFlag.get(shortFlag));
-    }
-
-    /**
-     * Returns the requested Switch or FlaggedOption with the specified short
-     * flag. Depending upon what you intend to do with the result, it may be
-     * necessary to re-cast the result as a Switch or FlaggedOption as
-     * appropriate.
-     *
-     * @param shortFlag the short flag of the requested Switch or FlaggedOption.
-     * @return the requested Switch or FlaggedOption, or null if no Flagged
-     * object with the specified short flag is defined in this JSAP.
-     */
-    public Flagged getByShortFlag(char shortFlag) {
-        return (getByShortFlag(new Character(shortFlag)));
-    }
-
-    /**
-     * Returns an Iterator over all UnflaggedOptions currently registered with
-     * this JSAP.
-     *
-     * @return an Iterator over all UnflaggedOptions currently registered with
-     * this JSAP.
-     * @see java.util.Iterator
-     */
-    public Iterator getUnflaggedOptionsIterator() {
-        return (unflaggedOptions.iterator());
-    }
-
-    /**
-     * Registers a new DefaultSource with this JSAP, at the end of the current
-     * DefaultSource chain, but before the defaults defined within the
-     * AbstractParameters themselves.
-     *
-     * @param ds the DefaultSource to append to the DefaultSource chain.
-     * @see com.martiansoftware.jsap.DefaultSource
-     */
-    public void registerDefaultSource(DefaultSource ds) {
-        defaultSources.add(ds);
-    }
-
-    /**
-     * Removes the specified DefaultSource from this JSAP's DefaultSource chain.
-     * If this specified DefaultSource is not currently in this JSAP's
-     * DefaultSource chain, this method does nothing.
-     *
-     * @param ds the DefaultSource to remove from the DefaultSource chain.
-     */
-    public void unregisterDefaultSource(DefaultSource ds) {
-        defaultSources.remove(ds);
-    }
-
-    /**
-     * Returns a Defaults object representing the default values defined within
-     * this JSAP's AbstractParameters themselves.
-     *
-     * @return a Defaults object representing the default values defined within
-     * this JSAP's AbstractParameters themselves.
-     */
-    private Defaults getSystemDefaults() {
-        Defaults defaults = new Defaults();
-        for (Iterator i = paramsByDeclarationOrder.iterator(); i.hasNext();) {
-            Parameter param = (Parameter) i.next();
-            defaults.setDefault(param.getID(), param.getDefault());
-        }
-        return (defaults);
-    }
-
-    /**
-     * Merges the specified Defaults objects, only copying Default values from
-     * the source to the destination if they are NOT currently defined in the
-     * destination.
-     *
-     * @param dest the destination Defaults object into which the source should
-     * be merged.
-     * @param src the source Defaults object.
-     */
-    private void combineDefaults(Defaults dest, Defaults src) {
-        if (src != null) {
-            for (Iterator i = src.idIterator(); i.hasNext();) {
-                String paramID = (String) i.next();
-                dest.setDefaultIfNeeded(paramID, src.getDefault(paramID));
-            }
-        }
-    }
-
-    /**
-     * Returns a Defaults object representing the merged Defaults of every
-     * DefaultSource in the DefaultSource chain and the default values specified
-     * in the AbstractParameters themselves.
-     *
-     * @param exceptionMap the ExceptionMap object within which any encountered
-     * exceptions will be returned.
-     * @return a Defaults object representing the Defaults of the entire JSAP.
-     * @see com.martiansoftware.jsap.DefaultSource#getDefaults(IDMap, ExceptionMap)
-     */
-    protected Defaults getDefaults(ExceptionMap exceptionMap) {
-        Defaults defaults = new Defaults();
-        IDMap idMap = getIDMap();
-        for (Iterator dsi = defaultSources.iterator(); dsi.hasNext();) {
-            DefaultSource ds = (DefaultSource) dsi.next();
-            combineDefaults(defaults, ds.getDefaults(idMap, exceptionMap));
-        }
-        combineDefaults(defaults, getSystemDefaults());
-        return (defaults);
-    }
-
-    /**
-     * Registers the specified Parameter (i.e., Switch, FlaggedOption,
-     * or UnflaggedOption) with this JSAP.
-     *
-     * <p>Registering an Parameter <b>locks</b> the parameter.
-     * Attempting to change its properties (ID, flags, etc.) while it is locked
-     * will result in a JSAPException.  To unlock an Parameter, it must
-     * be unregistered from the JSAP.
-     *
-     * @param param the Parameter to register.
-     * @throws JSAPException if this Parameter cannot be added. Possible
-     * reasons include:
-     * <ul>
-     *     <li>Another Parameter with the same ID has already been
-     *      registered.</li>
-     *  <li>You are attempting to register a Switch or FlaggedOption with
-     *      neither a short nor long flag.</li>
-     *  <li>You are attempting to register a Switch or FlaggedOption with a long
-     *      or short flag that is already
-     *  defined in this JSAP.</li>
-     *  <li>You are attempting to register a second greedy UnflaggedOption</li>
-     * </ul>
-     */
-    public void registerParameter(Parameter param)
-        throws JSAPException {
-        String paramID = param.getID();
-
-        if (paramsByID.containsKey(paramID)) {
-            throw (
-                new JSAPException(
-                    "A parameter with ID '"
-                        + paramID
-                        + "' has already been registered."));
-        }
-
-        if (param instanceof Flagged) {
-            Flagged f = (Flagged) param;
-            if ((f.getShortFlagCharacter() == null)
-                && (f.getLongFlag() == null)) {
-                throw (
-                    new JSAPException(
-                        "FlaggedOption '"
-                            + paramID
-                            + "' has no flags defined."));
-            }
-            if (paramsByShortFlag.containsKey(f.getShortFlagCharacter())) {
-                throw (
-                    new JSAPException(
-                        "A parameter with short flag '"
-                            + f.getShortFlag()
-                            + "' has already been registered."));
-            }
-            if (paramsByLongFlag.containsKey(f.getLongFlag())) {
-                throw (
-                    new JSAPException(
-                        "A parameter with long flag '"
-                            + f.getLongFlag()
-                            + "' has already been registered."));
-            }
-        } else {
-            if ((unflaggedOptions.size() > 0)
-                && (((UnflaggedOption) unflaggedOptions
-                    .get(unflaggedOptions.size() - 1))
-                    .isGreedy())) {
-                throw (
-                    new JSAPException(
-                        "A greedy unflagged option has already been registered;"
-                            + " option '"
-                            + paramID
-                            + "' will never be reached."));
-            }
-        }
-
-        if (param instanceof Option) {
-            ((Option) param).register();
-        }
-
-        // if we got this far, it's safe to insert it.
-        param.setLocked(true);
-        paramsByID.put(paramID, param);
-        paramsByDeclarationOrder.add(param);
-        if (param instanceof Flagged) {
-            Flagged f = (Flagged) param;
-            if (f.getShortFlagCharacter() != null) {
-                paramsByShortFlag.put(f.getShortFlagCharacter(), param);
-            }
-            if (f.getLongFlag() != null) {
-                paramsByLongFlag.put(f.getLongFlag(), param);
-            }
-        } else if (param instanceof Option) {
-            unflaggedOptions.add(param);
-        }
-    }
-
-    /**
-     * Unregisters the specified Parameter (i.e., Switch, FlaggedOption,
-     * or UnflaggedOption) from this JSAP.  Unregistering an Parameter
-     * also unlocks it, allowing changes to its properties (ID, flags, etc.).
-     *
-     * @param param the Parameter to unregister from this JSAP.
-     */
-    public void unregisterParameter(Parameter param) {
-        if (paramsByID.containsKey(param.getID())) {
-
-            if (param instanceof Option) {
-                ((Option) param).unregister();
-            }
-
-            paramsByID.remove(param.getID());
-            paramsByDeclarationOrder.remove(param);
-            if (param instanceof Flagged) {
-                Flagged f = (Flagged) param;
-                paramsByShortFlag.remove(f.getShortFlagCharacter());
-                paramsByLongFlag.remove(f.getLongFlag());
-            } else if (param instanceof UnflaggedOption) {
-                unflaggedOptions.remove(param);
-            }
-            param.setLocked(false);
-        }
-    }
-
-    /**
-     * Parses the specified command line array.  If no Exception is thrown, the
-     * entire command line has been parsed successfully, and its results have
-     * been successfully instantiated.
-     *
-     * @param args An array of command line arguments to parse.  This array is
-     * typically provided in the application's main class' main() method.
-     * @return a JSAPResult containing the resulting Objects.
-     */
-    public JSAPResult parse(String[] args) {
-        Parser p = new Parser(this, args);
-        return (p.parse());
-    }
-
-    /**
-     * Parses the specified command line.  The specified command line is first
-     * parsed into an array, much like the operating system does for the JVM
-     * prior to calling your application's main class' main() method.  If no
-     * Exception is thrown, the entire command line has been parsed
-     * successfully, and its results have been successfully instantiated.
-     *
-     * @param cmdLine An array of command line arguments to parse.  This array
-     * is typically provided in the application's main class' main() method.
-     * @return a JSAPResult containing the resulting Objects.
-     */
-    public JSAPResult parse(String cmdLine) {
-        String[] args = CommandLineTokenizer.tokenize(cmdLine);
-        return (parse(args));
-    }
-
-    /**
-     * Unregisters all registered AbstractParameters, allowing them to perform
-     * their cleanup.
-     */
-    @Override
-    public void finalize() {
-        Parameter[] params =
-            (Parameter[]) paramsByDeclarationOrder.toArray(
-                new Parameter[0]);
-        int paramCount = params.length;
-        for (int i = 0; i < paramCount; ++i) {
-            unregisterParameter(params[i]);
-        }
-    }
-
-}

File Source/com/martiansoftware/jsap/JSAPException.java

-/*
- * Copyright (c) 2002-2004, Martian Software, Inc.
- * This file is made available under the LGPL as described in the accompanying
- * LICENSE.TXT file.
- */
-
-package com.martiansoftware.jsap;
-
-/**
- * The base class for all of JSAP's exceptions.  A JSAPException can
- * encapsulate another Exception, which can be obtained via the getRootCause()
- * method.  This is useful in cases where subclasses might need to
- * throw an exception that JSAP is not expecting, such as an IOException while
- * loading a DefaultSource.  The subclass can in these cases throw a new
- * JSAPException encapsulating the IOException.
- * @author <a href="http://www.martiansoftware.com/contact.html">Marty Lamb</a>
- * @see com.martiansoftware.jsap.Flagged
- * @see com.martiansoftware.jsap.Option
- */
-public class JSAPException extends Exception {
-
-    /**
-     * Creates a new JSAPException.
-     */
-    public JSAPException() {
-        super();
-    }
-
-    /**
-     * Creates a new JSAPException with the specified message.
-     * @param msg the message for this JSAPException.
-     */
-    public JSAPException(String msg) {
-        super(msg);
-    }
-
-    /**
-     * Creates a new JSAPException encapsulating the specified Throwable.
-     * @param cause the Throwable to encapsulate.
-     */
-    public JSAPException(Throwable cause) {
-        super(cause);
-    }
-
-    /**
-     * Creates a new JSAPException with the specified message encapsulating
-     * the specified Throwable.
-     * @param msg the message for this JSAPException.
-     * @param cause the Throwable to encapsulate.
-     */
-    public JSAPException(String msg, Throwable cause) {
-        super(msg, cause);