Index: lutinutil/src/java/org/codelutin/util/Option.java diff -u lutinutil/src/java/org/codelutin/util/Option.java:1.2 lutinutil/src/java/org/codelutin/util/Option.java:1.3 --- lutinutil/src/java/org/codelutin/util/Option.java:1.2 Wed Nov 28 01:27:24 2007 +++ lutinutil/src/java/org/codelutin/util/Option.java Wed Nov 28 17:18:40 2007 @@ -17,11 +17,12 @@ *@author Benjamin Poussin * * Copyright Code Lutin - *@version $Revision: 1.2 $ Mise a jour: $Date: 2007-11-28 01:27:24 $ par : $Author: tchemit $ + *@version $Revision: 1.3 $ Mise a jour: $Date: 2007-11-28 17:18:40 $ par : $Author: tchemit $ */ package org.codelutin.util; +import java.lang.reflect.Array; import java.util.ArrayList; import java.util.Arrays; import java.util.List; @@ -35,9 +36,9 @@ */ public class Option { // Option + /** la clef de cette option */ protected final OptionKeyFactory.OptionKey key; - /** L'alias utilisé sur la ligne de commande pour cette option */ protected final String usedAlias; @@ -86,10 +87,22 @@ return result.toArray(new OptionKeyFactory.OptionArgumentKey[result.size()]); } + public String getConstantArgumentValue(int position) { + for (OptionArgument argument : arguments) { + if (argument.getPosition() == position && argument.definition.getType() == OptionArgumentType.constant) { + return (String) argument.getValue(); + } + } + return null; + } + @SuppressWarnings({"unchecked"}) - public T getArgumentValue(OptionKeyFactory.OptionArgumentKey key) { + public T getValuedArgumentValue(int position, Class clazz) { for (OptionArgument argument : arguments) { - if (argument.getKey().equals(key)) { + if (argument.getPosition() == position + && argument.definition.getType() == OptionArgumentType.valued + && argument.definition.getValueType().getClazz() == clazz) { + return (T) argument.getValue(); } } @@ -97,25 +110,48 @@ } @SuppressWarnings({"unchecked"}) - public T[] getArgumentValues(OptionKeyFactory.OptionArgumentKey key) { - java.util.List result = new ArrayList(); + public T getNamedAndValuedArgumentValue(int position, String key, Class clazz) { for (OptionArgument argument : arguments) { - if (argument.getKey().equals(key)) { + if (argument.getPosition() == position + && argument.definition.getType() == OptionArgumentType.namedAndValued + && argument.definition.getKey().equals(key) + && argument.definition.getValueType().getClazz() == clazz) { + + return (T) argument.getValue(); + } + } + return null; + } + + @SuppressWarnings({"unchecked"}) + public T[] getValuedArgumentValues(int position, Class clazz) { + List result = new ArrayList(); + for (OptionArgument argument : arguments) { + if (argument.getPosition() == position + && argument.definition.getType() == OptionArgumentType.valued + && argument.definition.getValueType().getClazz() == clazz) { + result.add((T) argument.getValue()); } } - return (T[]) result.toArray(); + T[] r = (T[]) Array.newInstance(clazz, result.size()); + return result.toArray(r); } - + @SuppressWarnings({"unchecked"}) - protected OptionArgument[] getArguments(OptionKeyFactory.OptionArgumentKey key) { - java.util.List> result = new ArrayList>(); + public T[] getNamedAndValuedArgumentValues(int position, String key, Class clazz) { + List result = new ArrayList(); for (OptionArgument argument : arguments) { - if (argument.getKey().equals(key)) { - result.add(argument); + if (argument.getPosition() == position + && argument.definition.getType() == OptionArgumentType.namedAndValued + && argument.definition.getKey().equals(key) + && argument.definition.getValueType().getClazz() == clazz) { + + result.add((T) argument.getValue()); } } - return result.toArray(new OptionArgument[result.size()]); + T[] r = (T[]) Array.newInstance(clazz, result.size()); + return result.toArray(r); } @Override