Skip to content

Commit

Permalink
Add a reset() method to ProgressLoggerInterface. (#1184)
Browse files Browse the repository at this point in the history
* Add a reset() method to ProgressLoggerInterface
* The default implementation of reset() is a no-op.
  • Loading branch information
nh13 authored and lbergelson committed Oct 5, 2018
1 parent 49c70e5 commit a7214ca
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
22 changes: 16 additions & 6 deletions src/main/java/htsjdk/samtools/util/AbstractProgressLogger.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,13 @@ abstract public class AbstractProgressLogger implements ProgressLoggerInterface
private final int n;
private final String verb;
private final String noun;
private final long startTime = System.currentTimeMillis();
private long startTime;
private final NumberFormat fmt = new DecimalFormat("#,###");
private final NumberFormat timeFmt = new DecimalFormat("00");
private long processed = 0;
// Set to -1 until the first record is added
private long lastStartTime = -1;
private String lastChrom = null;
private int lastPos = 0;
private long processed;
private long lastStartTime;
private String lastChrom;
private int lastPos;

/**
* Construct an AbstractProgressLogger.
Expand All @@ -37,6 +36,7 @@ protected AbstractProgressLogger(final String noun, final String verb, final int
this.noun = noun;
this.verb = verb;
this.n = n;
reset();
}

/**
Expand Down Expand Up @@ -124,6 +124,16 @@ public boolean record(final SAMRecord... recs) {
/** Returns the number of seconds since progress tracking began. */
public long getElapsedSeconds() { return (System.currentTimeMillis() - this.startTime) / 1000; }

/** Resets the start time to now and the number of records to zero. */
public void reset() {
startTime = System.currentTimeMillis();
processed = 0;
// Set to -1 until the first record is added
lastStartTime = -1;
lastChrom = null;
lastPos = 0;
}

/** Left pads a string until it is at least the given length. */
private String pad (String in, final int length) {
while (in.length() < length) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,5 @@ public interface ProgressLoggerInterface {
boolean record(final String chrom, final int pos);
boolean record(final SAMRecord rec);
boolean record(final SAMRecord... recs);

default void reset() {};
}

0 comments on commit a7214ca

Please sign in to comment.