Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a reset() method to ProgressLoggerInterface. #1184

Merged
merged 2 commits into from
Oct 5, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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. */
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In general, you want the javadoc on the baseclass or interface, so it's inherited by all subclassers and so a user can see the javadoc when dealing with the interface type.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed, but I am going to pass on this change to be consistent with how ProgressLoggerInterface currently is written.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree with @pshapiro4broad but lets handle that separately.

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);

void reset();
}