// 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;
/*
 * Copyright (c) 2014 CodeAndMagic
 * Cristian Vrabie, Evelina Vrabie
 *
 * This file is part of android-promise.
 * android-promise is free software: you can redistribute it and/or modify it
 * under the terms of the GNU Lesser General Public License as published by the
 * Free Software Foundation, either version 3 of the License,or (at your option)
 * any later version.
 *
 * android-promise is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
 * or FITNESS FOR A PARTICULAR PURPOSE.
 * See the GNU Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with android-promise. If not, see <http://www.gnu.org/licenses/>.
 */

package org.codeandmagic.promise.impl;



/**
 * Created by evelina on 18/03/2014.
 */
class PromisesList<Success> implements Promises<Success> {

    private final Collection<Promise<Success>> mPromises;

    PromisesList(Collection<Promise<Success>> promises) {
        mPromises = promises;
    }

    @Override
    public <Success2> Promises<Success2> map(Transformation<Success, Success2> transform) {
        List<Promise<Success2>> newPromises = new ArrayList<Promise<Success2>>(mPromises.size());
        for (Promise<Success> p : mPromises) {
            newPromises.add(p.map(transform));
        }
        return new PromisesList<Success2>(newPromises);
    }

    @Override
    public Promises<Success> onSuccess(Callback<Success> onSuccess) {
        for (Promise<Success> p : mPromises) {
            p.onSuccess(onSuccess);
        }
        return this;
    }

    @Override
    public Promises<Success> onFailure(Callback<Throwable> onFailure) {
        for (Promise<Success> p : mPromises) {
            p.onFailure(onFailure);
        }
        return this;
    }

    @Override
    public Promises<Success> runOnUiThread() {
// 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;

/*
 * Copyright (c) 2014 CodeAndMagic
 * Cristian Vrabie, Evelina Vrabie
 *
 * This file is part of android-promise.
 * android-promise is free software: you can redistribute it and/or modify it
 * under the terms of the GNU Lesser General Public License as published by the
 * Free Software Foundation, either version 3 of the License,or (at your option)
 * any later version.
 *
 * android-promise is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
 * or FITNESS FOR A PARTICULAR PURPOSE.
 * See the GNU Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with android-promise. If not, see <http://www.gnu.org/licenses/>.
 */

package org.codeandmagic.promise.impl;



/**
 * Created by evelina on 18/03/2014.
 */
class PromisesList<Success> implements Promises<Success> {

    private final Collection<Promise<Success>> mPromises;

    PromisesList(Collection<Promise<Success>> promises) {
        mPromises = promises;
    }

    @Override
    public <Success2> Promises<Success2> map(Transformation<Success, Success2> transform) {
        List<Promise<Success2>> newPromises = new ArrayList<Promise<Success2>>(mPromises.size());
        for (Promise<Success> p : mPromises) {
            newPromises.add(p.map(transform));
        }
        return new PromisesList<Success2>(newPromises);
    }

    @Override
    public Promises<Success> onSuccess(Callback<Success> onSuccess) {
        for (Promise<Success> p : mPromises) {
            p.onSuccess(onSuccess);
        }
        return this;
    }

    @Override
    public Promises<Success> onFailure(Callback<Throwable> onFailure) {
        for (Promise<Success> p : mPromises) {
            p.onFailure(onFailure);
        }
        return this;
    }

    @Override
    public Promises<Success> runOnUiThread() {
        List<Promise<Success>> newPromises = new ArrayList<Promise<Success>>(mPromises.size());