diff --git a/public/java/src/org/broadinstitute/sting/utils/collections/LoggingNestedIntegerArray.java b/public/java/src/org/broadinstitute/sting/utils/collections/LoggingNestedIntegerArray.java index 617391714..6fda0245b 100644 --- a/public/java/src/org/broadinstitute/sting/utils/collections/LoggingNestedIntegerArray.java +++ b/public/java/src/org/broadinstitute/sting/utils/collections/LoggingNestedIntegerArray.java @@ -34,7 +34,12 @@ import java.io.PrintStream; * to the provided output stream. For testing/debugging purposes. * * Log entries are of the following form (fields are tab-separated): - * LABEL VALUE KEY1 KEY2 ... KEY_N + * LABEL OPERATION VALUE KEY1 KEY2 ... KEY_N + * + * A header line is written before the log entries giving the dimensions of this NestedIntegerArray. + * It has the form: + * + * # LABEL SIZE_OF_FIRST_DIMENSION SIZE_OF_SECOND_DIMENSION ... SIZE_OF_NTH_DIMENSION * * @author David Roazen */ @@ -43,6 +48,9 @@ public class LoggingNestedIntegerArray extends NestedIntegerArray { private PrintStream log; private String logEntryLabel; + public static final String HEADER_LINE_PREFIX = "# "; + public enum NestedIntegerArrayOperation { GET, PUT }; + /** * * @param log output stream to which to log update operations @@ -57,6 +65,37 @@ public class LoggingNestedIntegerArray extends NestedIntegerArray { } this.log = log; this.logEntryLabel = logEntryLabel != null ? logEntryLabel : ""; + + // Write the header line recording the dimensions of this NestedIntegerArray: + StringBuilder logHeaderLine = new StringBuilder(); + + logHeaderLine.append(HEADER_LINE_PREFIX); + logHeaderLine.append(this.logEntryLabel); + for ( int dimension : dimensions ) { + logHeaderLine.append("\t"); + logHeaderLine.append(dimension); + } + + this.log.println(logHeaderLine.toString()); + } + + @Override + public T get( final int... keys ) { + StringBuilder logEntry = new StringBuilder(); + + logEntry.append(logEntryLabel); + logEntry.append("\t"); + logEntry.append(NestedIntegerArrayOperation.GET); + logEntry.append("\t"); // empty field for the datum value + + for ( int key : keys ) { + logEntry.append("\t"); + logEntry.append(key); + } + + log.println(logEntry.toString()); + + return super.get(keys); } @Override @@ -67,6 +106,8 @@ public class LoggingNestedIntegerArray extends NestedIntegerArray { logEntry.append(logEntryLabel); logEntry.append("\t"); + logEntry.append(NestedIntegerArrayOperation.PUT); + logEntry.append("\t"); logEntry.append(value); for ( int key : keys ) { logEntry.append("\t");