Index: lutinutil/src/java/org/codelutin/util/Option.java diff -u /dev/null lutinutil/src/java/org/codelutin/util/Option.java:1.1 --- /dev/null Mon Nov 19 20:48:00 2007 +++ lutinutil/src/java/org/codelutin/util/Option.java Mon Nov 19 20:47:54 2007 @@ -0,0 +1,90 @@ +/** + * ##% Copyright (C) 2002, 2003 Code Lutin This program is free software; you + * can redistribute it and/or modify it under the terms of the GNU General + * Public License as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. This program is + * distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; + * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A + * PARTICULAR PURPOSE. See the GNU General Public License for more details. You + * should have received a copy of the GNU General Public License along with this + * program; if not, write to the Free Software Foundation, Inc., 59 Temple Place + * - Suite 330, Boston, MA 02111-1307, USA. ##%* + */ + +/** + * Option.java Created: 22 août 2003 + * + *@author Benjamin Poussin + * + * Copyright Code Lutin + *@version $Revision: 1.1 $ Mise a jour: $Date: 2007-11-19 20:47:54 $ par : $Author: tchemit $ + */ + +package org.codelutin.util; + +/** + * Classe représentant une option trouvée lors du parsing de + * la ligne de commande par le parseur {@link OptionParser}. + * + * @author chemit + * @created 15 nov 2007 + */ +public class Option { // Option + + /** L'alias utilisé sur la ligne de commande pour cette option */ + protected final String usedAlias; + + /** la liste des arguments consommés pour cette option */ + protected final OptionArgument[] arguments; + + /** la definition de l'option */ + protected final OptionDefinition definition; + + /** + * @param definition definition de l'option + * @param usedAlias used alias + * @param arguments arguments of the option + */ + public Option(OptionDefinition definition, String usedAlias, + OptionArgument... arguments) { + this.definition = definition; + this.usedAlias = usedAlias; + this.arguments = arguments; + } + + public String getUsedAlias() { + return usedAlias; + } + + public OptionDefinition getDefinition() { + return definition; + } + + public OptionArgument[] getArguments() { + return arguments; + } + + public Object[] getArgumentsValue() { + Object[] result = new Object[arguments.length]; + for (int i = 0; i < arguments.length; i++) { + OptionArgument argument = arguments[i]; + result[i] = argument.getValue(); + } + return result; + } + + public Object getArgumentValue(String argumentKey) { + for (OptionArgument optionArgument : arguments) { + if (optionArgument.getKey().equals(argumentKey)) { + return optionArgument.getValue(); + } + } + return null; + } + + @Override + public String toString() { + return definition + " (" + usedAlias + ")" + + java.util.Arrays.toString(getArguments()); + } +}// Option