<commit_before>/*
 * Copyright 2013 Square Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package flow;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Parcelable;
import android.support.annotation.CheckResult;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.view.View;

import java.util.Iterator;

import static flow.Preconditions.checkArgument;
import static flow.Preconditions.checkNotNull;

/**
 * Holds the current truth, the history of screens, and exposes operations to change it.
 */
public final class Flow {
    public static final KeyParceler DEFAULT_KEY_PARCELER = new KeyParceler() { //
        @Override
        public Parcelable toParcelable(Object key) {
            return (Parcelable) key;
        }

        @Override
        public Object toKey(Parcelable parcelable) {
            return parcelable;
        }
    };

    @NonNull
    public static Flow get(@NonNull View view) {
        return get(view.getContext());
    }

    @NonNull
    public static Flow get(@NonNull Context context) {
        Flow flow = InternalContextWrapper.getFlow(context);
        if(null == flow) {
            throw new IllegalStateException("Context was not wrapped with flow. " + "Make sure attachBaseContext was overridden in your main activity");
        }
        return flow;
    }

    /**
     * @return null if context has no Flow key embedded.
     */
    @Nullable
    public static <T> T getKey(@NonNull Context context) {
        final FlowContextWrapper wrapper = FlowContextWrapper.get(context);
        if(wrapper == null) {
            return null;
        }
        return wrapper.getKey();
    }

    /**
     * @return null if view's Context has no Flow key embedded.
     */
    @Nullable
    public static <T> T getKey(@NonNull View view) {
        return getKey(view.getContext());
    }

    @NonNull
    public static Installer configure(@NonNull Context baseContext, @NonNull Activity activity) {
        return new Installer(baseContext, activity);
    }

    /**
     * Adds a history as an extra to an Intent.
     */
    public void addHistory(@NonNull Intent intent, @NonNull History history, @NonNull KeyParceler parceler) {
        InternalLifecycleIntegration.addHistoryToIntent(intent, history, parceler, keyManager);
    }<commit_msg>added method to bind intent history w/o state<commit_after>/*
 * Copyright 2013 Square Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package flow;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Parcelable;
import android.support.annotation.CheckResult;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.view.View;

import java.util.Iterator;

import static flow.Preconditions.checkArgument;
import static flow.Preconditions.checkNotNull;

/**
 * Holds the current truth, the history of screens, and exposes operations to change it.
 */
public final class Flow {
    public static final KeyParceler DEFAULT_KEY_PARCELER = new KeyParceler() { //
        @Override
        public Parcelable toParcelable(Object key) {
            return (Parcelable) key;
        }

        @Override
        public Object toKey(Parcelable parcelable) {
            return parcelable;
        }
    };

    @NonNull
    public static Flow get(@NonNull View view) {
        return get(view.getContext());
    }

    @NonNull
    public static Flow get(@NonNull Context context) {
        Flow flow = InternalContextWrapper.getFlow(context);
        if(null == flow) {
            throw new IllegalStateException("Context was not wrapped with flow. " + "Make sure attachBaseContext was overridden in your main activity");
        }
        return flow;
    }

    /**
     * @return null if context has no Flow key embedded.
     */
    @Nullable
    public static <T> T getKey(@NonNull Context context) {
        final FlowContextWrapper wrapper = FlowContextWrapper.get(context);
        if(wrapper == null) {
            return null;
        }
        return wrapper.getKey();
    }

    /**
     * @return null if view's Context has no Flow key embedded.
     */
    @Nullable
    public static <T> T getKey(@NonNull View view) {
        return getKey(view.getContext());
    }

    @NonNull
    public static Installer configure(@NonNull Context baseContext, @NonNull Activity activity) {
        return new Installer(baseContext, activity);
    }

    /**
     * Adds a history as an extra to an Intent.
     */
    public void addHistoryToIntent(@NonNull Intent intent, @NonNull History history, @NonNull KeyParceler parceler) {
        InternalLifecycleIntegration.addHistoryToIntent(intent, history, parceler, keyManager);
    }

    public static void addHistoryToIntentWithoutState(@NonNull Intent intent, @NonNull History history, @NonNull KeyParceler parceler) {
        InternalLifecycleIntegration.addHistoryToIntent(intent, history, parceler, null);
    }
{'fraction_non_alphanumeric': 0.08245901639344262, 'fraction_numerical': 0.002622950819672131, 'mean_word_length': 3.0377233620119126, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '6625285', 'n_tokens_mistral': 1581, 'n_tokens_neox': 1573, 'n_words': 571}