// Path: flow/src/main/java/flow/Dispatcher.java
// public interface Dispatcher {
//   /**
//    * Called when the history is about to change.  Note that Flow does not consider the
//    * Traversal to be finished, and will not actually update the history, until the callback is
//    * triggered. Traversals cannot be canceled.
//    *
//    * @param callback Must be called to indicate completion of the traversal.
//    */
//   void dispatch(@NonNull Traversal traversal, @NonNull TraversalCallback callback);
// }
// 
// Path: flow/src/main/java/flow/KeyChanger.java
// public interface KeyChanger {
//   void changeKey(@Nullable State outgoingState, @NonNull State incomingState,
//       @NonNull Direction direction, @NonNull Map<Object, Context> incomingContexts,
//       @NonNull TraversalCallback callback);
// }
// 
// Path: flow/src/main/java/flow/State.java
// public class State {
//   /** Creates a State instance that has no state and is effectively immutable. */
//   @NonNull public static State empty(@NonNull final Object key) {
//     return new EmptyState(key);
//   }
// 
//   @NonNull static State fromBundle(@NonNull Bundle savedState, @NonNull KeyParceler parceler) {
//     Object key = parceler.toKey(savedState.getParcelable("KEY"));
//     State state = new State(key);
//     state.viewState = savedState.getSparseParcelableArray("VIEW_STATE");
//     state.bundle = savedState.getBundle("BUNDLE");
//     return state;
//   }
// 
//   private final Object key;
//   @Nullable private Bundle bundle;
//   @Nullable SparseArray<Parcelable> viewState;
// 
//   State(Object key) {
//     // No external instances.
//     this.key = key;
//   }
// 
//   @NonNull public final <T> T getKey() {
//     @SuppressWarnings("unchecked") final T state = (T) key;
//     return state;
//   }
// 
//   public void save(@NonNull View view) {
//     SparseArray<Parcelable> state = new SparseArray<>();
//     view.saveHierarchyState(state);
//     viewState = state;
//   }
// 
//   public void restore(@NonNull View view) {
//     if (viewState != null) {
//       view.restoreHierarchyState(viewState);
//     }
//   }
// 
//   public void setBundle(@Nullable Bundle bundle) {
//     this.bundle = bundle;
//   }
// 
//   @Nullable public Bundle getBundle() {
//     return bundle;
//   }
// 
//   Bundle toBundle(KeyParceler parceler) {
//     Bundle outState = new Bundle();
//     outState.putParcelable("KEY", parceler.toParcelable(getKey()));
//     if (viewState != null && viewState.size() > 0) {
//       outState.putSparseParcelableArray("VIEW_STATE", viewState);
//     }
//     if (bundle != null && !bundle.isEmpty()) {
//       outState.putBundle("BUNDLE", bundle);
//     }
//     return outState;
//   }
// 
//   @Override public boolean equals(Object o) {
//     if (this == o) return true;
//     if (o == null || getClass() != o.getClass()) return false;
//     State state = (State) o;
//     return (getKey().equals(state.getKey()));
//   }
// 
//   @Override public int hashCode() {
//     return getKey().hashCode();
//   }
// 
//   @Override public String toString() {
//     return getKey().toString();
//   }
// 
//   private static final class EmptyState extends State {
//     public EmptyState(Object flowState) {
//       super(flowState);
//     }
// 
//     @Override public void save(@NonNull View view) {
//     }
// 
//     @Override public void restore(@NonNull View view) {
//     }
// 
//     @Override public void setBundle(Bundle bundle) {
//     }
// 
//     @Nullable @Override public Bundle getBundle() {
//       return null;
//     }
//   }
// }
// 
// Path: app/src/main/java/leonardo2204/com/br/flowtests/mortar/ScreenScoper.java
// public class ScreenScoper {
// 
//     public MortarScope getScreenScope(MortarScope parentScope, String name, Object key) {
// 
//         parentScope = parentScope.findChild(RootActivity.class.getName());
//         MortarScope childScope = parentScope.findChild(name);
// 
//         if (childScope != null)
//             return childScope;
// 
//         if (!(key instanceof InjectionComponent)) {
//             //throw new IllegalStateException(String.format(Locale.getDefault(),"The screen (%s) must implement InjectionComponent",key.getClass().getSimpleName()));
//             return null;
//         }
// 
//         InjectionComponent screenComponent = (InjectionComponent) key;
//         Object component = screenComponent.createComponent(parentScope.getService(DaggerService.SERVICE_NAME));
// 
//         return parentScope.buildChild().withService(DaggerService.SERVICE_NAME, component).build(name);
//     }
// 
// }


import android.app.Activity;
import android.content.Context;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import flow.Direction;
import flow.Dispatcher;
import flow.KeyChanger;
import flow.MultiKey;
import flow.State;
import flow.Traversal;
import flow.TraversalCallback;
import leonardo2204.com.br.flowtests.mortar.ScreenScoper;
package leonardo2204.com.br.flowtests.flow.dispatcher;




/**
 * Created by Leonardo on 08/03/2016.
 */
public class MortarDispatcher implements Dispatcher {

    public static final class Builder {
        private final Activity activity;
// Path: flow/src/main/java/flow/Dispatcher.java
// public interface Dispatcher {
//   /**
//    * Called when the history is about to change.  Note that Flow does not consider the
//    * Traversal to be finished, and will not actually update the history, until the callback is
//    * triggered. Traversals cannot be canceled.
//    *
//    * @param callback Must be called to indicate completion of the traversal.
//    */
//   void dispatch(@NonNull Traversal traversal, @NonNull TraversalCallback callback);
// }
// 
// Path: flow/src/main/java/flow/KeyChanger.java
// public interface KeyChanger {
//   void changeKey(@Nullable State outgoingState, @NonNull State incomingState,
//       @NonNull Direction direction, @NonNull Map<Object, Context> incomingContexts,
//       @NonNull TraversalCallback callback);
// }
// 
// Path: flow/src/main/java/flow/State.java
// public class State {
//   /** Creates a State instance that has no state and is effectively immutable. */
//   @NonNull public static State empty(@NonNull final Object key) {
//     return new EmptyState(key);
//   }
// 
//   @NonNull static State fromBundle(@NonNull Bundle savedState, @NonNull KeyParceler parceler) {
//     Object key = parceler.toKey(savedState.getParcelable("KEY"));
//     State state = new State(key);
//     state.viewState = savedState.getSparseParcelableArray("VIEW_STATE");
//     state.bundle = savedState.getBundle("BUNDLE");
//     return state;
//   }
// 
//   private final Object key;
//   @Nullable private Bundle bundle;
//   @Nullable SparseArray<Parcelable> viewState;
// 
//   State(Object key) {
//     // No external instances.
//     this.key = key;
//   }
// 
//   @NonNull public final <T> T getKey() {
//     @SuppressWarnings("unchecked") final T state = (T) key;
//     return state;
//   }
// 
//   public void save(@NonNull View view) {
//     SparseArray<Parcelable> state = new SparseArray<>();
//     view.saveHierarchyState(state);
//     viewState = state;
//   }
// 
//   public void restore(@NonNull View view) {
//     if (viewState != null) {
//       view.restoreHierarchyState(viewState);
//     }
//   }
// 
//   public void setBundle(@Nullable Bundle bundle) {
//     this.bundle = bundle;
//   }
// 
//   @Nullable public Bundle getBundle() {
//     return bundle;
//   }
// 
//   Bundle toBundle(KeyParceler parceler) {
//     Bundle outState = new Bundle();
//     outState.putParcelable("KEY", parceler.toParcelable(getKey()));
//     if (viewState != null && viewState.size() > 0) {
//       outState.putSparseParcelableArray("VIEW_STATE", viewState);
//     }
//     if (bundle != null && !bundle.isEmpty()) {
//       outState.putBundle("BUNDLE", bundle);
//     }
//     return outState;
//   }
// 
//   @Override public boolean equals(Object o) {
//     if (this == o) return true;
//     if (o == null || getClass() != o.getClass()) return false;
//     State state = (State) o;
//     return (getKey().equals(state.getKey()));
//   }
// 
//   @Override public int hashCode() {
//     return getKey().hashCode();
//   }
// 
//   @Override public String toString() {
//     return getKey().toString();
//   }
// 
//   private static final class EmptyState extends State {
//     public EmptyState(Object flowState) {
//       super(flowState);
//     }
// 
//     @Override public void save(@NonNull View view) {
//     }
// 
//     @Override public void restore(@NonNull View view) {
//     }
// 
//     @Override public void setBundle(Bundle bundle) {
//     }
// 
//     @Nullable @Override public Bundle getBundle() {
//       return null;
//     }
//   }
// }
// 
// Path: app/src/main/java/leonardo2204/com/br/flowtests/mortar/ScreenScoper.java
// public class ScreenScoper {
// 
//     public MortarScope getScreenScope(MortarScope parentScope, String name, Object key) {
// 
//         parentScope = parentScope.findChild(RootActivity.class.getName());
//         MortarScope childScope = parentScope.findChild(name);
// 
//         if (childScope != null)
//             return childScope;
// 
//         if (!(key instanceof InjectionComponent)) {
//             //throw new IllegalStateException(String.format(Locale.getDefault(),"The screen (%s) must implement InjectionComponent",key.getClass().getSimpleName()));
//             return null;
//         }
// 
//         InjectionComponent screenComponent = (InjectionComponent) key;
//         Object component = screenComponent.createComponent(parentScope.getService(DaggerService.SERVICE_NAME));
// 
//         return parentScope.buildChild().withService(DaggerService.SERVICE_NAME, component).build(name);
//     }
// 
// }


// Path: app/src/main/java/leonardo2204/com/br/flowtests/flow/dispatcher/MortarDispatcher.java
import android.app.Activity;
import android.content.Context;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import flow.Direction;
import flow.Dispatcher;
import flow.KeyChanger;
import flow.MultiKey;
import flow.State;
import flow.Traversal;
import flow.TraversalCallback;
import leonardo2204.com.br.flowtests.mortar.ScreenScoper;

package leonardo2204.com.br.flowtests.flow.dispatcher;




/**
 * Created by Leonardo on 08/03/2016.
 */
public class MortarDispatcher implements Dispatcher {

    public static final class Builder {
        private final Activity activity;
        private final KeyChanger keyChanger;