[Swift-commit] r6057 - trunk/src/org/griphyn/vdl/mapping/file

hategan at ci.uchicago.edu hategan at ci.uchicago.edu
Sun Nov 18 02:44:53 CST 2012


Author: hategan
Date: 2012-11-18 02:44:46 -0600 (Sun, 18 Nov 2012)
New Revision: 6057

Modified:
   trunk/src/org/griphyn/vdl/mapping/file/FixedArrayFileMapper.java
Log:
fixed fixed_array_mapper

Modified: trunk/src/org/griphyn/vdl/mapping/file/FixedArrayFileMapper.java
===================================================================
--- trunk/src/org/griphyn/vdl/mapping/file/FixedArrayFileMapper.java	2012-11-18 07:41:37 UTC (rev 6056)
+++ trunk/src/org/griphyn/vdl/mapping/file/FixedArrayFileMapper.java	2012-11-18 08:44:46 UTC (rev 6057)
@@ -18,23 +18,31 @@
 package org.griphyn.vdl.mapping.file;
 
 import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.Collection;
+import java.util.Iterator;
 import java.util.List;
+import java.util.Map;
+import java.util.Set;
 import java.util.StringTokenizer;
+import java.util.TreeSet;
 
 import org.griphyn.vdl.mapping.AbsFile;
 import org.griphyn.vdl.mapping.AbstractMapper;
+import org.griphyn.vdl.mapping.DSHandle;
 import org.griphyn.vdl.mapping.InvalidMappingParameterException;
 import org.griphyn.vdl.mapping.MappingParam;
 import org.griphyn.vdl.mapping.MappingParamSet;
 import org.griphyn.vdl.mapping.Path;
 import org.griphyn.vdl.mapping.PhysicalFormat;
+import org.griphyn.vdl.type.Types;
 
 
 /** Maps a string (separated by space, comma or semicolon) of filenames to
     an array. */
 public class FixedArrayFileMapper extends AbstractMapper {
 	public static final MappingParam PARAM_FILES = new MappingParam("files");
+	private List<String> files;
 
 	public FixedArrayFileMapper() {
 		super();
@@ -42,26 +50,42 @@
 
 	public void setParams(MappingParamSet params) {
 		super.setParams(params);
-		String cfiles = PARAM_FILES.getStringValue(this);
-		if (cfiles == null) {
-			throw new InvalidMappingParameterException("Missing required mapper parameter: "
-					+ PARAM_FILES);
+		DSHandle dn = (DSHandle) PARAM_FILES.getRawValue(this);
+		if (dn == null) {
+		    throw new InvalidMappingParameterException("Missing required mapper parameter: "
+                    + PARAM_FILES);
 		}
-		StringTokenizer st = new StringTokenizer(cfiles, " ,;");
-		String[] files = new String[st.countTokens()];
-		for (int i = 0; st.hasMoreTokens(); i++) {
-			files[i] = st.nextToken();
+		if (Types.STRING.equals(dn.getType())) {
+		    String cfiles = (String) dn.getValue();
+        
+            StringTokenizer st = new StringTokenizer(cfiles, " ,;");
+            String[] files = new String[st.countTokens()];
+            for (int i = 0; st.hasMoreTokens(); i++) {
+                files[i] = st.nextToken();
+            }
+            this.files = Arrays.asList(files);
 		}
-		PARAM_FILES.setValue(this, files);
+		else if (dn.getType().isArray() && Types.STRING.equals(dn.getType().itemType())) {
+		    files = new ArrayList<String>();
+            Map<?, DSHandle> m = dn.getArrayValue();
+            // must keep order
+            @SuppressWarnings("unchecked")
+            Set<Comparable<?>> s = new TreeSet<Comparable<?>>((Set<Comparable<?>>) m.keySet());
+            Iterator<?> i = s.iterator();
+            while(i.hasNext()) {
+                Comparable<?> nextKey = (Comparable<?>) i.next();
+                files.add((String) m.get(nextKey).getValue());
+            }
+		}
+		else {
+		    throw new InvalidMappingParameterException("Unrecognized value for "
+                    + PARAM_FILES + " parameter: " + dn.getType() + ". Valid values are a string or an array of strings.");
+		}
 	}
 
-	protected String[] getFiles() {
-		return (String[]) PARAM_FILES.getValue(this);
-	}
-
 	public Collection<Path> existing() {
 		List<Path> l = new ArrayList<Path>();
-		for (int i = 0; i < getFiles().length; i++) {
+		for (int i = 0; i < files.size(); i++) {
 			l.add(Path.EMPTY_PATH.addLast(i, true));
 		}
 		return l;
@@ -75,7 +99,7 @@
 		    Object o = path.getFirst();
 		    if (o instanceof Integer) {
 		        int index = ((Integer) o).intValue();
-		        return new AbsFile(getFiles()[index]);
+		        return new AbsFile(files.get(index));
 		    }
 		    else {
 		        throw new IllegalArgumentException("The fixed array mapper can only be used with an int key array");




More information about the Swift-commit mailing list