diff dwtx/core/commands/ParameterizedCommand.d @ 71:4878bef4a38e

Some fixing
author Frank Benoit <benoit@tionex.de>
date Thu, 22 May 2008 04:03:58 +0200
parents 46a6e0e6ccd4
children 04b47443bb01
line wrap: on
line diff
--- a/dwtx/core/commands/ParameterizedCommand.d	Thu May 22 01:36:46 2008 +0200
+++ b/dwtx/core/commands/ParameterizedCommand.d	Thu May 22 04:03:58 2008 +0200
@@ -29,16 +29,18 @@
 import tango.util.collection.HashSet;
 import tango.util.collection.HashMap;
 
+import dwtx.core.commands.AbstractParameterValueConverter;
 import dwtx.core.commands.Command;
 import dwtx.core.commands.CommandManager;
 import dwtx.core.commands.IParameter;
 import dwtx.core.commands.IParameterValues;
+import dwtx.core.commands.ParameterType;
 import dwtx.core.commands.Parameterization;
 import dwtx.core.commands.ParameterValuesException;
+import dwtx.core.commands.ParameterValueConversionException;
 import dwtx.core.commands.ExecutionEvent;
 import dwtx.core.commands.common.NotDefinedException;
 import dwtx.core.internal.commands.util.Util;
-
 import dwt.dwthelper.utils;
 import tango.text.convert.Format;
 
@@ -320,7 +322,7 @@
     /**
      * Take a command and a map of parameter IDs to values, and generate the
      * appropriate parameterized command.
-     * 
+     *
      * @param command
      *            The command object. Must not be <code>null</code>.
      * @param parameters
@@ -331,19 +333,17 @@
      * @since 3.4
      */
     public static final ParameterizedCommand generateCommand(Command command,
-            Map parameters) {
+            Map!(String,Object) parameters) {
         // no parameters
-        if (parameters is null || parameters.isEmpty()) {
+        if (parameters is null || parameters.drained()) {
             return new ParameterizedCommand(command, null);
         }
 
         try {
-            ArrayList parms = new ArrayList();
-            Iterator i = parameters.keySet().iterator();
+            Parameterization[] parms;
 
             // iterate over given parameters
-            while (i.hasNext()) {
-                String key = (String) i.next();
+            foreach( key, value; parameters ){
                 IParameter parameter = null;
                 // get the parameter from the command
                 parameter = command.getParameter(key);
@@ -354,26 +354,24 @@
                 }
                 ParameterType parameterType = command.getParameterType(key);
                 if (parameterType is null) {
-                    parms.add(new Parameterization(parameter,
-                            (String) parameters.get(key)));
+                    parms ~= new Parameterization(parameter,
+                            stringcast(value) );
                 } else {
                     AbstractParameterValueConverter valueConverter = parameterType
                             .getValueConverter();
                     if (valueConverter !is null) {
-                        String val = valueConverter.convertToString(parameters
-                                .get(key));
-                        parms.add(new Parameterization(parameter, val));
+                        String val = valueConverter.convertToString(value);
+                        parms ~= new Parameterization(parameter, val);
                     } else {
-                        parms.add(new Parameterization(parameter,
-                                (String) parameters.get(key)));
+                        parms ~= new Parameterization(parameter,
+                                stringcast(value));
                     }
                 }
             }
 
             // convert the parameters to an Parameterization array and create
             // the command
-            return new ParameterizedCommand(command, (Parameterization[]) parms
-                    .toArray(new Parameterization[parms.size()]));
+            return new ParameterizedCommand(command, parms );
         } catch (NotDefinedException e) {
         } catch (ParameterValueConversionException e) {
         }
@@ -431,7 +429,7 @@
             for (int j = 0; j < parms.length; j++) {
                 for (int i = 0; i < parameterizations.length; i++) {
                     Parameterization pm = parameterizations[i];
-                    if (parms[j].equals(pm.getParameter())) {
+                    if ((cast(Object)parms[j]).opEquals(cast(Object)pm.getParameter())) {
                         params[parmIndex++] = pm;
                     }
                 }
@@ -629,7 +627,7 @@
 
     /*
      * (non-Javadoc)
-     * 
+     *
      * @see java.lang.Object#hashCode()
      */
     public override final hash_t toHash() {