<commit_before>/* 
 * Copyright (C) 2016 <NAME>
 * All rights reserved.
 *
 * This software may be modified and distributed under the terms
 * of the BSD license.  See the LICENSE file for details.
 */
package com.bouye.gw2.sab.query;

import api.web.gw2.mapping.core.JsonpContext;
import api.web.gw2.mapping.core.PageResult;
import api.web.gw2.mapping.v1.guilddetails.GuildDetails;
import api.web.gw2.mapping.v2.account.Account;
import api.web.gw2.mapping.v2.guild.id.log.LogEvent;
import api.web.gw2.mapping.v2.guild.id.members.Member;
import api.web.gw2.mapping.v2.tokeninfo.TokenInfo;
import api.web.gw2.mapping.v2.worlds.World;
import api.web.gw2.mapping.v2.wvw.matches.Match;
import com.bouye.gw2.sab.SABConstants;
import com.bouye.gw2.sab.demo.DemoSupport;
import java.io.IOException;
import java.net.URL;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Locale;
import java.util.Optional;
import java.util.Set;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 * Centralized class for web-queries.
 * @author <NAME>
 */
public enum WebQuery {
    INSTANCE;

    /**
     * Return the language code to be used when doing queries that return localized values.
     * <br>If the user's current language is not supported, the default locale will be used instead.
     * @return A {@code String} instance, never {@code null}.
     */
    private String getLanguageCode() {
        final Set<String> supportedLanguages = SABConstants.INSTANCE.getSupportedWebApiLanguages();
        final String currentLanguage = Locale.getDefault().getLanguage();
        return supportedLanguages.contains(currentLanguage) ? currentLanguage : SABConstants.DEFAULT_WEBAPI_LANGUAGE;
    }

    /**
     * Convert given {@code int} ids into a {@code String} for the query.
     * @param ids the ids.
     * @return A {@code String}, never {@code null}.
     * <br>Contains {@code "all"} no id provided.
     */
    private String idsToString(final int... ids) {
        String result = "all"; // NOI18N.
        if (ids.length > 0) {
            final StringBuilder builder = new StringBuilder();
            for (final int id : ids) {
                builder.append(id);
                builder.append(','); // NOI18N.
            }
            // Remove last comma.
            builder.replace(builder.length() - 1, builder.length(), ""); // NOI18N.
            result = builder.toString();
        }
        return result;
    }

    /**
     * Convert given {@code String} ids into a {@code String} for the query.
     * @param ids the ids.
     * @return A {@code String}, never {@code null}.
     * <br>Contains {@code "all"} no id provided.
     */
    public String idsToString(final String... ids) {
        String result = "all"; // NOI18N.
        if (ids.length > 0) {
            final StringBuilder builder = new StringBuilder();
            for (final String id : ids) {<commit_msg>Made the int variant of idsToString() public. Added a method to encore character names that use non-iso letters.<commit_after>/* 
 * Copyright (C) 2016 <NAME>
 * All rights reserved.
 *
 * This software may be modified and distributed under the terms
 * of the BSD license.  See the LICENSE file for details.
 */
package com.bouye.gw2.sab.query;

import api.web.gw2.mapping.core.JsonpContext;
import api.web.gw2.mapping.core.PageResult;
import api.web.gw2.mapping.v1.guilddetails.GuildDetails;
import api.web.gw2.mapping.v2.account.Account;
import api.web.gw2.mapping.v2.guild.id.log.LogEvent;
import api.web.gw2.mapping.v2.guild.id.members.Member;
import api.web.gw2.mapping.v2.tokeninfo.TokenInfo;
import api.web.gw2.mapping.v2.worlds.World;
import api.web.gw2.mapping.v2.wvw.matches.Match;
import com.bouye.gw2.sab.SABConstants;
import com.bouye.gw2.sab.demo.DemoSupport;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.net.URL;
import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Locale;
import java.util.Optional;
import java.util.Set;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 * Centralized class for web-queries.
 * @author <NAME>
 */
public enum WebQuery {
    INSTANCE;

    public String encodeURLParameter(final String value) throws UnsupportedEncodingException {
        String result = URLEncoder.encode(value, "utf-8"); // NOI18N.
        result = result.replaceAll("\\+", "%20"); // NOI18N.
        return result;
    }
    
    /**
     * Return the language code to be used when doing queries that return localized values.
     * <br>If the user's current language is not supported, the default locale will be used instead.
     * @return A {@code String} instance, never {@code null}.
     */
    private String getLanguageCode() {
        final Set<String> supportedLanguages = SABConstants.INSTANCE.getSupportedWebApiLanguages();
        final String currentLanguage = Locale.getDefault().getLanguage();
        return supportedLanguages.contains(currentLanguage) ? currentLanguage : SABConstants.DEFAULT_WEBAPI_LANGUAGE;
    }

    /**
     * Convert given {@code int} ids into a {@code String} for the query.
     * @param ids the ids.
     * @return A {@code String}, never {@code null}.
     * <br>Contains {@code "all"} no id provided.
     */
    public String idsToString(final int... ids) {
        String result = "all"; // NOI18N.
        if (ids.length > 0) {
            final StringBuilder builder = new StringBuilder();
            for (final int id : ids) {
                builder.append(id);
                builder.append(','); // NOI18N.
            }
            // Remove last comma.
            builder.replace(builder.length() - 1, builder.length(), ""); // NOI18N.
            result = builder.toString();
        }
        return result;
    }

    /**
     * Convert given {@code String} ids into a {@code String} for the query.
     * @param ids the ids.
     * @return A {@code String}, never {@code null}.
     * <br>Contains {@code "all"} no id provided.
     */
    public String idsToString(final String... ids) {
        String result = "all"; // NOI18N.
        if (ids.length > 0) {
            final StringBuilder builder = new StringBuilder();
            for (final String id : ids) {
{'fraction_non_alphanumeric': 0.12157721796276014, 'fraction_numerical': 0.01173525269910812, 'mean_word_length': 2.8115682766845556, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 19, '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': '7314016', 'n_tokens_mistral': 1965, 'n_tokens_neox': 1921, 'n_words': 543}