Skip to content

Instantly share code, notes, and snippets.

@adamv
Created February 7, 2012 18:50
Show Gist options
  • Save adamv/1761199 to your computer and use it in GitHub Desktop.
Save adamv/1761199 to your computer and use it in GitHub Desktop.
public class RetryCounter {
private final int maxAttempts;
private int attempts;
private boolean successful;
public RetryCounter(final int maxAttempts) {
this.maxAttempts = maxAttempts;
this.attempts = 0;
this.successful = false;
}
public void attempt(final boolean wasSuccessful) {
this.attempts++;
this.successful = wasSuccessful;
}
public boolean shouldTryAgain() {
return !successful && attempts < maxAttempts;
}
public boolean wasSuccessful() {
return successful;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment