Vincent Fiack committed f5fcf5c

DeclareList can declare a prepopulated list, with varargs

Comments (0)

Files changed (1)


 import org.blocks.runtime.Slot;
 import org.blocks.runtime.Types;
 import org.blocks.runtime.ExecutionContext;
+import org.blocks.runtime.parameters.VarargsParameter;
+import org.blocks.runtime.parameters.Parameter;
 import org.blocks.exceptions.BlocksValidationException;
 import org.blocks.exceptions.BlocksRuntimeException;
 import java.util.ArrayList;
+import java.util.List;
+import java.util.Collections;
 public class DeclareList extends JavaBlock {
 	public DeclareList() throws BlocksValidationException {
         setDescription("Declare a new list");
         addSlot(new Slot("varname", Types.TEXT));
-	}
+        addSlot(new Slot(VarargsParameter.SLOT_NAME, Types.ANY, true));
+    }
-	public Object run(ExecutionContext context)
+    @SuppressWarnings("unchecked")
+    public Object run(ExecutionContext context)
 	throws BlocksRuntimeException {
 		String name = context.lookupText("varname");
-        Object value = new ArrayList();
+        List list = new ArrayList();
+        //map parameters to java
+        List<Parameter> varargs = (List<Parameter>)context.lookup(VarargsParameter.SLOT_NAME);
+        if(varargs != null) {
+            for(Parameter parameter: varargs) {
+                list.add(parameter.getJavaObject(context));
+            }
+        }
-        context.setVariable(name, value);
-		return value;
+        context.setVariable(name, list);
+		return list;
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.