// Path: RxDbFlow-Rx2/src/main/java/au/com/roadhouse/rxdbflow/rx2/sql/observables/functions/ValueAction.java
// public interface ValueAction<T> {
//     T run();
// }
// 
// Path: RxDbFlow-Rx2/src/main/java/au/com/roadhouse/rxdbflow/rx2/sql/transaction/DbTransaction.java
// public class DbTransaction {
// 
//     private final Class mClass;
//     private static Map<String, List<OnDbTransactionListener>> sTransactionListenerMap = new HashMap<>();
// 
//     public DbTransaction(Class tableClass){
//         mClass = tableClass;
//     }
// 
//     public static void registerDbTransactionListener(Class tableClass, OnDbTransactionListener listener){
//         String databaseName = FlowManager.getDatabaseForTable(tableClass).getDatabaseName();
//         if(sTransactionListenerMap.containsKey(databaseName)){
//             sTransactionListenerMap.get(databaseName).add(listener);
//         } else {
//             List<OnDbTransactionListener> listenerList = new ArrayList<>();
//             listenerList.add(listener);
//             sTransactionListenerMap.put(databaseName, listenerList);
//         }
//     }
// 
//     public static void unregisterDbTransactionListener(Class tableClass, OnDbTransactionListener listener) {
//         String databaseName = FlowManager.getDatabaseForTable(tableClass).getDatabaseName();
//         if(sTransactionListenerMap.containsKey(databaseName)){
//             sTransactionListenerMap.get(databaseName).remove(databaseName);
//             if(sTransactionListenerMap.get(databaseName).size() == 0){
//                 sTransactionListenerMap.remove(databaseName);
//             }
//         } else {
//             Log.e("DbTransaction", "Attempting to unregister a listener which was not registered");
// 
//         }
//     }
// 
//     public void beginTransaction(){
//         FlowManager.getDatabase(mClass).getWritableDatabase().beginTransaction();
//         String databaseName = FlowManager.getDatabaseForTable(mClass).getDatabaseName();
//         if(sTransactionListenerMap.containsKey(databaseName)){
//             List<OnDbTransactionListener> listenerList = sTransactionListenerMap.get(databaseName);
//             for(int i = 0; i < listenerList.size(); i++){
//                 listenerList.get(i).onTransactionStarted();
//             }
//         }
//     }
// 
//     public void setTransactionSuccessful(){
//         FlowManager.getDatabase(mClass).getWritableDatabase().setTransactionSuccessful();
//     }
// 
//     public void endTransaction() {
//         FlowManager.getDatabase(mClass).getWritableDatabase().endTransaction();
//         String databaseName = FlowManager.getDatabaseForTable(mClass).getDatabaseName();
//         if(sTransactionListenerMap.containsKey(databaseName)){
//             List<OnDbTransactionListener> listenerList = sTransactionListenerMap.get(databaseName);
//             for(int i = 0; i < listenerList.size(); i++){
//                 listenerList.get(i).onTransactionEnded();
//             }
//         }
//     }
// 
//     public interface OnDbTransactionListener {
//         void onTransactionStarted();
//         void onTransactionEnded();
//     }
// }


import android.support.annotation.Nullable;
import com.raizlabs.android.dbflow.config.FlowManager;
import com.raizlabs.android.dbflow.runtime.FlowContentObserver;
import com.raizlabs.android.dbflow.structure.BaseModel;
import java.util.Arrays;
import java.util.List;
import au.com.roadhouse.rxdbflow.rx2.sql.observables.functions.ValueAction;
import au.com.roadhouse.rxdbflow.rx2.sql.transaction.DbTransaction;
import io.reactivex.Observable;
import io.reactivex.ObservableSource;
import io.reactivex.Observer;
import io.reactivex.disposables.Disposable;
import io.reactivex.internal.fuseable.HasUpstreamObservableSource;
package au.com.roadhouse.rxdbflow.rx2.sql.observables.operators;






public class DBFlowRestartOnChange<T> extends Observable<T> implements HasUpstreamObservableSource<T> {
    private final ObservableSource<T> mSource;
    private final Class[] mSubscribedClasses;
    private final ValueAction<T> mRestartAction;

    public DBFlowRestartOnChange(Observable<T> source, Class[] subscribedClasses, ValueAction<T> restartAction) {
        mSource = source;
        mSubscribedClasses = subscribedClasses;
        mRestartAction = restartAction;
    }

    @Override
    protected void subscribeActual(Observer<? super T> observer) {
        final RestartOnChangeObserver<T> disposable = new RestartOnChangeObserver<T>(observer, mSubscribedClasses, mRestartAction);
        mSource.subscribe(disposable);
    }

    @Override
    public ObservableSource<T> source() {
        return mSource;
    }

// Path: RxDbFlow-Rx2/src/main/java/au/com/roadhouse/rxdbflow/rx2/sql/observables/functions/ValueAction.java
// public interface ValueAction<T> {
//     T run();
// }
// 
// Path: RxDbFlow-Rx2/src/main/java/au/com/roadhouse/rxdbflow/rx2/sql/transaction/DbTransaction.java
// public class DbTransaction {
// 
//     private final Class mClass;
//     private static Map<String, List<OnDbTransactionListener>> sTransactionListenerMap = new HashMap<>();
// 
//     public DbTransaction(Class tableClass){
//         mClass = tableClass;
//     }
// 
//     public static void registerDbTransactionListener(Class tableClass, OnDbTransactionListener listener){
//         String databaseName = FlowManager.getDatabaseForTable(tableClass).getDatabaseName();
//         if(sTransactionListenerMap.containsKey(databaseName)){
//             sTransactionListenerMap.get(databaseName).add(listener);
//         } else {
//             List<OnDbTransactionListener> listenerList = new ArrayList<>();
//             listenerList.add(listener);
//             sTransactionListenerMap.put(databaseName, listenerList);
//         }
//     }
// 
//     public static void unregisterDbTransactionListener(Class tableClass, OnDbTransactionListener listener) {
//         String databaseName = FlowManager.getDatabaseForTable(tableClass).getDatabaseName();
//         if(sTransactionListenerMap.containsKey(databaseName)){
//             sTransactionListenerMap.get(databaseName).remove(databaseName);
//             if(sTransactionListenerMap.get(databaseName).size() == 0){
//                 sTransactionListenerMap.remove(databaseName);
//             }
//         } else {
//             Log.e("DbTransaction", "Attempting to unregister a listener which was not registered");
// 
//         }
//     }
// 
//     public void beginTransaction(){
//         FlowManager.getDatabase(mClass).getWritableDatabase().beginTransaction();
//         String databaseName = FlowManager.getDatabaseForTable(mClass).getDatabaseName();
//         if(sTransactionListenerMap.containsKey(databaseName)){
//             List<OnDbTransactionListener> listenerList = sTransactionListenerMap.get(databaseName);
//             for(int i = 0; i < listenerList.size(); i++){
//                 listenerList.get(i).onTransactionStarted();
//             }
//         }
//     }
// 
//     public void setTransactionSuccessful(){
//         FlowManager.getDatabase(mClass).getWritableDatabase().setTransactionSuccessful();
//     }
// 
//     public void endTransaction() {
//         FlowManager.getDatabase(mClass).getWritableDatabase().endTransaction();
//         String databaseName = FlowManager.getDatabaseForTable(mClass).getDatabaseName();
//         if(sTransactionListenerMap.containsKey(databaseName)){
//             List<OnDbTransactionListener> listenerList = sTransactionListenerMap.get(databaseName);
//             for(int i = 0; i < listenerList.size(); i++){
//                 listenerList.get(i).onTransactionEnded();
//             }
//         }
//     }
// 
//     public interface OnDbTransactionListener {
//         void onTransactionStarted();
//         void onTransactionEnded();
//     }
// }


// Path: RxDbFlow-Rx2/src/main/java/au/com/roadhouse/rxdbflow/rx2/sql/observables/operators/DBFlowRestartOnChange.java
import android.support.annotation.Nullable;
import com.raizlabs.android.dbflow.config.FlowManager;
import com.raizlabs.android.dbflow.runtime.FlowContentObserver;
import com.raizlabs.android.dbflow.structure.BaseModel;
import java.util.Arrays;
import java.util.List;
import au.com.roadhouse.rxdbflow.rx2.sql.observables.functions.ValueAction;
import au.com.roadhouse.rxdbflow.rx2.sql.transaction.DbTransaction;
import io.reactivex.Observable;
import io.reactivex.ObservableSource;
import io.reactivex.Observer;
import io.reactivex.disposables.Disposable;
import io.reactivex.internal.fuseable.HasUpstreamObservableSource;

package au.com.roadhouse.rxdbflow.rx2.sql.observables.operators;






public class DBFlowRestartOnChange<T> extends Observable<T> implements HasUpstreamObservableSource<T> {
    private final ObservableSource<T> mSource;
    private final Class[] mSubscribedClasses;
    private final ValueAction<T> mRestartAction;

    public DBFlowRestartOnChange(Observable<T> source, Class[] subscribedClasses, ValueAction<T> restartAction) {
        mSource = source;
        mSubscribedClasses = subscribedClasses;
        mRestartAction = restartAction;
    }

    @Override
    protected void subscribeActual(Observer<? super T> observer) {
        final RestartOnChangeObserver<T> disposable = new RestartOnChangeObserver<T>(observer, mSubscribedClasses, mRestartAction);
        mSource.subscribe(disposable);
    }

    @Override
    public ObservableSource<T> source() {
        return mSource;
    }

    private class RestartOnChangeObserver<T> implements Observer<T>, Disposable, DbTransaction.OnDbTransactionListener {