Kevin Archie avatar Kevin Archie committed 09af467

MainHeader checks for ECAT magic; MatrixData now Comparable

Comments (0)

Files changed (2)

ecat-io/src/main/java/org/nrg/ecat/MainHeader.java

  *
  */
 public final class MainHeader implements Header {
+	private static final String ECAT_MAGIC = "MATRIX7";
+	
 	private final SortedMap values;
 	
 	public MainHeader(final InputStream in) throws IOException {
 		final SortedMap m = new TreeMap();
-		for (final Iterator vi = allVariables.iterator(); vi.hasNext(); ) {
+		final Iterator vi = allVariables.iterator();
+		
+		// First variable is (or should be) ECAT magic
+		final Variable magicv = (Variable)vi.next();
+		assert MAGIC_NUMBER == magicv;
+		final String magic = (String)magicv.readValue(in);
+		if (!magic.startsWith(ECAT_MAGIC)) {
+			throw new IOException("Data not in ECAT format");
+		}
+		
+		while (vi.hasNext()) {
 			final Variable v = (Variable)vi.next();
 			m.put(v, v.readValue(in));
 		}

ecat-io/src/main/java/org/nrg/ecat/MatrixData.java

 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Collections;
+import java.util.Date;
 import java.util.HashMap;
 import java.util.Iterator;
 import java.util.LinkedHashMap;
  * @author Kevin A. Archie <karchie@npg.wustl.edu>
  *
  */
-public class MatrixData {	// TODO: implements Comparable
+public class MatrixData implements Comparable {
 	private final static int BLOCK_SIZE = 512;
 	private final Map values;
 	private final MainHeader mainHeader;
 		this(in, Collections.EMPTY_MAP);
 	}
 	
+	/**
+	 * Implementation for Comparable<MatrixData>
+	 * @param o MatrixData to which this should be compared
+	 * @return @see {@link java.lang.Comparable#compareTo(Object)}
+	 */
+	public int compareTo(final MatrixData o) {
+		final Date d1 = (Date)getMainHeader().getValue(MainHeader.SCAN_START_TIME);
+		final Date d2 = (Date)o.getMainHeader().getValue(MainHeader.SCAN_START_TIME);
+		return d1.compareTo(d2);
+	}
+	
+	/*
+	 * (non-Javadoc)
+	 * @see java.lang.Comparable#compareTo(java.lang.Object)
+	 */
+	public int compareTo(final Object o) {
+		return compareTo((MatrixData)o);
+	}
 
+	
 	private static Map arrangeRequestedVars(final Collection requestedVars) {
 		final Map m = new HashMap();
 		for (final Iterator i = requestedVars.iterator(); i.hasNext(); ) {
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 ProjectModifiedEvent.java.
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.