// Path: simple-stack/src/main/java/com/zhuinden/simplestack/StateChange.java
// public class StateChange {
//     @Retention(SOURCE)
//             // @IntDef({FORWARD, BACKWARD, REPLACE}) // removed android.support.annotation
//     @interface StateChangeDirection {
//     }
// 
//     public static final int REPLACE = 0;
//     public static final int BACKWARD = -1;
//     public static final int FORWARD = 1;
// 
//     StateChange(Backstack backstack, List<Object> previousKeys, List<Object> newKeys, @StateChangeDirection int direction) {
//         this.backstack = backstack;
//         this.previousKeys = previousKeys;
//         this.newKeys = newKeys;
//         this.direction = direction;
//     }
// 
//     Backstack backstack;
//     List<Object> previousKeys;
//     List<Object> newKeys;
//     int direction;
// 
//     /**
//      * The backstack this state change was executed by.
//      *
//      * @return the backstack
//      */
//     @Nonnull
//     public Backstack getBackstack() {
//         return backstack;
//     }
// 
//     /**
//      * Convenience method to help short-circuit if the top new key is the same as the previous one.
//      *
//      * @return if the top new key is equal to the top previous key
//      */
//     public final boolean isTopNewKeyEqualToPrevious() {
//         return topNewKey().equals(topPreviousKey());
//     }
// 
//     // create a copy list where each item is casted to <T>
//     private <T> History<T> createParametricCopyList(List<Object> list) {
//         List<T> copyList = new LinkedList<>();
//         for(Object key : list) {
//             // noinspection unchecked
//             copyList.add((T)key);
//         }
//         return History.from(copyList);
//     }
// 
//     /**
//      * The previous state from before the new keys were set.
//      * If empty, then this is an initialize {@link StateChange}.
//      *
//      * @param <T> the type of the key
//      *
//      * @return the previous state.
//      */
//     @Nonnull
//     public <T> History<T> getPreviousKeys() {
//         return createParametricCopyList(previousKeys);
//     }
// 
//     /**
//      * The new state after the state change is complete.
//      *
//      * @param <T> the type of the key
//      *
//      * @return the new state.
//      */
//     @Nonnull
//     public <T> History<T> getNewKeys() {
//         return createParametricCopyList(newKeys);
//     }
// 
//     /**
//      * The direction of the state change.
//      *
//      * @return the direction: FORWARD, BACKWARD or REPLACE.
//      */
//     @StateChangeDirection
//     public int getDirection() {
//         return direction;
//     }
// 
//     /**
//      * Provides the top of the previous state.
//      *
//      * @return the last element in previous state, or null if empty.
//      */
//     @Nullable
//     public <T> T topPreviousKey() {
//         if(previousKeys.size() > 0) {
//             // noinspection unchecked
//             return (T) previousKeys.get(previousKeys.size() - 1);
//         } else {
//             return null;
//         }
//     }
// 
//     /**
//      * Provides the top of the new state.
//      *
//      * @return the last element in new state.
//      */
//     @Nonnull
//     public <T> T topNewKey() {
//         // noinspection unchecked
//         return (T) newKeys.get(newKeys.size() - 1);
//     }
// 
//     /**
//      * Creates a {@link KeyContextWrapper} using the provided key.
//      *
//      * @param base the context used as base for the new context wrapper.
//      * @param key  the key this context is associated with.
//      * @return the context to use used with LayoutInflater.from().
//      */
//     @Nonnull
//     public Context createContext(@Nonnull Context base, @Nonnull Object key) {
//         return new KeyContextWrapper(base, key);
//     }
// }


import com.zhuinden.simplestack.StateChange;
import com.zhuinden.simplestacktutorials.R;
import java.util.List;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentTransaction;
package com.zhuinden.simplestacktutorials.steps.step_5;




public class FragmentStateChanger {
    private FragmentManager fragmentManager;
    private int containerId;

    public FragmentStateChanger(FragmentManager fragmentManager, int containerId) {
        this.fragmentManager = fragmentManager;
        this.containerId = containerId;
    }

// Path: simple-stack/src/main/java/com/zhuinden/simplestack/StateChange.java
// public class StateChange {
//     @Retention(SOURCE)
//             // @IntDef({FORWARD, BACKWARD, REPLACE}) // removed android.support.annotation
//     @interface StateChangeDirection {
//     }
// 
//     public static final int REPLACE = 0;
//     public static final int BACKWARD = -1;
//     public static final int FORWARD = 1;
// 
//     StateChange(Backstack backstack, List<Object> previousKeys, List<Object> newKeys, @StateChangeDirection int direction) {
//         this.backstack = backstack;
//         this.previousKeys = previousKeys;
//         this.newKeys = newKeys;
//         this.direction = direction;
//     }
// 
//     Backstack backstack;
//     List<Object> previousKeys;
//     List<Object> newKeys;
//     int direction;
// 
//     /**
//      * The backstack this state change was executed by.
//      *
//      * @return the backstack
//      */
//     @Nonnull
//     public Backstack getBackstack() {
//         return backstack;
//     }
// 
//     /**
//      * Convenience method to help short-circuit if the top new key is the same as the previous one.
//      *
//      * @return if the top new key is equal to the top previous key
//      */
//     public final boolean isTopNewKeyEqualToPrevious() {
//         return topNewKey().equals(topPreviousKey());
//     }
// 
//     // create a copy list where each item is casted to <T>
//     private <T> History<T> createParametricCopyList(List<Object> list) {
//         List<T> copyList = new LinkedList<>();
//         for(Object key : list) {
//             // noinspection unchecked
//             copyList.add((T)key);
//         }
//         return History.from(copyList);
//     }
// 
//     /**
//      * The previous state from before the new keys were set.
//      * If empty, then this is an initialize {@link StateChange}.
//      *
//      * @param <T> the type of the key
//      *
//      * @return the previous state.
//      */
//     @Nonnull
//     public <T> History<T> getPreviousKeys() {
//         return createParametricCopyList(previousKeys);
//     }
// 
//     /**
//      * The new state after the state change is complete.
//      *
//      * @param <T> the type of the key
//      *
//      * @return the new state.
//      */
//     @Nonnull
//     public <T> History<T> getNewKeys() {
//         return createParametricCopyList(newKeys);
//     }
// 
//     /**
//      * The direction of the state change.
//      *
//      * @return the direction: FORWARD, BACKWARD or REPLACE.
//      */
//     @StateChangeDirection
//     public int getDirection() {
//         return direction;
//     }
// 
//     /**
//      * Provides the top of the previous state.
//      *
//      * @return the last element in previous state, or null if empty.
//      */
//     @Nullable
//     public <T> T topPreviousKey() {
//         if(previousKeys.size() > 0) {
//             // noinspection unchecked
//             return (T) previousKeys.get(previousKeys.size() - 1);
//         } else {
//             return null;
//         }
//     }
// 
//     /**
//      * Provides the top of the new state.
//      *
//      * @return the last element in new state.
//      */
//     @Nonnull
//     public <T> T topNewKey() {
//         // noinspection unchecked
//         return (T) newKeys.get(newKeys.size() - 1);
//     }
// 
//     /**
//      * Creates a {@link KeyContextWrapper} using the provided key.
//      *
//      * @param base the context used as base for the new context wrapper.
//      * @param key  the key this context is associated with.
//      * @return the context to use used with LayoutInflater.from().
//      */
//     @Nonnull
//     public Context createContext(@Nonnull Context base, @Nonnull Object key) {
//         return new KeyContextWrapper(base, key);
//     }
// }


// Path: tutorials/tutorial-sample/src/main/java/com/zhuinden/simplestacktutorials/steps/step_5/FragmentStateChanger.java
import com.zhuinden.simplestack.StateChange;
import com.zhuinden.simplestacktutorials.R;
import java.util.List;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentTransaction;

package com.zhuinden.simplestacktutorials.steps.step_5;




public class FragmentStateChanger {
    private FragmentManager fragmentManager;
    private int containerId;

    public FragmentStateChanger(FragmentManager fragmentManager, int containerId) {
        this.fragmentManager = fragmentManager;
        this.containerId = containerId;
    }

    public void handleStateChange(StateChange stateChange) {