Index: lutinutil/src/java/org/codelutin/util/OptionArgument.java diff -u /dev/null lutinutil/src/java/org/codelutin/util/OptionArgument.java:1.1 --- /dev/null Mon Nov 19 20:47:47 2007 +++ lutinutil/src/java/org/codelutin/util/OptionArgument.java Mon Nov 19 20:47:41 2007 @@ -0,0 +1,85 @@ +/** + * ##% Copyright (C) 2002, 2007 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. ##%* + */ + +package org.codelutin.util; + +import static org.codelutin.i18n.I18n._; + +/** + * Cette classe abstraite définit le contrat à respecter pour un argument d'une + * option dans le parser de ligne de commande. + *

+ * La classe est typée par le type de retour de l'argument attendu {@link #value} + * + * @author chemit + */ +public class OptionArgument { + + /** la clef de l'argument */ + protected String key; + + /** l'argument de la ligne de commande qui a été consommé par cet argument */ + protected String arg; + + /** la valeur typée de l'argument de la ligne de commande utilisé */ + protected T value; + /** + * la position de l'argument dans l'option si c'est un argument + * d'un groupe obligatoire, sinon -1 + */ + protected int position; + + public OptionArgument(String key, int position, String arg, T value) { + this.key = key; + this.arg = arg; + this.value = value; + this.position = position; + } + + /** @return la clef de l'argument */ + public String getKey() { + return key; + } + + /** @return l'argument consommé de la ligne de commande */ + public String getArg() { + return arg; + } + + /** + * @return la valeur typée correspondant à l'argument de la ligne de + * commande + */ + public T getValue() { + return value; + } + + /** + * @return la position de l'argument dans l'option si c'est un argument + * d'un groupe obligatiore, sinon -1. + */ + public int getPosition() { + return position; + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append(_("lutinutil.parser.printDetail.argument", key, arg, value)); + if (position != -1) { + sb.append(_("lutinutil.parser.printDetail.argument.mandatory", + position)); + } + return sb.toString(); + } +}