// Path: core/src/main/java/org/codeandmagic/promise/Callback.java
// public interface Callback<T> {
// 
//     void onCallback(final T result);
// }
// 
// Path: core/src/main/java/org/codeandmagic/promise/Promise.java
// public interface Promise<Success> extends Promise3<Success, Throwable, Float> {
// 
//     @Override
//     public Promise<Success> onSuccess(Callback<Success> onSuccess);
// 
//     @Override
//     public Promise<Success> onFailure(Callback<Throwable> onFailure);
// 
//     @Override
//     public Promise<Success> onProgress(Callback<Float> onProgress);
// 
//     @Override
//     public Promise<Success> onComplete(Callback<Either<Throwable, Success>> onComplete);
// 
//     @Override
//     public <Success2> Promise<Success2> map(final Transformation<Success, Success2> transform);
// 
//     @Override
//     public <Success2> Promise<Success2> flatMap(final Transformation<Success, Either<Throwable, Success2>> transform);
// 
//     @Override
//     public Promise<Success> andThen(Callback<Success> onSuccess,
//                                     Callback<Throwable> onFailure,
//                                     Callback<Float> onProgress);
// 
//     @Override
//     public Promise<Success> flatRecover(final Transformation<Throwable, Either<Throwable, Success>> transform);
// 
//     @Override
//     public Promise<Success> recover(final Transformation<Throwable, Success> transform);
// 
// 
//     public <Success2> Promise<Success2> pipe(final Pipe<Success, Success2> transform);
// 
//     public Promise<Success> recoverWith(final Pipe<Throwable, Success> transform);
// 
//     @Override
//     public Promise<Success> runOnUiThread();
// 
//     /**
//      * <b>IMPORTANT NOTE</b>
//      * This method operates on the assumption that the Success of this Promise is an {@link java.util.Collection<T1>}.
//      * If not, it will fail with a {@link ClassCastException}.
//      * <p/>
//      * This method creates a list of Promises by applying a {@link Pipe} to each
//      * element in the {@link java.util.Collection<T1>}.
//      * <p/>
//      *
//      * @param transform the {@link Transformation} to be applied to each element
//      * @param <T1>
//      * @param <T2>
//      * @return
//      */
//     public <T1, T2> Promises<T2> split(Pipe<T1, T2> transform);
// }
// 
// Path: core/src/main/java/org/codeandmagic/promise/Promises.java
// public interface Promises<Success>{
// 
//     <Success2> Promises<Success2> map(final Transformation<Success, Success2> transform);
// 
//     Promises<Success> onSuccess(Callback<Success> onSuccess);
// 
//     Promises<Success> onFailure(Callback<Throwable> onFailure);
// 
//     Promises<Success> runOnUiThread();
// }
// 
// Path: core/src/main/java/org/codeandmagic/promise/Transformation.java
// public interface Transformation<T1, T2> {
// 
//     T2 transform(T1 value);
// 
// }


import org.codeandmagic.promise.Callback;
import org.codeandmagic.promise.Promise;
import org.codeandmagic.promise.Promises;
import org.codeandmagic.promise.Transformation;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;
        for (Callback<Success> c : mSuccessCallbacks) {
            thePromise.onSuccess(c);
        }
        for (Callback<Throwable> c : mFailureCallbacks) {
            thePromise.onFailure(c);
        }
        for (Callback<Collection<Promise<Success>>> c : mSetCallbacks) {
            c.onCallback(promises);
        }
        return thePromise;
    }

    @Override
    public <Success2> Promises<Success2> map(final Transformation<Success, Success2> transform) {
        final ProxyPromises<Success2> proxy = new ProxyPromises<Success2>();
        mSetCallbacks.add(new Callback<Collection<Promise<Success>>>() {
            @Override
            public void onCallback(Collection<Promise<Success>> promises) {
                Collection<Promise<Success2>> newPromises = new ArrayList<Promise<Success2>>(promises.size());
                for (Promise<Success> p : promises) {
                    newPromises.add(p.map(transform));
                }
                proxy.setPromises(newPromises);
            }
        });
        return proxy;
    }

    @Override
    public Promises<Success> onSuccess(Callback<Success> onSuccess) {
// Path: core/src/main/java/org/codeandmagic/promise/Callback.java
// public interface Callback<T> {
// 
//     void onCallback(final T result);
// }
// 
// Path: core/src/main/java/org/codeandmagic/promise/Promise.java
// public interface Promise<Success> extends Promise3<Success, Throwable, Float> {
// 
//     @Override
//     public Promise<Success> onSuccess(Callback<Success> onSuccess);
// 
//     @Override
//     public Promise<Success> onFailure(Callback<Throwable> onFailure);
// 
//     @Override
//     public Promise<Success> onProgress(Callback<Float> onProgress);
// 
//     @Override
//     public Promise<Success> onComplete(Callback<Either<Throwable, Success>> onComplete);
// 
//     @Override
//     public <Success2> Promise<Success2> map(final Transformation<Success, Success2> transform);
// 
//     @Override
//     public <Success2> Promise<Success2> flatMap(final Transformation<Success, Either<Throwable, Success2>> transform);
// 
//     @Override
//     public Promise<Success> andThen(Callback<Success> onSuccess,
//                                     Callback<Throwable> onFailure,
//                                     Callback<Float> onProgress);
// 
//     @Override
//     public Promise<Success> flatRecover(final Transformation<Throwable, Either<Throwable, Success>> transform);
// 
//     @Override
//     public Promise<Success> recover(final Transformation<Throwable, Success> transform);
// 
// 
//     public <Success2> Promise<Success2> pipe(final Pipe<Success, Success2> transform);
// 
//     public Promise<Success> recoverWith(final Pipe<Throwable, Success> transform);
// 
//     @Override
//     public Promise<Success> runOnUiThread();
// 
//     /**
//      * <b>IMPORTANT NOTE</b>
//      * This method operates on the assumption that the Success of this Promise is an {@link java.util.Collection<T1>}.
//      * If not, it will fail with a {@link ClassCastException}.
//      * <p/>
//      * This method creates a list of Promises by applying a {@link Pipe} to each
//      * element in the {@link java.util.Collection<T1>}.
//      * <p/>
//      *
//      * @param transform the {@link Transformation} to be applied to each element
//      * @param <T1>
//      * @param <T2>
//      * @return
//      */
//     public <T1, T2> Promises<T2> split(Pipe<T1, T2> transform);
// }
// 
// Path: core/src/main/java/org/codeandmagic/promise/Promises.java
// public interface Promises<Success>{
// 
//     <Success2> Promises<Success2> map(final Transformation<Success, Success2> transform);
// 
//     Promises<Success> onSuccess(Callback<Success> onSuccess);
// 
//     Promises<Success> onFailure(Callback<Throwable> onFailure);
// 
//     Promises<Success> runOnUiThread();
// }
// 
// Path: core/src/main/java/org/codeandmagic/promise/Transformation.java
// public interface Transformation<T1, T2> {
// 
//     T2 transform(T1 value);
// 
// }


// Path: core/src/main/java/org/codeandmagic/promise/impl/Promises.java
import org.codeandmagic.promise.Callback;
import org.codeandmagic.promise.Promise;
import org.codeandmagic.promise.Promises;
import org.codeandmagic.promise.Transformation;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;

        for (Callback<Success> c : mSuccessCallbacks) {
            thePromise.onSuccess(c);
        }
        for (Callback<Throwable> c : mFailureCallbacks) {
            thePromise.onFailure(c);
        }
        for (Callback<Collection<Promise<Success>>> c : mSetCallbacks) {
            c.onCallback(promises);
        }
        return thePromise;
    }

    @Override
    public <Success2> Promises<Success2> map(final Transformation<Success, Success2> transform) {
        final ProxyPromises<Success2> proxy = new ProxyPromises<Success2>();
        mSetCallbacks.add(new Callback<Collection<Promise<Success>>>() {
            @Override
            public void onCallback(Collection<Promise<Success>> promises) {
                Collection<Promise<Success2>> newPromises = new ArrayList<Promise<Success2>>(promises.size());
                for (Promise<Success> p : promises) {
                    newPromises.add(p.map(transform));
                }
                proxy.setPromises(newPromises);
            }
        });
        return proxy;
    }

    @Override
    public Promises<Success> onSuccess(Callback<Success> onSuccess) {
        mSuccessCallbacks.add(onSuccess);