From: <fd...@us...> - 2007-02-11 22:28:12
|
Revision: 3120 http://jnode.svn.sourceforge.net/jnode/?rev=3120&view=rev Author: fduminy Date: 2007-02-11 14:28:11 -0800 (Sun, 11 Feb 2007) Log Message: ----------- reworked Argument whith small set of possible values around the class ListArgument Modified Paths: -------------- trunk/shell/src/shell/org/jnode/shell/help/argument/CountryArgument.java trunk/shell/src/shell/org/jnode/shell/help/argument/LanguageArgument.java trunk/shell/src/shell/org/jnode/shell/help/argument/StringListArgument.java Modified: trunk/shell/src/shell/org/jnode/shell/help/argument/CountryArgument.java =================================================================== --- trunk/shell/src/shell/org/jnode/shell/help/argument/CountryArgument.java 2007-02-11 22:25:20 UTC (rev 3119) +++ trunk/shell/src/shell/org/jnode/shell/help/argument/CountryArgument.java 2007-02-11 22:28:11 UTC (rev 3120) @@ -22,6 +22,7 @@ package org.jnode.shell.help.argument; import java.util.Arrays; +import java.util.Collection; import java.util.List; import java.util.Locale; @@ -34,11 +35,15 @@ .getISOCountries()); public CountryArgument(String name, String description, boolean multi) { - super(name, description, multi, validCountries); + super(name, description, multi); } public CountryArgument(String name, String description) { - super(name, description, validCountries); + super(name, description); } + @Override + protected Collection<String> getValues() { + return validCountries; + } } Modified: trunk/shell/src/shell/org/jnode/shell/help/argument/LanguageArgument.java =================================================================== --- trunk/shell/src/shell/org/jnode/shell/help/argument/LanguageArgument.java 2007-02-11 22:25:20 UTC (rev 3119) +++ trunk/shell/src/shell/org/jnode/shell/help/argument/LanguageArgument.java 2007-02-11 22:28:11 UTC (rev 3120) @@ -22,6 +22,7 @@ package org.jnode.shell.help.argument; import java.util.Arrays; +import java.util.Collection; import java.util.List; import java.util.Locale; @@ -33,11 +34,15 @@ private static final List<String> languages = Arrays.asList(Locale.getISOLanguages()); public LanguageArgument(String name, String description, boolean multi) { - super(name, description, multi, languages); + super(name, description, multi); } public LanguageArgument(String name, String description) { - super(name, description, languages); + super(name, description); } + @Override + protected Collection<String> getValues() { + return languages; + } } Modified: trunk/shell/src/shell/org/jnode/shell/help/argument/StringListArgument.java =================================================================== --- trunk/shell/src/shell/org/jnode/shell/help/argument/StringListArgument.java 2007-02-11 22:25:20 UTC (rev 3119) +++ trunk/shell/src/shell/org/jnode/shell/help/argument/StringListArgument.java 2007-02-11 22:28:11 UTC (rev 3120) @@ -1,50 +1,41 @@ package org.jnode.shell.help.argument; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; -import java.util.List; +import java.util.Collection; -import org.jnode.shell.help.Argument; +import org.jnode.shell.help.ParsedArguments; -public class StringListArgument extends Argument { - - private final List<String> choices; - - public StringListArgument(String name, String description, boolean multi, List<String> choices) { +abstract public class StringListArgument extends ListArgument<String> +{ + public StringListArgument(String name, String description, boolean multi) { super(name, description, multi); - this.choices = choices; } - public StringListArgument(String name, String description, List<String> choices) { - this(name, description, false, choices); + public StringListArgument(String name, String description) { + super(name, description, false); } - public StringListArgument(String name, String description, boolean multi, String[] choices) { - this(name, description, multi, Arrays.asList(choices)); + @Override + public String getArgValue(String value) { + return value; } - - public StringListArgument(String name, String description, String[] choices) { - this(name, description, false, choices); + + @Override + protected String toStringArgument(String arg) + { + return arg; } - - public String complete(String partial) { - final List<String> result = new ArrayList<String>(); - for (String choice : choices) { - if (choice.startsWith(partial)) { - result.add(choice); - } - } - - Collections.sort(result); - return complete(partial, result); + + @Override + protected boolean isPartOfArgument(String argument, String part) + { + return argument.startsWith(part); } - - protected boolean isValidValue(String choice) { - if ((choice == null) || "".equals(choice)) - return true; - - return choices.contains(choice); + + @Override + public int compare(String choice1, String choice2) + { + return choice1.compareTo(choice2); } + abstract protected Collection<String> getValues(); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |