[Swift-commit] r2726 - trunk/src/org/griphyn/vdl/karajan/lib

noreply at svn.ci.uchicago.edu noreply at svn.ci.uchicago.edu
Sun Mar 22 07:38:06 CDT 2009


Author: benc
Date: 2009-03-22 07:38:06 -0500 (Sun, 22 Mar 2009)
New Revision: 2726

Modified:
   trunk/src/org/griphyn/vdl/karajan/lib/Range.java
Log:
backout r2674, as it breaks some basic array related behaviour

Modified: trunk/src/org/griphyn/vdl/karajan/lib/Range.java
===================================================================
--- trunk/src/org/griphyn/vdl/karajan/lib/Range.java	2009-03-22 12:37:09 UTC (rev 2725)
+++ trunk/src/org/griphyn/vdl/karajan/lib/Range.java	2009-03-22 12:38:06 UTC (rev 2726)
@@ -3,24 +3,13 @@
  */
 package org.griphyn.vdl.karajan.lib;
 
-import java.util.AbstractMap;
-import java.util.AbstractSet;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.Iterator;
-import java.util.Map;
-import java.util.Set;
-
 import org.globus.cog.karajan.arguments.Arg;
 import org.globus.cog.karajan.stack.VariableStack;
 import org.globus.cog.karajan.workflow.ExecutionException;
 import org.griphyn.vdl.mapping.AbstractDataNode;
 import org.griphyn.vdl.mapping.DSHandle;
-import org.griphyn.vdl.mapping.HandleOpenException;
-import org.griphyn.vdl.mapping.InvalidPathException;
 import org.griphyn.vdl.mapping.Path;
 import org.griphyn.vdl.mapping.RootArrayDataNode;
-import org.griphyn.vdl.mapping.RootDataNode;
 import org.griphyn.vdl.type.Type;
 import org.griphyn.vdl.type.Types;
 
@@ -33,113 +22,27 @@
 		setArguments(Range.class, new Arg[] { PA_FROM, PA_TO, OA_STEP });
 	}
 
-	public Object function(final VariableStack stack) throws ExecutionException {
+	public Object function(VariableStack stack) throws ExecutionException {
 		// TODO: deal with expression
-		final Type type = PA_FROM.getType(stack);
-		final double start = PA_FROM.getDoubleValue(stack);
-		final double stop = PA_TO.getDoubleValue(stack);
-		final double incr = OA_STEP.getDoubleValue(stack);
+		Type type = PA_FROM.getType(stack);
+		double start = PA_FROM.getDoubleValue(stack);
+		double stop = PA_TO.getDoubleValue(stack);
+		double incr = OA_STEP.getDoubleValue(stack);
 
 		// only deal with int and float
 		try {
-			final AbstractDataNode handle;
+			AbstractDataNode handle;
 
-			handle = new RootArrayDataNode(type.arrayType()) {
-				final DSHandle h = this;
-				
-				public Collection getFields(Path path)
-						throws InvalidPathException, HandleOpenException {
-					if (path.size() > 1) {
-						throw new InvalidPathException(path, this);
-					}
-					else if (path.equals(Path.EMPTY_PATH)) {
-						return Collections.singletonList(this);
-					}
-					else {
-						int index = Integer.parseInt(path.getFirst());
-						DSHandle value = new RootDataNode(type);
-						value.init(null);
-						value.setValue(new Double(start + incr * index));
-						value.closeShallow();
-						return Collections.singletonList(value);
-					}
-				}
+			handle = new RootArrayDataNode(type.arrayType());
+			int index = 0;
+			for (double v = start; v <= stop; v += incr, index++) {
+				Path path = Path.EMPTY_PATH.addLast(String.valueOf(index), true);
+				DSHandle field = handle.getField(path);
+				field.setValue(new Double(v));
+				closeShallow(stack, field);
+			}
 
-				public Map getArrayValue() {
-					return new AbstractMap() {
-						public Set entrySet() {
-							return new AbstractSet() {
-								public Iterator iterator() {
-									return new Iterator() {
-										private double crt = start;
-										private int index = 0;
-										
-										public boolean hasNext() {
-											return crt <= stop;
-										}
-
-										public Object next() {
-											try {
-												Map.Entry e = new Map.Entry() {
-													private DSHandle value;
-													private int key;
-													
-													{
-														value = new RootDataNode(type);
-														value.init(null);
-														value.setValue(new Double(crt));
-														value.closeShallow();
-														key = index;
-													}
-
-													public Object getKey() {
-														return new Double(key);
-													}
-
-													public Object getValue() {
-														return value;
-													}
-
-													public Object setValue(Object value) {
-														throw new UnsupportedOperationException();
-													}
-												};
-												index++;
-												crt += incr;
-												if (crt > stop) {
-													VDLFunction.closeShallow(stack, h);
-												}
-												return e;
-											}
-											catch (Exception e) {
-												throw new RuntimeException(e);
-											}
-										}
-
-										public void remove() {
-											throw new UnsupportedOperationException();
-										}
-									};
-								}
-
-								public int size() {
-									return (int) ((stop - start) / incr);
-								}								
-							};
-						}
-					};
-				}
-
-				public boolean isClosed() {
-					//the need for this lie arises from:
-					//1. adding fields to a truly closed array throws an exception
-					//2. this is a lazy array not a future array. Consequently, we 
-					//   want the consumer(s) of this array to think that all values
-					//   in the array are available
-					return true;
-				}
-				
-			};
+			closeShallow(stack, handle);
 			return handle;
 		}
 		catch (Exception e) {




More information about the Swift-commit mailing list