<commit_before>package com.nordnetab.chcp.main.config;

import android.content.Context;

import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.JsonNodeFactory;
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.nordnetab.chcp.main.utils.VersionHelper;

import java.io.IOException;

/**
 * Created by <NAME> on 28.07.15.
 * <p/>
 * Model for plugin internal preferences.
 */
public class PluginInternalPreferences {

    // json keys of the preference
    private static final String APPLICATION_BUILD_VERSION = "app_build_version";
    private static final String WWW_FOLDER_INSTALLED_FLAG = "www_folder_installed";
    private static final String PREVIOUS_RELEASE_VERSION_NAME = "previous_release_version_name";
    private static final String CURRENT_RELEASE_VERSION_NAME = "current_release_version_name";
    private static final String READY_FOR_INSTALLATION_RELEASE_VERSION_NAME = "ready_for_installation_release_version_name";

    private int appBuildVersion;
    private boolean wwwFolderInstalled;
    private String currentReleaseVersionName;
    private String previousReleaseVersionName;
    private String readyForInstallationReleaseVersionName;

    /**
     * Create instance of the object from JSON string.
     *
     * @param json JSON string
     * @return object instance
     */
    public static PluginInternalPreferences fromJson(final String json) {
        PluginInternalPreferences config = new PluginInternalPreferences();
        try {
            JsonNode jsonNode = new ObjectMapper().readTree(json);
            config.setAppBuildVersion(
                    jsonNode.get(APPLICATION_BUILD_VERSION).asInt()
            );
            config.setWwwFolderInstalled(
                    jsonNode.get(WWW_FOLDER_INSTALLED_FLAG).asBoolean()
            );
            config.setCurrentReleaseVersionName(
                    jsonNode.get(CURRENT_RELEASE_VERSION_NAME).asText()
            );
            config.setPreviousReleaseVersionName(
                    jsonNode.get(PREVIOUS_RELEASE_VERSION_NAME).asText()
            );
            config.setReadyForInstallationReleaseVersionName(
                    jsonNode.get(READY_FOR_INSTALLATION_RELEASE_VERSION_NAME).asText()
            );
        } catch (IOException e) {
            e.printStackTrace();

            config = null;
        }

        return config;
    }

    private PluginInternalPreferences() {
    }

    /**
     * Create default preferences.
     *
     * @param context application context
     * @return default plugin internal preferences
     */
    public static PluginInternalPreferences createDefault(final Context context) {
        final PluginInternalPreferences pluginPrefs = new PluginInternalPreferences();
        pluginPrefs.setAppBuildVersion(VersionHelper.applicationVersionCode(context));
        pluginPrefs.setWwwFolderInstalled(false);
        pluginPrefs.setPreviousReleaseVersionName("");
        pluginPrefs.setReadyForInstallationReleaseVersionName("");
        pluginPrefs.setCurrentReleaseVersionName("");
<commit_msg>Android fix for backwards capability with v1.1.2.<commit_after>package com.nordnetab.chcp.main.config;

import android.content.Context;

import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.JsonNodeFactory;
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.nordnetab.chcp.main.utils.VersionHelper;

import java.io.IOException;

/**
 * Created by <NAME> on 28.07.15.
 * <p/>
 * Model for plugin internal preferences.
 */
public class PluginInternalPreferences {

    // json keys of the preference
    private static final String APPLICATION_BUILD_VERSION = "app_build_version";
    private static final String WWW_FOLDER_INSTALLED_FLAG = "www_folder_installed";
    private static final String PREVIOUS_RELEASE_VERSION_NAME = "previous_release_version_name";
    private static final String CURRENT_RELEASE_VERSION_NAME = "current_release_version_name";
    private static final String READY_FOR_INSTALLATION_RELEASE_VERSION_NAME = "ready_for_installation_release_version_name";

    private int appBuildVersion;
    private boolean wwwFolderInstalled;
    private String currentReleaseVersionName;
    private String previousReleaseVersionName;
    private String readyForInstallationReleaseVersionName;

    /**
     * Create instance of the object from JSON string.
     *
     * @param json JSON string
     * @return object instance
     */
    public static PluginInternalPreferences fromJson(final String json) {
        PluginInternalPreferences config = new PluginInternalPreferences();
        try {
            JsonNode jsonNode = new ObjectMapper().readTree(json);
            config.setAppBuildVersion(
                    jsonNode.get(APPLICATION_BUILD_VERSION).asInt()
            );
            config.setWwwFolderInstalled(
                    jsonNode.get(WWW_FOLDER_INSTALLED_FLAG).asBoolean()
            );

            if (jsonNode.has(CURRENT_RELEASE_VERSION_NAME)) {
                config.setCurrentReleaseVersionName(
                        jsonNode.get(CURRENT_RELEASE_VERSION_NAME).asText()
                );
            }

            if (jsonNode.has(PREVIOUS_RELEASE_VERSION_NAME)) {
                config.setPreviousReleaseVersionName(
                        jsonNode.get(PREVIOUS_RELEASE_VERSION_NAME).asText()
                );
            }

            if (jsonNode.has(READY_FOR_INSTALLATION_RELEASE_VERSION_NAME)) {
                config.setReadyForInstallationReleaseVersionName(
                        jsonNode.get(READY_FOR_INSTALLATION_RELEASE_VERSION_NAME).asText()
                );
            }
        } catch (IOException e) {
            e.printStackTrace();

            config = null;
        }

        return config;
    }

    private PluginInternalPreferences() {
        currentReleaseVersionName = "";
        previousReleaseVersionName = "";
        readyForInstallationReleaseVersionName = "";
    }

    /**
     * Create default preferences.
     *
     * @param context application context
     * @return default plugin internal preferences
     */
    public static PluginInternalPreferences createDefault(final Context context) {
        final PluginInternalPreferences pluginPrefs = new PluginInternalPreferences();
        pluginPrefs.setAppBuildVersion(VersionHelper.applicationVersionCode(context));
        pluginPrefs.setWwwFolderInstalled(false);
        pluginPrefs.setPreviousReleaseVersionName("");
        pluginPrefs.setReadyForInstallationReleaseVersionName("");
        pluginPrefs.setCurrentReleaseVersionName("");

{'fraction_non_alphanumeric': 0.0730445068756469, 'fraction_numerical': 0.002217950613633003, 'mean_word_length': 3.0527261833433195, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 4, 'xml': 8}, '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': '1466658', 'n_tokens_mistral': 1792, 'n_tokens_neox': 1661, 'n_words': 331}