<commit_before>package com.growthbeat;

import android.content.Context;

import com.growthbeat.http.GrowthbeatHttpClient;
import com.growthbeat.intenthandler.IntentHandler;
import com.growthbeat.intenthandler.NoopIntentHandler;
import com.growthbeat.intenthandler.UrlIntentHandler;
import com.growthbeat.link.GrowthLink;
import com.growthbeat.message.GrowthMessage;
import com.growthbeat.model.Client;
import com.growthbeat.model.GrowthPushClient;
import com.growthbeat.model.Intent;
import com.growthpush.GrowthPush;

import java.util.Arrays;
import java.util.List;

public class Growthbeat {

    private static final String LOGGER_DEFAULT_TAG = "Growthbeat";
    private static final String HTTP_CLIENT_DEFAULT_BASE_URL = "https://api.growthbeat.com/";
    private static final int HTTP_CLIENT_DEFAULT_CONNECT_TIMEOUT = 60 * 1000;
    private static final int HTTP_CLIENT_DEFAULT_READ_TIMEOUT = 60 * 1000;
    private static final String PREFERENCE_DEFAULT_FILE_NAME = "growthbeat-preferences";

    private static final Growthbeat instance = new Growthbeat();
    private final Logger logger = new Logger(LOGGER_DEFAULT_TAG);
    private final GrowthbeatHttpClient httpClient = new GrowthbeatHttpClient(HTTP_CLIENT_DEFAULT_BASE_URL,
        HTTP_CLIENT_DEFAULT_CONNECT_TIMEOUT, HTTP_CLIENT_DEFAULT_READ_TIMEOUT);
    private final GrowthbeatThreadExecutor executor = new GrowthbeatThreadExecutor();
    private final Preference preference = new Preference(PREFERENCE_DEFAULT_FILE_NAME);

    private Context context = null;

    private boolean initialized = false;
    private Client client;

    private List<? extends IntentHandler> intentHandlers;

    private Growthbeat() {
        super();
    }

    public static Growthbeat getInstance() {
        return instance;
    }

    public void initialize(Context context, final String applicationId, final String credentialId) {

        if (initialized)
            return;
        initialized = true;

        if (context == null) {
            logger.warning("The context parameter cannot be null.");
            return;
        }

        this.context = context.getApplicationContext();

        this.intentHandlers = Arrays.asList(new UrlIntentHandler(this.context), new NoopIntentHandler());

        logger.info(String.format("Initializing... (applicationId:%s)", applicationId));

        preference.setContext(Growthbeat.this.context);

        GrowthPushClient growthPushClient = GrowthPushClient.load();
        client = Client.load();

        if (growthPushClient != null) {
            if (client != null && client.getId().equals(growthPushClient.getGrowthbeatClientId())
                && client.getApplication().getId().equals(growthPushClient.getGrowthbeatApplicationId())
                && client.getApplication().getId().equals(applicationId)) {
                logger.info(String.format("Client already exists. (id:%s)", client.getId()));
                GrowthPushClient.removePreference();
                return;
            }
        } else {
            if (client != null && client.getApplication().getId().equals(applicationId)) {
                logger.info(String.format("Client already exists. (id:%s)", client.getId()));
                return;
            }
        }

        preference.removeAll();
        client = null;

        executor.execute(new Runnable() {

            @Override
            public void run() {

                GrowthPushClient growthPushClient = GrowthPushClient.load();
                if (growthPushClient != null) {
                    growthPushClient = GrowthPushClient.findByGrowthPushClientId(growthPushClient.getId(), growthPushClient.getCode());
                    logger.info(String
                        .format("Growth Push Client found. Convert GrowthPush Client into Growthbeat Client. (GrowthPushClientId:%d, GrowthbeatClientId:%s)",
                            growthPushClient.getId(), growthPushClient.getGrowthbeatClientId()));

                    client = Client.findById(growthPushClient.getGrowthbeatClientId(), credentialId);
                    if (client == null) {
                        logger.info("Failed to convert client.");
                        client = null;
                    } else {
                        Client.save(client);
                        logger.info(String.format("Client converted. (id:%s)", client.getId()));
                    }

                    GrowthPushClient.removePreference();

                } else {
                    logger.info(String.format("Creating client... (applicationId:%s)", applicationId));
                    client = Client.create(applicationId, credentialId);

                    if (client == null) {
                        logger.info("Failed to create client.");
                        return;
                    }

                    Client.save(client);
                    logger.info(String.format("Client created. (id:%s)", client.getId()));
                }
            }
<commit_msg>set client completed confirm client<commit_after>package com.growthbeat;

import android.content.Context;

import com.growthbeat.http.GrowthbeatHttpClient;
import com.growthbeat.intenthandler.IntentHandler;
import com.growthbeat.intenthandler.NoopIntentHandler;
import com.growthbeat.intenthandler.UrlIntentHandler;
import com.growthbeat.link.GrowthLink;
import com.growthbeat.message.GrowthMessage;
import com.growthbeat.model.Client;
import com.growthbeat.model.GrowthPushClient;
import com.growthbeat.model.Intent;
import com.growthpush.GrowthPush;

import java.util.Arrays;
import java.util.List;

public class Growthbeat {

    private static final String LOGGER_DEFAULT_TAG = "Growthbeat";
    private static final String HTTP_CLIENT_DEFAULT_BASE_URL = "https://api.growthbeat.com/";
    private static final int HTTP_CLIENT_DEFAULT_CONNECT_TIMEOUT = 60 * 1000;
    private static final int HTTP_CLIENT_DEFAULT_READ_TIMEOUT = 60 * 1000;
    private static final String PREFERENCE_DEFAULT_FILE_NAME = "growthbeat-preferences";

    private static final Growthbeat instance = new Growthbeat();
    private final Logger logger = new Logger(LOGGER_DEFAULT_TAG);
    private final GrowthbeatHttpClient httpClient = new GrowthbeatHttpClient(HTTP_CLIENT_DEFAULT_BASE_URL,
        HTTP_CLIENT_DEFAULT_CONNECT_TIMEOUT, HTTP_CLIENT_DEFAULT_READ_TIMEOUT);
    private final GrowthbeatThreadExecutor executor = new GrowthbeatThreadExecutor();
    private final Preference preference = new Preference(PREFERENCE_DEFAULT_FILE_NAME);

    private Context context = null;

    private boolean initialized = false;
    private Client client;

    private List<? extends IntentHandler> intentHandlers;

    private Growthbeat() {
        super();
    }

    public static Growthbeat getInstance() {
        return instance;
    }

    public void initialize(Context context, final String applicationId, final String credentialId) {

        if (initialized)
            return;
        initialized = true;

        if (context == null) {
            logger.warning("The context parameter cannot be null.");
            return;
        }

        this.context = context.getApplicationContext();

        this.intentHandlers = Arrays.asList(new UrlIntentHandler(this.context), new NoopIntentHandler());

        logger.info(String.format("Initializing... (applicationId:%s)", applicationId));

        preference.setContext(Growthbeat.this.context);

        GrowthPushClient growthPushClient = GrowthPushClient.load();
        Client existingClient = Client.load();

        if (growthPushClient != null) {
            if (existingClient != null && existingClient.getId().equals(growthPushClient.getGrowthbeatClientId())
                && existingClient.getApplication().getId().equals(growthPushClient.getGrowthbeatApplicationId())
                && existingClient.getApplication().getId().equals(applicationId)) {
                logger.info(String.format("Client already exists. (id:%s)", existingClient.getId()));
                client = existingClient;
                GrowthPushClient.removePreference();
                return;
            }
        } else {
            if (existingClient != null && existingClient.getApplication().getId().equals(applicationId)) {
                logger.info(String.format("Client already exists. (id:%s)", existingClient.getId()));
                client = existingClient;
                return;
            }
        }

        preference.removeAll();
        client = null;

        executor.execute(new Runnable() {

            @Override
            public void run() {

                GrowthPushClient growthPushClient = GrowthPushClient.load();
                if (growthPushClient != null) {
                    growthPushClient = GrowthPushClient.findByGrowthPushClientId(growthPushClient.getId(), growthPushClient.getCode());
                    logger.info(String
                        .format("Growth Push Client found. Convert GrowthPush Client into Growthbeat Client. (GrowthPushClientId:%d, GrowthbeatClientId:%s)",
                            growthPushClient.getId(), growthPushClient.getGrowthbeatClientId()));

                    Client convertedClient = Client.findById(growthPushClient.getGrowthbeatClientId(), credentialId);
                    if (client == null) {
                        logger.info("Failed to convert existingClient.");
                    } else {
                        Client.save(client);
                        logger.info(String.format("Client converted. (id:%s)", client.getId()));
                    }

                    client = convertedClient;
                    GrowthPushClient.removePreference();

                } else {
                    logger.info(String.format("Creating existingClient... (applicationId:%s)", applicationId));
                    Client newClient = Client.create(applicationId, credentialId);

                    if (newClient == null) {
                        logger.info("Failed to create existingClient.");
                        return;
                    }

                    Client.save(newClient);
                    client = newClient;
                    logger.info(String.format("Client created. (id:%s)", newClient.getId()));
                }
            }

{'fraction_non_alphanumeric': 0.09442559379544353, 'fraction_numerical': 0.00232670867668444, 'mean_word_length': 2.474570562478949, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 2, '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': '7055663', 'n_tokens_mistral': 2644, 'n_tokens_neox': 2460, 'n_words': 539}