<commit_before>package io.reist.visum.view;

import android.app.Fragment;
import android.app.FragmentManager;
import android.app.FragmentTransaction;
import android.support.annotation.IdRes;
import android.support.annotation.Nullable;

/**
 * Created by defuera on 29/01/2016.
 * This Activity helps you handle your fragments
 */
public class VisumFragmentManager {

    /**
     * @param fragment - fragment to display
     * @param remove   - boolean, stays for whether current fragment should be thrown away or stay in a back stack.
     *                 false to stay in a back stack
     * @param resId    - id of view group to put fragment to
     */
    public static void showFragment(FragmentManager fragmentManager, VisumFragment fragment, @IdRes int resId, boolean remove) {
        showFragment(fragmentManager, fragment, resId, remove, false);
    }

    /**
     * @param popBackStackInclusive all entries up to but not including that entry will be removed
     */
    public static void showFragment(
            FragmentManager fragmentManager,
            VisumFragment fragment,
            @IdRes int resId,
            boolean remove,
            boolean popBackStackInclusive
    ) {

        Fragment topmostFragment = findTopmostFragment(fragmentManager);

        if (topmostFragment != null && fragment.getName().equals(topmostFragment.getTag())) {
            return;
        }

        replace(fragmentManager, topmostFragment, fragment, resId, remove, popBackStackInclusive);

    }

    private static void replace(
            FragmentManager fragmentManager,
            Fragment what,
            VisumFragment with,
            @IdRes int resId,
            boolean remove,
            boolean popBackStackInclusive
    ) {

        if (popBackStackInclusive && fragmentManager.getBackStackEntryCount() > 0) {
            fragmentManager.popBackStackImmediate(fragmentManager.getBackStackEntryAt(0).getName(), FragmentManager.POP_BACK_STACK_INCLUSIVE);
        }

        FragmentTransaction transaction = fragmentManager.beginTransaction();

        if (what != null && !popBackStackInclusive) {
            if (remove) {
                transaction = transaction.remove(what);
            } else {
                transaction = transaction.hide(what);
            }
        }

        String fragmentName = with.getName();

        if (with.isAdded()) {
            transaction = transaction.show(with);
        } else {
            transaction = transaction.add(resId, with, fragmentName);
        }
<commit_msg>fix not possible display multiple instances of one fragment<commit_after>package io.reist.visum.view;

import android.app.Fragment;
import android.app.FragmentManager;
import android.app.FragmentTransaction;
import android.support.annotation.IdRes;
import android.support.annotation.Nullable;

/**
 * Created by defuera on 29/01/2016.
 * This Activity helps you handle your fragments
 */
public class VisumFragmentManager {

    /**
     * @param fragment - fragment to display
     * @param remove   - boolean, stays for whether current fragment should be thrown away or stay in a back stack.
     *                 false to stay in a back stack
     * @param resId    - id of view group to put fragment to
     */
    public static void showFragment(FragmentManager fragmentManager, VisumFragment fragment, @IdRes int resId, boolean remove) {
        showFragment(fragmentManager, fragment, resId, remove, false);
    }

    /**
     * @param popBackStackInclusive all entries up to but not including that entry will be removed
     */
    public static void showFragment(
            FragmentManager fragmentManager,
            VisumFragment fragment,
            @IdRes int resId,
            boolean remove,
            boolean popBackStackInclusive
    ) {

        Fragment topmostFragment = findTopmostFragment(fragmentManager);
        replace(fragmentManager, topmostFragment, fragment, resId, remove, popBackStackInclusive);
    }

    private static void replace(
            FragmentManager fragmentManager,
            @Nullable Fragment what,
            VisumFragment with,
            @IdRes int resId,
            boolean remove,
            boolean popBackStackInclusive
    ) {

        if (popBackStackInclusive && fragmentManager.getBackStackEntryCount() > 0) {
            fragmentManager.popBackStackImmediate(fragmentManager.getBackStackEntryAt(0).getName(), FragmentManager.POP_BACK_STACK_INCLUSIVE);
        }

        FragmentTransaction transaction = fragmentManager.beginTransaction();

        if (what != null && !popBackStackInclusive) {
            if (remove) {
                transaction = transaction.remove(what);
            } else {
                transaction = transaction.hide(what);
            }
        }

        String fragmentName = with.getName();

        if (with.isAdded()) {
            transaction = transaction.show(with);
        } else {
            transaction = transaction.add(resId, with, fragmentName);
        }

{'fraction_non_alphanumeric': 0.07618858165904117, 'fraction_numerical': 0.003978516013526954, 'mean_word_length': 2.479584775086505, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '12968', 'n_tokens_mistral': 1251, 'n_tokens_neox': 1197, 'n_words': 356}