package com.cookpad.android.puree.retryable;

import android.os.Handler;

public class RetryableTaskRunner {
    private Handler handler;
    private boolean hasAlreadySet;
    private Runnable callback;
    private BuckoffCounter buckoffCounter;

    public RetryableTaskRunner(final Runnable task, final int interval) {
        this.buckoffCounter = new BuckoffCounter(interval);
        this.handler = new Handler();
        this.hasAlreadySet = false;

        this.callback = new Runnable() {
            @Override
            public void run() {
                task.run();
            }
        };
    }

    public synchronized void tryToStart() {
        if (hasAlreadySet) {
            return;
        }
        buckoffCounter.resetRetryCount();
        startDelayed();
    }

    private synchronized void startDelayed() {
        handler.removeCallbacks(callback);
        handler.postDelayed(callback, buckoffCounter.time());
        hasAlreadySet = true;
    }

    public synchronized void reset() {
        hasAlreadySet = false;
        buckoffCounter.resetRetryCount();
    }

    public synchronized void retryLater() {
        buckoffCounter.incrementRetryCount();
        startDelayed();
    }
}

@@ -162,18 +162,22 @@
 AlreadyS
-e
 t
+arted
 ;%0A    pr
@@ -433,34 +433,38 @@
 this.hasAlreadyS
-e
 t
+arted
  = false;%0A%0A     
@@ -680,18 +680,22 @@
 AlreadyS
-e
 t
+arted
 ) %7B%0A    
@@ -964,18 +964,22 @@
 AlreadyS
-e
 t
+arted
  = true;
@@ -1044,18 +1044,22 @@
 AlreadyS
-e
 t
+arted
  = false

Rename field `hasAlreadySet` -> `hasAlreadyStarted`