|
From: <ls...@us...> - 2007-01-03 20:03:18
|
Revision: 2977
http://jnode.svn.sourceforge.net/jnode/?rev=2977&view=rev
Author: lsantha
Date: 2007-01-03 12:03:17 -0800 (Wed, 03 Jan 2007)
Log Message:
-----------
Moved shell related classes to shell project. Avoid fragmentation.
Added Paths:
-----------
trunk/shell/src/shell/org/jnode/shell/help/argument/HostArgument.java
trunk/shell/src/shell/org/jnode/shell/help/argument/NetworkArgument.java
Copied: trunk/shell/src/shell/org/jnode/shell/help/argument/HostArgument.java (from rev 2975, trunk/net/src/net/org/jnode/net/help/argument/HostArgument.java)
===================================================================
--- trunk/shell/src/shell/org/jnode/shell/help/argument/HostArgument.java (rev 0)
+++ trunk/shell/src/shell/org/jnode/shell/help/argument/HostArgument.java 2007-01-03 20:03:17 UTC (rev 2977)
@@ -0,0 +1,49 @@
+/*
+ * $Id: HostArgument.java 2224 2006-01-01 12:49:03Z epr $
+ *
+ * JNode.org
+ * Copyright (C) 2003-2006 JNode.org
+ *
+ * This library is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as published
+ * by the Free Software Foundation; either version 2.1 of the License, or
+ * (at your option) any later version.
+ *
+ * This library 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 Lesser General Public
+ * License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this library; If not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+package org.jnode.shell.help.argument;
+
+import org.jnode.net.ipv4.IPv4Address;
+import org.jnode.shell.help.Argument;
+import org.jnode.shell.help.ParsedArguments;
+
+/**
+ * @author qades
+ */
+public class HostArgument extends Argument {
+
+ public HostArgument(String name, String description, boolean multi) {
+ super(name, description, multi);
+ }
+
+ public HostArgument(String name, String description) {
+ super(name, description);
+ }
+
+ // here the specific command line completion would be implemented
+
+ public IPv4Address getAddress(ParsedArguments args) {
+ String value = getValue(args);
+ if( value == null )
+ return null;
+ return new IPv4Address(value);
+ }
+}
Copied: trunk/shell/src/shell/org/jnode/shell/help/argument/NetworkArgument.java (from rev 2975, trunk/net/src/net/org/jnode/net/help/argument/NetworkArgument.java)
===================================================================
--- trunk/shell/src/shell/org/jnode/shell/help/argument/NetworkArgument.java (rev 0)
+++ trunk/shell/src/shell/org/jnode/shell/help/argument/NetworkArgument.java 2007-01-03 20:03:17 UTC (rev 2977)
@@ -0,0 +1,49 @@
+/*
+ * $Id: NetworkArgument.java 2224 2006-01-01 12:49:03Z epr $
+ *
+ * JNode.org
+ * Copyright (C) 2003-2006 JNode.org
+ *
+ * This library is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as published
+ * by the Free Software Foundation; either version 2.1 of the License, or
+ * (at your option) any later version.
+ *
+ * This library 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 Lesser General Public
+ * License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this library; If not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+package org.jnode.shell.help.argument;
+
+import org.jnode.net.ipv4.IPv4Address;
+import org.jnode.shell.help.Argument;
+import org.jnode.shell.help.ParsedArguments;
+
+/**
+ * @author qades
+ */
+public class NetworkArgument extends Argument {
+
+ public NetworkArgument(String name, String description, boolean multi) {
+ super(name, description, multi);
+ }
+
+ public NetworkArgument(String name, String description) {
+ super(name, description);
+ }
+
+ // here the specific command line completion would be implemented
+
+ public IPv4Address getAddress(ParsedArguments args) {
+ String value = getValue(args);
+ if( "default".equals(value) )
+ value = "0.0.0.0";
+ return new IPv4Address(value);
+ }
+}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <ls...@us...> - 2007-01-03 20:23:54
|
Revision: 2978
http://jnode.svn.sourceforge.net/jnode/?rev=2978&view=rev
Author: lsantha
Date: 2007-01-03 12:23:46 -0800 (Wed, 03 Jan 2007)
Log Message:
-----------
Undoing last chenge.
Removed Paths:
-------------
trunk/shell/src/shell/org/jnode/shell/help/argument/HostArgument.java
trunk/shell/src/shell/org/jnode/shell/help/argument/NetworkArgument.java
Deleted: trunk/shell/src/shell/org/jnode/shell/help/argument/HostArgument.java
===================================================================
--- trunk/shell/src/shell/org/jnode/shell/help/argument/HostArgument.java 2007-01-03 20:03:17 UTC (rev 2977)
+++ trunk/shell/src/shell/org/jnode/shell/help/argument/HostArgument.java 2007-01-03 20:23:46 UTC (rev 2978)
@@ -1,49 +0,0 @@
-/*
- * $Id: HostArgument.java 2224 2006-01-01 12:49:03Z epr $
- *
- * JNode.org
- * Copyright (C) 2003-2006 JNode.org
- *
- * This library is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as published
- * by the Free Software Foundation; either version 2.1 of the License, or
- * (at your option) any later version.
- *
- * This library 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 Lesser General Public
- * License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this library; If not, write to the Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
- */
-
-package org.jnode.shell.help.argument;
-
-import org.jnode.net.ipv4.IPv4Address;
-import org.jnode.shell.help.Argument;
-import org.jnode.shell.help.ParsedArguments;
-
-/**
- * @author qades
- */
-public class HostArgument extends Argument {
-
- public HostArgument(String name, String description, boolean multi) {
- super(name, description, multi);
- }
-
- public HostArgument(String name, String description) {
- super(name, description);
- }
-
- // here the specific command line completion would be implemented
-
- public IPv4Address getAddress(ParsedArguments args) {
- String value = getValue(args);
- if( value == null )
- return null;
- return new IPv4Address(value);
- }
-}
Deleted: trunk/shell/src/shell/org/jnode/shell/help/argument/NetworkArgument.java
===================================================================
--- trunk/shell/src/shell/org/jnode/shell/help/argument/NetworkArgument.java 2007-01-03 20:03:17 UTC (rev 2977)
+++ trunk/shell/src/shell/org/jnode/shell/help/argument/NetworkArgument.java 2007-01-03 20:23:46 UTC (rev 2978)
@@ -1,49 +0,0 @@
-/*
- * $Id: NetworkArgument.java 2224 2006-01-01 12:49:03Z epr $
- *
- * JNode.org
- * Copyright (C) 2003-2006 JNode.org
- *
- * This library is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as published
- * by the Free Software Foundation; either version 2.1 of the License, or
- * (at your option) any later version.
- *
- * This library 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 Lesser General Public
- * License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this library; If not, write to the Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
- */
-
-package org.jnode.shell.help.argument;
-
-import org.jnode.net.ipv4.IPv4Address;
-import org.jnode.shell.help.Argument;
-import org.jnode.shell.help.ParsedArguments;
-
-/**
- * @author qades
- */
-public class NetworkArgument extends Argument {
-
- public NetworkArgument(String name, String description, boolean multi) {
- super(name, description, multi);
- }
-
- public NetworkArgument(String name, String description) {
- super(name, description);
- }
-
- // here the specific command line completion would be implemented
-
- public IPv4Address getAddress(ParsedArguments args) {
- String value = getValue(args);
- if( "default".equals(value) )
- value = "0.0.0.0";
- return new IPv4Address(value);
- }
-}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
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.
|
|
From: <fd...@us...> - 2007-02-11 22:29:52
|
Revision: 3122
http://jnode.svn.sourceforge.net/jnode/?rev=3122&view=rev
Author: fduminy
Date: 2007-02-11 14:29:51 -0800 (Sun, 11 Feb 2007)
Log Message:
-----------
added min/max properties for validation of int/long arguments
Modified Paths:
--------------
trunk/shell/src/shell/org/jnode/shell/help/argument/IntegerArgument.java
trunk/shell/src/shell/org/jnode/shell/help/argument/LongArgument.java
Modified: trunk/shell/src/shell/org/jnode/shell/help/argument/IntegerArgument.java
===================================================================
--- trunk/shell/src/shell/org/jnode/shell/help/argument/IntegerArgument.java 2007-02-11 22:28:59 UTC (rev 3121)
+++ trunk/shell/src/shell/org/jnode/shell/help/argument/IntegerArgument.java 2007-02-11 22:29:51 UTC (rev 3122)
@@ -27,22 +27,65 @@
/**
* @author Ewout Prangsma (ep...@us...)
+ * @author Fabien DUMINY (fduminy at jnode.org)
+ *
+ * TODO should be factorized with LongArgument
*/
public class IntegerArgument extends Argument {
+ private int min;
+ private int max;
+ public IntegerArgument(String name, String description) {
+ this(name, description, SINGLE);
+ }
+
public IntegerArgument(String name, String description, boolean multi) {
- super(name, description, multi);
+ this(name, description, multi, Integer.MIN_VALUE, Integer.MAX_VALUE);
}
- public IntegerArgument(String name, String description) {
- super(name, description);
+ public IntegerArgument(String name, String description, boolean multi, int min, int max) {
+ super(name, description, multi);
+ if(min > max)
+ {
+ throw new IllegalArgumentException("min(value:"+min+") > max(value:"+max+")");
+ }
+
+ this.min = min;
+ this.max = max;
}
-
+
public String complete(String partial) {
return partial;
+ }
+
+ @Override
+ protected boolean isValidValue(String value) {
+ int val = -1;
+ try {
+ val = getIntValue(value);
+ } catch (NumberFormatException e) {
+ return false;
+ }
+
+ if(val < min)
+ {
+ return false;
+ }
+
+ if(val > max)
+ {
+ return false;
+ }
+
+ return true;
}
public int getInteger(ParsedArguments args) {
- return Integer.parseInt(this.getValue(args));
+ return getIntValue(this.getValue(args));
}
+
+ protected int getIntValue(String value)
+ {
+ return Integer.parseInt(value);
+ }
}
Modified: trunk/shell/src/shell/org/jnode/shell/help/argument/LongArgument.java
===================================================================
--- trunk/shell/src/shell/org/jnode/shell/help/argument/LongArgument.java 2007-02-11 22:28:59 UTC (rev 3121)
+++ trunk/shell/src/shell/org/jnode/shell/help/argument/LongArgument.java 2007-02-11 22:29:51 UTC (rev 3122)
@@ -27,21 +27,68 @@
/**
* @author Ewout Prangsma (ep...@us...)
*/
+/**
+ * @author Ewout Prangsma (ep...@us...)
+ * @author Fabien DUMINY (fduminy at jnode.org)
+ *
+ * TODO should be factorized with IntegerArgument
+ */
public class LongArgument extends Argument {
-
- public LongArgument(String name, String description, boolean multi) {
- super(name, description, multi);
- }
+ private long min;
+ private long max;
+
+ public LongArgument(String name, String description) {
+ this(name, description, SINGLE);
+ }
- public LongArgument(String name, String description) {
- super(name, description);
- }
+ public LongArgument(String name, String description, boolean multi) {
+ this(name, description, multi, Long.MIN_VALUE, Long.MAX_VALUE);
+ }
- public String complete(String partial) {
- return partial;
- }
-
- public long getLong(ParsedArguments args) {
- return Long.parseLong(this.getValue(args));
- }
+ public LongArgument(String name, String description, boolean multi,
+ long min, long max) {
+ super(name, description, multi);
+ if(min > max)
+ {
+ throw new IllegalArgumentException("min(value:"+min+") > max(value:"+max+")");
+ }
+
+ this.min = min;
+ this.max = max;
+ }
+
+ public String complete(String partial) {
+ return partial;
+ }
+
+ @Override
+ protected boolean isValidValue(String value) {
+ long val = -1;
+ try {
+ val = getLongValue(value);
+ } catch (NumberFormatException e) {
+ return false;
+ }
+
+ if(val < min)
+ {
+ return false;
+ }
+
+ if(val > max)
+ {
+ return false;
+ }
+
+ return true;
+ }
+
+ public long getLong(ParsedArguments args) {
+ return getLongValue(this.getValue(args));
+ }
+
+ protected long getLongValue(String value)
+ {
+ return Long.parseLong(value);
+ }
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|