// 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/MergeFailure.java
// public class MergeFailure extends Exception {
// 
//     public final Throwable[] mFailures;
// 
//     public MergeFailure(String message, Throwable[] failures) {
//         super(message);
//         mFailures = failures;
//     }
// }
// 
// 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);
// }


import java.lang.reflect.Array;
import org.codeandmagic.promise.Callback;
import org.codeandmagic.promise.MergeFailure;
import org.codeandmagic.promise.Promise;
        return new MergePromise<T, S>(clazz, allowedFailures, promises);
    }

    @Override
    public void success(Success resolved) {
        super.success(resolved);
    }

    @Override
    public void failure(Throwable throwable) {
        super.failure(throwable);
    }

    @Override
    public void progress(Float progress) {
        super.progress(progress);
    }

    public static class MergePromise<T, S extends T> extends DeferredObject<T[]> {

        private final Promise<S>[] mPromises;
        private final int mLength;
        private final int mAllowedFailures;

        private final Throwable[] mFailures;
        private final T[] mSuccesses;
        private int mCountCompleted = 0;
        private int mCountFailures = 0;


// 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/MergeFailure.java
// public class MergeFailure extends Exception {
// 
//     public final Throwable[] mFailures;
// 
//     public MergeFailure(String message, Throwable[] failures) {
//         super(message);
//         mFailures = failures;
//     }
// }
// 
// 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/impl/DeferredObject.java
import java.lang.reflect.Array;
import org.codeandmagic.promise.Callback;
import org.codeandmagic.promise.MergeFailure;
import org.codeandmagic.promise.Promise;

        return new MergePromise<T, S>(clazz, allowedFailures, promises);
    }

    @Override
    public void success(Success resolved) {
        super.success(resolved);
    }

    @Override
    public void failure(Throwable throwable) {
        super.failure(throwable);
    }

    @Override
    public void progress(Float progress) {
        super.progress(progress);
    }

    public static class MergePromise<T, S extends T> extends DeferredObject<T[]> {

        private final Promise<S>[] mPromises;
        private final int mLength;
        private final int mAllowedFailures;

        private final Throwable[] mFailures;
        private final T[] mSuccesses;
        private int mCountCompleted = 0;
        private int mCountFailures = 0;


        private Callback<Throwable> newFailureCallback(final int index) {