package com.novoda.downloadmanager;

import com.novoda.notils.logger.simple.Log;

class WaitForLockRunnable {

    interface Action {
        void performAction();
    }

    static WaitForLockAndThenPerformActionRunnable waitFor(Object lock) {
        return new WaitForLockAndThenPerformActionRunnable(lock);
    }

    static class WaitForLockAndThenPerformActionRunnable {

        private final Object lock;

        WaitForLockAndThenPerformActionRunnable(Object lock) {
            this.lock = lock;
        }

        Runnable thenPerform(final Action action) {
            return new Runnable() {
                @Override
                public void run() {
                    waitOnLock();
                    action.performAction();
                }
            };
        }

        private void waitOnLock() {
            try {
                synchronized (lock) {
                    lock.wait();
                }
            } catch (InterruptedException e) {
                Log.e(e, "Interruped waiting for download service.");
            }
        }
    }

}

@@ -156,32 +156,114 @@
 ction();%0A    %7D%0A%0A
+    private WaitForLockRunnable() %7B%0A        // Uses static factory method.%0A    %7D%0A%0A
     static WaitF

Add private constructor for factory.