Index: lutinutil/src/java/org/codelutin/util/OptionGroupDefinition.java diff -u /dev/null lutinutil/src/java/org/codelutin/util/OptionGroupDefinition.java:1.1 --- /dev/null Sun Dec 16 22:27:29 2007 +++ lutinutil/src/java/org/codelutin/util/OptionGroupDefinition.java Sun Dec 16 22:27:24 2007 @@ -0,0 +1,81 @@ +/** + * ##% 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 org.codelutin.util.OptionParserAnnotationHelper.*; + +/** + * Cette classe représente la définition d'un groupe d'arguments d'une option. + *

+ * Elle comprend : + *

+ * De manière générale cette classe ne doit pas être instanciée directement, + * cela est fait automatiquement lors du parsing de la définition de l'option + * par le parseur ou dans les factory de définitions. + *

+ * Pour l'instant les cardinalités sur groupe se limite à {0,1} : facultatif, + * et {1,1} obligatoire exacement une fois. + *

+ * Il suffira de modifier les algorithmes des parseurs pour intégrer la gestion + * des cardinalités sur les groupes d'arguments d'option. A faire. + * + * @author chemit + */ +public class OptionGroupDefinition { + + public static final int OPTIONAL_POSITION = -1; + + /** la position du groupe d'argument dans l'option si obligatoire, -1 sinon */ + protected int pos; + + /** la liste de tous les argument du groupe */ + protected OptionArgumentDefinition[] arguments; + + protected OptionGroupDefinition(int pos,OptionArgumentDefinition[] arguments) { + this.pos = pos; + this.arguments = arguments; + } + + public OptionGroupDefinition(GroupA definition) { + this.pos = definition.pos(); + ArgumentA[] argumentDefinitions = definition.args(); + this.arguments = new OptionArgumentDefinition[argumentDefinitions.length]; + for (int i = 0; i < argumentDefinitions.length; i++) { + this.arguments[i] = new OptionArgumentDefinition(argumentDefinitions[i]); + } + } + + public int getPos() { + return pos; + } + + public boolean isMandatory() { + return pos != OPTIONAL_POSITION; + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + StringBuffer s = new StringBuffer(); + for (OptionArgumentDefinition argument : arguments) { + s.append('|').append(argument); + } + String s1 = s.toString(); + StringUtil.printCardinalite(sb, s1.length() > 0 ? s1.substring(1) : s1, isMandatory()?1:0, 1, isMandatory(),"<",">","[","]"); + return sb.toString(); + } + +} \ No newline at end of file