fragment/src/main/java/androidx/fragment/app/BackStackRecord.java
@SuppressWarnings("ReferenceEquality")
    Fragment expandOps(ArrayList<Fragment> added, Fragment oldPrimaryNav) {
        for (int opNum = 0; opNum < mOps.size(); opNum++) {
            final Op op = mOps.get(opNum);
            switch (op.cmd) {
                case OP_ADD:
                case OP_ATTACH:
                    added.add(op.fragment);
                    break;
                case OP_REMOVE:
                case OP_DETACH: {
                    added.remove(op.fragment);
                    if (op.fragment == oldPrimaryNav) {
                        mOps.add(opNum, new Op(OP_UNSET_PRIMARY_NAV, op.fragment));
                        opNum++;
                        oldPrimaryNav = null;
                    }
                }
                break;
                case OP_REPLACE: {
                    final Fragment f = op.fragment;
                    final int containerId = f.mContainerId;
                    boolean alreadyAdded = false;
                    for (int i = added.size() - 1; i >= 0; i--) {
                        final Fragment old = added.get(i);
                        if (old.mContainerId == containerId) {
                            if (old == f) {
                                alreadyAdded = true;
                            } else {
                                // This is duplicated from above since we only make
                                // a single pass for expanding ops. Unset any outgoing primary nav.
                                if (old == oldPrimaryNav) {
                                    mOps.add(opNum, new Op(OP_UNSET_PRIMARY_NAV, old));
                                    opNum++;
                                    oldPrimaryNav = null;
                                }
                                final Op removeOp = new Op(OP_REMOVE, old);
                                removeOp.enterAnim = op.enterAnim;
                                removeOp.popEnterAnim = op.popEnterAnim;
                                removeOp.exitAnim = op.exitAnim;
                                removeOp.popExitAnim = op.popExitAnim;
                                mOps.add(opNum, removeOp);
                                added.remove(old);
                                opNum++;
                            }
                        }
                    }
                    if (alreadyAdded) {
                        mOps.remove(opNum);
                        opNum--;
                    } else {
                        op.cmd = OP_ADD;
                        added.add(f);
                    }
                }
                break;
                case OP_SET_PRIMARY_NAV: {
                    // It's ok if this is null, that means we will restore to no active
                    // primary navigation fragment on a pop.
                    mOps.add(opNum, new Op(OP_UNSET_PRIMARY_NAV, oldPrimaryNav));
                    opNum++;
                    // Will be set by the OP_SET_PRIMARY_NAV we inserted before when run
                    oldPrimaryNav = op.fragment;
                }
                break;
            }
        }
        return oldPrimaryNav;
    }
/**
     * Expands all meta-ops into their more primitive equivalents. This must be called prior to
     * {@link #executeOps()} or any other call that operations on mOps for forward navigation.
     * It should not be called for pop/reverse navigation operations.
     *
     * <p>Removes all OP_REPLACE ops and replaces them with the proper add and remove
     * operations that are equivalent to the replace.</p>
     *
     * <p>Adds OP_UNSET_PRIMARY_NAV ops to match OP_SET_PRIMARY_NAV, OP_REMOVE and OP_DETACH
     * ops so that we can restore the old primary nav fragment later. Since callers call this
     * method in a loop before running ops from several transactions at once, the caller should
     * pass the return value from this method as the oldPrimaryNav parameter for the next call.
     * The first call in such a loop should pass the value of
     * {@link FragmentManager#getPrimaryNavigationFragment()}.</p>
     *
     * @param added Initialized to the fragments that are in the mManager.mAdded, this
     *              will be modified to contain the fragments that will be in mAdded
     *              after the execution ({@link #executeOps()}.
     * @param oldPrimaryNav The tracked primary navigation fragment as of the beginning of
     *                      this set of ops
     * @return the new oldPrimaryNav fragment after this record's ops would be run
     */
Expands all meta-ops into their more primitive equivalents. This must be called prior to
#executeOps() or any other call that operations on mOps for forward navigation.
It should not be called for pop/reverse navigation operations.

Removes all OP_REPLACE ops and replaces them with the proper add and remove
operations that are equivalent to the replace.

Adds OP_UNSET_PRIMARY_NAV ops to match OP_SET_PRIMARY_NAV, OP_REMOVE and OP_DETACH
ops so that we can restore the old primary nav fragment later. Since callers call this
method in a loop before running ops from several transactions at once, the caller should
pass the return value from this method as the oldPrimaryNav parameter for the next call.
The first call in such a loop should pass the value of
FragmentManager#getPrimaryNavigationFragment().

@param added Initialized to the fragments that are in the mManager.mAdded, this
will be modified to contain the fragments that will be in mAdded
after the execution ( #executeOps().
@param oldPrimaryNav The tracked primary navigation fragment as of the beginning of
this set of ops
@return the new oldPrimaryNav fragment after this record's ops would be run
Expands all meta - ops into their more primitive equivalents . This must be called prior to #executeOps () or any other call that operations on mOps for forward navigation . It should not be called for pop / reverse navigation operations . Removes all OP_REPLACE ops and replaces them with the proper add and remove operations that are equivalent to the replace . Adds OP_UNSET_PRIMARY_NAV ops to match OP_SET_PRIMARY_NAV OP_REMOVE and OP_DETACH ops so that we can restore the old primary nav fragment later . Since callers call this method in a loop before running ops from several transactions at once the caller should pass the return value from this method as the oldPrimaryNav parameter for the next call . The first call in such a loop should pass the value of FragmentManager#getPrimaryNavigationFragment () . @param added Initialized to the fragments that are in the mManager . mAdded this will be modified to contain the fragments that will be in mAdded after the execution ( #executeOps () . @param oldPrimaryNav The tracked primary navigation fragment as of the beginning of this set of ops @return the new oldPrimaryNav fragment after this record ' s ops would be run
@SuppressWarnings("ReferenceEquality")
    Fragment expandOps(ArrayList<Fragment> added, Fragment oldPrimaryNav) {
        for (int opNum = 0; opNum < mOps.size(); opNum++) {
            final Op op = mOps.get(opNum);
            switch (op.cmd) {
                case OP_ADD:
                case OP_ATTACH:
                    added.add(op.fragment);
                    break;
                case OP_REMOVE:
                case OP_DETACH: {
                    added.remove(op.fragment);
                    if (op.fragment == oldPrimaryNav) {
                        mOps.add(opNum, new Op(OP_UNSET_PRIMARY_NAV, op.fragment));
                        opNum++;
                        oldPrimaryNav = null;
                    }
                }
                break;
                case OP_REPLACE: {
                    final Fragment f = op.fragment;
                    final int containerId = f.mContainerId;
                    boolean alreadyAdded = false;
                    for (int i = added.size() - 1; i >= 0; i--) {
                        final Fragment old = added.get(i);
                        if (old.mContainerId == containerId) {
                            if (old == f) {
                                alreadyAdded = true;
                            } else {
                                if (old == oldPrimaryNav) {
                                    mOps.add(opNum, new Op(OP_UNSET_PRIMARY_NAV, old));
                                    opNum++;
                                    oldPrimaryNav = null;
                                }
                                final Op removeOp = new Op(OP_REMOVE, old);
                                removeOp.enterAnim = op.enterAnim;
                                removeOp.popEnterAnim = op.popEnterAnim;
                                removeOp.exitAnim = op.exitAnim;
                                removeOp.popExitAnim = op.popExitAnim;
                                mOps.add(opNum, removeOp);
                                added.remove(old);
                                opNum++;
                            }
                        }
                    }
                    if (alreadyAdded) {
                        mOps.remove(opNum);
                        opNum--;
                    } else {
                        op.cmd = OP_ADD;
                        added.add(f);
                    }
                }
                break;
                case OP_SET_PRIMARY_NAV: {
                    mOps.add(opNum, new Op(OP_UNSET_PRIMARY_NAV, oldPrimaryNav));
                    opNum++;
                    oldPrimaryNav = op.fragment;
                }
                break;
            }
        }
        return oldPrimaryNav;
    }
@ SuppressWarnings ( "ReferenceEquality" ) Fragment expandOps ( ArrayList < Fragment > added , Fragment oldPrimaryNav ) { for ( int opNum = 0 ; opNum < mOps . size ( ) ; opNum ++ ) { final Op op = mOps . get ( opNum ) ; switch ( op . cmd ) { case OP_ADD : case OP_ATTACH : added . add ( op . fragment ) ; break ; case OP_REMOVE : case OP_DETACH : { added . remove ( op . fragment ) ; if ( op . fragment == oldPrimaryNav ) { mOps . add ( opNum , new Op ( OP_UNSET_PRIMARY_NAV , op . fragment ) ) ; opNum ++ ; oldPrimaryNav = null ; } } break ; case OP_REPLACE : { final Fragment f = op . fragment ; final int containerId = f . mContainerId ; boolean alreadyAdded = false ; for ( int i = added . size ( ) - 1 ; i >= 0 ; i -- ) { final Fragment old = added . get ( i ) ; if ( old . mContainerId == containerId ) { if ( old == f ) { alreadyAdded = true ; } else { if ( old == oldPrimaryNav ) { mOps . add ( opNum , new Op ( OP_UNSET_PRIMARY_NAV , old ) ) ; opNum ++ ; oldPrimaryNav = null ; } final Op removeOp = new Op ( OP_REMOVE , old ) ; removeOp . enterAnim = op . enterAnim ; removeOp . popEnterAnim = op . popEnterAnim ; removeOp . exitAnim = op . exitAnim ; removeOp . popExitAnim = op . popExitAnim ; mOps . add ( opNum , removeOp ) ; added . remove ( old ) ; opNum ++ ; } } } if ( alreadyAdded ) { mOps . remove ( opNum ) ; opNum -- ; } else { op . cmd = OP_ADD ; added . add ( f ) ; } } break ; case OP_SET_PRIMARY_NAV : { mOps . add ( opNum , new Op ( OP_UNSET_PRIMARY_NAV , oldPrimaryNav ) ) ; opNum ++ ; oldPrimaryNav = op . fragment ; } break ; } } return oldPrimaryNav ; }
Expands all meta-ops into their more primitive equivalents.
Expands all meta - ops into their more primitive equivalents .
// This is duplicated from above since we only make // a single pass for expanding ops. Unset any outgoing primary nav. // It's ok if this is null, that means we will restore to no active // primary navigation fragment on a pop. // Will be set by the OP_SET_PRIMARY_NAV we inserted before when run