<commit_before>package com.pixable.pixalytics.core;

import android.content.Context;

import com.pixable.pixalytics.core.platform.Platform;
import com.pixable.pixalytics.core.proxy.PlatformProxy;
import com.pixable.pixalytics.core.trace.TraceProxy;

import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;

/**
 * Entry point for the Pixalytics. To make usage simple, it is a singleton.
 * <p/>
 * In your {@link android.app.Application#onCreate} lifecycle method, construct the singleton
 * instance with {@link #createInstance}, and then use {@link #onApplicationCreate} right there to
 * initialize the application tracking.
 * <p/>
 * After that, use {@link #get} to call the other methods as needed.
 */
public class Pixalytics {
    private static final String TAG = Pixalytics.class.getSimpleName();
    static Pixalytics INSTANCE;

    private Config configuration;

    /**
     * Map of platform IDs to proxies to be able to have the client just use IDs.
     */
    private Map<String, PlatformProxy> platformProxyMap = new HashMap<>();
    private boolean initialized = false;

    private Pixalytics(Config configuration) {
        this.configuration = configuration;
    }

    public static Pixalytics createInstance(Config configuration) {
        if (INSTANCE == null) {
            INSTANCE = new Pixalytics(configuration);
            return INSTANCE;
        } else {
            throw new IllegalStateException("The singleton was already instantiated");
        }
    }

    /**
     * Returns the singleton instance. It should typically be called {@code getInstance}, but we
     * decided to make it shorter given that it's used extensively.
     */
    public static Pixalytics get() {
        if (INSTANCE == null) {
            throw new IllegalStateException("The singleton is not initialized");
        } else {
            return INSTANCE;
        }
    }

    /**
     * To be called from the {@code onCreate} method of your {@link android.app.Application}
     * instance.
     * <p/>
     * This is required.
     *
     * @param context application context
     */
    public void onApplicationCreate(Context context) {
        for (TraceProxy trace : configuration.getTraces()) {
            trace.traceMessage(TraceProxy.Level.DEBUG,
                    "On application create",
                    Collections.<String, Object>emptyMap(),
                    configuration.getPlatforms());
        }

        for (Platform platform : configuration.getPlatforms()) {
            platform.getProxy().onApplicationCreate(context);

            platformProxyMap.put(platform.getId(), platform.getProxy());
        }

        initialized = true;
    }

    /**
     * To be called from the {@code onStart} of every activity in your application. This lifecycle
     * method is used to open session. Not all tracking services support it.
     *
     * @param context activity context, not the global application context
     * @param platformIds platforms to which this event is to be sent. At least one platform must
     *                    be provided
     */<commit_msg>Fixed javadoc parse errors<commit_after>package com.pixable.pixalytics.core;

import android.content.Context;

import com.pixable.pixalytics.core.platform.Platform;
import com.pixable.pixalytics.core.proxy.PlatformProxy;
import com.pixable.pixalytics.core.trace.TraceProxy;

import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;

/**
 * Entry point for the Pixalytics. To make usage simple, it is a singleton.
 * <p>
 * In your {@link android.app.Application#onCreate} lifecycle method, construct the singleton
 * instance with {@link #createInstance}, and then use {@link #onApplicationCreate} right there to
 * initialize the application tracking.
 * <p>
 * After that, use {@link #get} to call the other methods as needed.
 */
public class Pixalytics {
    private static final String TAG = Pixalytics.class.getSimpleName();
    static Pixalytics INSTANCE;

    private Config configuration;

    /**
     * Map of platform IDs to proxies to be able to have the client just use IDs.
     */
    private Map<String, PlatformProxy> platformProxyMap = new HashMap<>();
    private boolean initialized = false;

    private Pixalytics(Config configuration) {
        this.configuration = configuration;
    }

    public static Pixalytics createInstance(Config configuration) {
        if (INSTANCE == null) {
            INSTANCE = new Pixalytics(configuration);
            return INSTANCE;
        } else {
            throw new IllegalStateException("The singleton was already instantiated");
        }
    }

    /**
     * Returns the singleton instance. It should typically be called {@code getInstance}, but we
     * decided to make it shorter given that it's used extensively.
     */
    public static Pixalytics get() {
        if (INSTANCE == null) {
            throw new IllegalStateException("The singleton is not initialized");
        } else {
            return INSTANCE;
        }
    }

    /**
     * To be called from the {@code onCreate} method of your {@link android.app.Application}
     * instance.
     * <p>
     * This is required.
     *
     * @param context application context
     */
    public void onApplicationCreate(Context context) {
        for (TraceProxy trace : configuration.getTraces()) {
            trace.traceMessage(TraceProxy.Level.DEBUG,
                    "On application create",
                    Collections.<String, Object>emptyMap(),
                    configuration.getPlatforms());
        }

        for (Platform platform : configuration.getPlatforms()) {
            platform.getProxy().onApplicationCreate(context);

            platformProxyMap.put(platform.getId(), platform.getProxy());
        }

        initialized = true;
    }

    /**
     * To be called from the {@code onStart} of every activity in your application. This lifecycle
     * method is used to open session. Not all tracking services support it.
     *
     * @param context activity context, not the global application context
     * @param platformIds platforms to which this event is to be sent. At least one platform must
     *                    be provided
     */
{'fraction_non_alphanumeric': 0.0879207297892419, 'fraction_numerical': 0.0, 'mean_word_length': 2.6483075157773954, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 15, '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': '5397952', 'n_tokens_mistral': 1641, 'n_tokens_neox': 1576, 'n_words': 559}