content: package powerup.systers.com.utils;
  
  import android.os.Handler;
  import android.os.Looper;
  import android.support.annotation.NonNull;
  import android.support.annotation.VisibleForTesting;
  
  import java.util.concurrent.Executor;
  import java.util.concurrent.Executors;
  
  public class AppExecutors implements Executor {
  
      private final Executor mDiskIO;
      private final Executor mainThread;
      @Override
      public void execute(@NonNull Runnable command) {
          mDiskIO.execute(command);
  
      }
  
      @VisibleForTesting
      AppExecutors(Executor diskIO, Executor mainThread) {
          this.mDiskIO = diskIO;
          this.mainThread = mainThread;
      }
  
      public AppExecutors() {
          this(new DiskIOThreadExecutor(),new MainThreadExecutor());
      }
  
  
      public Executor diskIO() {
          return mDiskIO;
      }
  
      public Executor mainThread() {
          return mainThread;
      }
  
      private static class MainThreadExecutor implements Executor {
          private Handler mainThreadHandler = new Handler(Looper.getMainLooper());
  
          @Override
          public void execute(@NonNull Runnable command) {
              mainThreadHandler.post(command);
          }
      }
  
      private static class DiskIOThreadExecutor implements Executor {
  
          private final Executor mDiskIO;
  
          public DiskIOThreadExecutor() {
              mDiskIO = Executors.newSingleThreadExecutor();
          }
  
          @Override
          public void execute(@NonNull Runnable command) {
              mDiskIO.execute(command);
          }
      }
  }
  