// Path: shelly/src/main/java/xiaofei/library/shelly/Shelly.java
// public class Shelly {
// 
//     private static final TargetCenter TARGET_CENTER = TargetCenter.getInstance();
// 
//     private static final DominoCenter DOMINO_CENTER = DominoCenter.getInstance();
// 
//     public static void register(Object object) {
//         TARGET_CENTER.register(object);
//     }
// 
//     public static boolean isRegistered(Object object) {
//         return TARGET_CENTER.isRegistered(object);
//     }
// 
//     public static void unregister(Object object) {
//         TARGET_CENTER.unregister(object);
//     }
// 
//     public static <T> Domino<T, T> createDomino(Object label) {
//         return new Domino<T, T>(label);
//     }
// 
//     public static <T> Domino<T, T> createAnonymousDomino() {
//         return createDomino(null);
//     }
// 
//     @SafeVarargs
//     public static <T> void playDomino(Object label, T... input) {
//         CopyOnWriteArrayList<T> newInput = new CopyOnWriteArrayList<T>();
//         if (input == null) {
//             newInput.add(null);
//         } else if (input.length > 0) {
//             newInput.addAll(Arrays.asList(input));
//         }
//         playDominoInternal(label, newInput);
//     }
// 
//     public static void playDomino(Object label) {
//         playDominoInternal(label, new CopyOnWriteArrayList<Object>());
//     }
// 
//     private static <T> void playDominoInternal(Object label, CopyOnWriteArrayList<T> input) {
//         DOMINO_CENTER.play(label, input);
//     }
// 
//     public static <T, R> Domino<T, R> getDominoByLabel(Object label) {
//         return DOMINO_CENTER.getDomino(label);
//     }
// }
// 
// Path: shelly/src/main/java/xiaofei/library/shelly/function/Action0.java
// public interface Action0 extends Action {
//     void call();
// }
// 
// Path: shelly/src/main/java/xiaofei/library/shelly/function/Action1.java
// public interface Action1<T> extends Action {
//     void call(T input);
// }
// 
// Path: shelly/src/main/java/xiaofei/library/shelly/function/Function1.java
// public interface Function1<T, R> extends Function {
//     R call(T input);
// }
// 
// Path: shelly/src/main/java/xiaofei/library/shelly/function/TargetAction0.java
// public interface TargetAction0<T> extends Action {
//     void call(T t);
// }
// 
// Path: shelly/src/main/java/xiaofei/library/shelly/function/TargetAction1.java
// public interface TargetAction1<T, R> extends Action {
//     void call(T t, R input);
// }
// 
// Path: shelly/src/main/java/xiaofei/library/shelly/operator/ListIdentityOperator.java
// public class ListIdentityOperator<T> extends IdentityOperator<List<T>> {
// }
// 
// Path: shelly/src/main/java/xiaofei/library/shelly/tuple/Triple.java
// public class Triple<T1, T2, T3> {
//     public final T1 first;
//     public final T2 second;
//     public final T3 third;
// 
//     @Deprecated
//     public Triple(T1 first, T2 second, T3 third) {
//         this.first = first;
//         this.second = second;
//         this.third = third;
//     }
// 
//     public static <T1, T2, T3> Triple<T1, T2, T3> create(T1 first, T2 second, T3 third) {
//         return new Triple<T1, T2, T3>(first, second, third);
//     }
// }
// 
// Path: shelly/src/main/java/xiaofei/library/shelly/util/Tile.java
// public interface Tile<T, R> extends Function1<List<T>, Player<R>> {
// 
// }


import xiaofei.library.shelly.util.Tile;
import java.util.ArrayList;
import java.util.List;
import retrofit2.Response;
import xiaofei.library.shelly.Shelly;
import xiaofei.library.shelly.function.Action0;
import xiaofei.library.shelly.function.Action1;
import xiaofei.library.shelly.function.Function1;
import xiaofei.library.shelly.function.TargetAction0;
import xiaofei.library.shelly.function.TargetAction1;
import xiaofei.library.shelly.operator.ListIdentityOperator;
import xiaofei.library.shelly.tuple.Triple;
/**
 *
 * Copyright 2016 Xiaofei
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 */

package xiaofei.library.shelly.domino;



/**
 * Created by Xiaofei on 16/6/27.
 */
public class RetrofitDomino<T, R> extends Domino<T, Triple<Boolean, Response<R>, Throwable>> {

    public RetrofitDomino(Object label, Tile<T, Triple<Boolean, Response<R>, Throwable>> tile) {
        super(label, tile);
    }

    private RetrofitDomino(Domino<T, Triple<Boolean, Response<R>, Throwable>> domino) {
        //can use getPlayer(), but not here!
        this(domino.getLabel(), domino.getPlayer());
    }
    @Override
    public RetrofitDomino<T, R> uiThread() {
        return new RetrofitDomino<T, R>(super.uiThread());
    }

    @Override
    public RetrofitDomino<T, R> background() {
        return new RetrofitDomino<T, R>(super.background());
    }

    @Override
    public RetrofitDomino<T, R> backgroundQueue() {
        return new RetrofitDomino<T, R>(super.backgroundQueue());
    }

    public RetrofitDomino<T, R> onFailure(final Domino<? super Throwable, ?> domino) {
        return new RetrofitDomino<T, R>(
// Path: shelly/src/main/java/xiaofei/library/shelly/Shelly.java
// public class Shelly {
// 
//     private static final TargetCenter TARGET_CENTER = TargetCenter.getInstance();
// 
//     private static final DominoCenter DOMINO_CENTER = DominoCenter.getInstance();
// 
//     public static void register(Object object) {
//         TARGET_CENTER.register(object);
//     }
// 
//     public static boolean isRegistered(Object object) {
//         return TARGET_CENTER.isRegistered(object);
//     }
// 
//     public static void unregister(Object object) {
//         TARGET_CENTER.unregister(object);
//     }
// 
//     public static <T> Domino<T, T> createDomino(Object label) {
//         return new Domino<T, T>(label);
//     }
// 
//     public static <T> Domino<T, T> createAnonymousDomino() {
//         return createDomino(null);
//     }
// 
//     @SafeVarargs
//     public static <T> void playDomino(Object label, T... input) {
//         CopyOnWriteArrayList<T> newInput = new CopyOnWriteArrayList<T>();
//         if (input == null) {
//             newInput.add(null);
//         } else if (input.length > 0) {
//             newInput.addAll(Arrays.asList(input));
//         }
//         playDominoInternal(label, newInput);
//     }
// 
//     public static void playDomino(Object label) {
//         playDominoInternal(label, new CopyOnWriteArrayList<Object>());
//     }
// 
//     private static <T> void playDominoInternal(Object label, CopyOnWriteArrayList<T> input) {
//         DOMINO_CENTER.play(label, input);
//     }
// 
//     public static <T, R> Domino<T, R> getDominoByLabel(Object label) {
//         return DOMINO_CENTER.getDomino(label);
//     }
// }
// 
// Path: shelly/src/main/java/xiaofei/library/shelly/function/Action0.java
// public interface Action0 extends Action {
//     void call();
// }
// 
// Path: shelly/src/main/java/xiaofei/library/shelly/function/Action1.java
// public interface Action1<T> extends Action {
//     void call(T input);
// }
// 
// Path: shelly/src/main/java/xiaofei/library/shelly/function/Function1.java
// public interface Function1<T, R> extends Function {
//     R call(T input);
// }
// 
// Path: shelly/src/main/java/xiaofei/library/shelly/function/TargetAction0.java
// public interface TargetAction0<T> extends Action {
//     void call(T t);
// }
// 
// Path: shelly/src/main/java/xiaofei/library/shelly/function/TargetAction1.java
// public interface TargetAction1<T, R> extends Action {
//     void call(T t, R input);
// }
// 
// Path: shelly/src/main/java/xiaofei/library/shelly/operator/ListIdentityOperator.java
// public class ListIdentityOperator<T> extends IdentityOperator<List<T>> {
// }
// 
// Path: shelly/src/main/java/xiaofei/library/shelly/tuple/Triple.java
// public class Triple<T1, T2, T3> {
//     public final T1 first;
//     public final T2 second;
//     public final T3 third;
// 
//     @Deprecated
//     public Triple(T1 first, T2 second, T3 third) {
//         this.first = first;
//         this.second = second;
//         this.third = third;
//     }
// 
//     public static <T1, T2, T3> Triple<T1, T2, T3> create(T1 first, T2 second, T3 third) {
//         return new Triple<T1, T2, T3>(first, second, third);
//     }
// }
// 
// Path: shelly/src/main/java/xiaofei/library/shelly/util/Tile.java
// public interface Tile<T, R> extends Function1<List<T>, Player<R>> {
// 
// }


// Path: shelly/src/main/java/xiaofei/library/shelly/domino/RetrofitDomino.java
import xiaofei.library.shelly.util.Tile;
import java.util.ArrayList;
import java.util.List;
import retrofit2.Response;
import xiaofei.library.shelly.Shelly;
import xiaofei.library.shelly.function.Action0;
import xiaofei.library.shelly.function.Action1;
import xiaofei.library.shelly.function.Function1;
import xiaofei.library.shelly.function.TargetAction0;
import xiaofei.library.shelly.function.TargetAction1;
import xiaofei.library.shelly.operator.ListIdentityOperator;
import xiaofei.library.shelly.tuple.Triple;

/**
 *
 * Copyright 2016 Xiaofei
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 */

package xiaofei.library.shelly.domino;



/**
 * Created by Xiaofei on 16/6/27.
 */
public class RetrofitDomino<T, R> extends Domino<T, Triple<Boolean, Response<R>, Throwable>> {

    public RetrofitDomino(Object label, Tile<T, Triple<Boolean, Response<R>, Throwable>> tile) {
        super(label, tile);
    }

    private RetrofitDomino(Domino<T, Triple<Boolean, Response<R>, Throwable>> domino) {
        //can use getPlayer(), but not here!
        this(domino.getLabel(), domino.getPlayer());
    }
    @Override
    public RetrofitDomino<T, R> uiThread() {
        return new RetrofitDomino<T, R>(super.uiThread());
    }

    @Override
    public RetrofitDomino<T, R> background() {
        return new RetrofitDomino<T, R>(super.background());
    }

    @Override
    public RetrofitDomino<T, R> backgroundQueue() {
        return new RetrofitDomino<T, R>(super.backgroundQueue());
    }

    public RetrofitDomino<T, R> onFailure(final Domino<? super Throwable, ?> domino) {
        return new RetrofitDomino<T, R>(
                perform(Shelly.<Triple<Boolean, Response<R>, Throwable>>createAnonymousDomino()