<commit_before>import com.telekom.m2m.cot.restsdk.CloudOfThingsPlatform;
import com.telekom.m2m.cot.restsdk.devicecontrol.CotCredentials;

/**
 * Helper class that is used by the examples and contains the boring infrastructure code.
 */
class PlatformFactory {

    /**
     * Reads credentials from environment variables and uses them to createFromEnvironment a Cloud of Things platform object.
     *
     * @return The platform object.
     */
    static CloudOfThingsPlatform createFromEnvironment() {
        // Ensure that you populate the required environment variables with your credentials.
        String host = System.getenv("COT_REST_CLIENT_HOST");
        if (host == null) {
            throw new RuntimeException("Cloud of Things host missing. Provide it via environment variable 'COT_REST_CLIENT_HOST'.");
        }
        String tenant = System.getenv("COT_REST_CLIENT_TENANT");
        if (tenant == null) {
            throw new RuntimeException("Cloud of Things tenant missing. Provide it via environment variable 'COT_REST_CLIENT_TENANT'.");
        }
        String user = System.getenv("COT_REST_CLIENT_USER");
        if (user == null) {
            throw new RuntimeException("Cloud of Things user missing. Provide it via environment variable 'COT_REST_CLIENT_USER'.");
        }
        String password = System.getenv("COT_REST_CLIENT_PASSWORD");
        if (password == null) {
            throw new RuntimeException("Cloud of Things password missing. Provide it via environment variable 'COT_REST_CLIENT_PASSWORD'.");
        }
        // From the platform we can get the numerous APIs, for example the AlarmApi:
        return new CloudOfThingsPlatform(host, new CotCredentials(tenant, user, password));
    }
}<commit_msg>refactoring: extracted method to read credential part from environment variable<commit_after>import com.telekom.m2m.cot.restsdk.CloudOfThingsPlatform;
import com.telekom.m2m.cot.restsdk.devicecontrol.CotCredentials;

/**
 * Helper class that is used by the examples and contains the boring infrastructure code.
 */
class PlatformFactory {

    /**
     * Reads credentials from environment variables and uses them to createFromEnvironment a Cloud of Things platform object.
     *
     * @return The platform object.
     */
    static CloudOfThingsPlatform createFromEnvironment() {
        return new CloudOfThingsPlatform(
                readFromEnvironment("host"),
                new CotCredentials(
                        readFromEnvironment("tenant"),
                        readFromEnvironment("user"),
                        readFromEnvironment("password")
                )
        );
    }

    /**
     * @param name The name of the environment variable (without prefix, case does not matter).
     * @return The value.
     */
    private static String readFromEnvironment(String name) {
        final String environmentVariableName = "COT_REST_CLIENT_" + name.toUpperCase();
        String value = System.getenv(environmentVariableName);
        if (value == null) {
            throw new RuntimeException("Cloud of Things " + name + " missing. Provide it via environment variable '" + environmentVariableName + "'.");
        }
        return value;
    }
}
{'fraction_non_alphanumeric': 0.08139894769421231, 'fraction_numerical': 0.0012380068090374497, 'mean_word_length': 2.8522050059594757, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '2968563', 'n_tokens_mistral': 814, 'n_tokens_neox': 798, 'n_words': 259}