<commit_before>/**
 * WL Multi Language Support Plugin
 * Copyright (C) 2013 MK124
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as
 * published by the Free Software Foundation, either version 3 of the
 * License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

package net.gtaun.wl.lang.dialog;

import java.util.Arrays;
import java.util.Map;
import java.util.TreeMap;

import net.gtaun.shoebill.object.Player;
import net.gtaun.util.event.EventManager;
import net.gtaun.wl.common.dialog.DialogUtils;
import net.gtaun.wl.common.dialog.WlListDialog;
import net.gtaun.wl.lang.Language;
import net.gtaun.wl.lang.LanguageService;
import net.gtaun.wl.lang.LanguageService.SelectLanguageCallback;

public class LanguageSelectionDialog
{
	public static WlListDialog create(Player player, EventManager rootEventManager, LanguageService service, SelectLanguageCallback callback)
	{
		Map<Float, Language> languages = new TreeMap<Float, Language>((Float o1, Float o2) -> o1 < o2 ? 1 : -1);
		Arrays.stream(Language.values()).forEach((lang) ->
		{
			float coverPercent = service.getCoverPercent(lang) * 100.0f;
			if (coverPercent > 0.0f) languages.put(coverPercent, lang);
		});
		
		return WlListDialog.create(player, rootEventManager)
			.caption("Please select your language")
			.execute((b) ->
				{
					languages.entrySet().forEach((entry) ->
					{
						Language lang = entry.getValue();
						String itemText = String.format("%1$s(%2$s, %3$1.1f%%)", DialogUtils.rightPad(lang.getNativeCp1252()+" ", 16, 8), lang.getName(), entry.getKey());
						b.item(itemText, (d) ->
						{
							player.playSound(1083);
							service.setPlayerLanguage(player, lang);
							if (callback != null) callback.onSelectLanguage(player, lang);
						});
					});
				})
			.onClickCancel((d)->
				{
					player.playSound(1083);
					d.show();
				})
			.build();
	}
}<commit_msg>Buggy Eclipse JDT Compiler<commit_after>/**
 * WL Multi Language Support Plugin
 * Copyright (C) 2013 MK124
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as
 * published by the Free Software Foundation, either version 3 of the
 * License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

package net.gtaun.wl.lang.dialog;

import java.util.Arrays;
import java.util.Map;
import java.util.TreeMap;

import net.gtaun.shoebill.common.dialog.ListDialog.AbstractListDialogBuilder;
import net.gtaun.shoebill.object.Player;
import net.gtaun.util.event.EventManager;
import net.gtaun.wl.common.dialog.DialogUtils;
import net.gtaun.wl.common.dialog.WlListDialog;
import net.gtaun.wl.lang.Language;
import net.gtaun.wl.lang.LanguageService;
import net.gtaun.wl.lang.LanguageService.SelectLanguageCallback;

public class LanguageSelectionDialog
{
	public static WlListDialog create(Player player, EventManager rootEventManager, LanguageService service, SelectLanguageCallback callback)
	{
		Map<Float, Language> languages = new TreeMap<Float, Language>((Float o1, Float o2) -> o1 < o2 ? 1 : -1);
		Arrays.stream(Language.values()).forEach((lang) ->
		{
			float coverPercent = service.getCoverPercent(lang) * 100.0f;
			if (coverPercent > 0.0f) languages.put(coverPercent, lang);
		});
		
		return WlListDialog.create(player, rootEventManager)
			.caption("Please select your language")
			.execute((b) ->
			{
				languages.entrySet().forEach((entry) ->
				{
					Language lang = entry.getValue();
					String itemText = String.format("%1$s(%2$s, %3$1.1f%%)", DialogUtils.rightPad(lang.getNativeCp1252()+" ", 16, 8), lang.getName(), entry.getKey());
					
					// XXX: Buggy Eclipse JDT Compiler
					((AbstractListDialogBuilder<?, ?>) b).item(itemText, (d) ->
					{
						player.playSound(1083);
						service.setPlayerLanguage(player, lang);
						if (callback != null) callback.onSelectLanguage(player, lang);
					});
				});
			})
			.onClickCancel((d)->
			{
				player.playSound(1083);
				d.show();
			})
			.build();
	}
}
{'fraction_non_alphanumeric': 0.12079573420836752, 'fraction_numerical': 0.016406890894175553, 'mean_word_length': 3.9163306451612905, 'pattern_counts': {'":': 0, '<': 12, '<?xml version=': 0, '>': 24, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '2404944', 'n_tokens_mistral': 1703, 'n_tokens_neox': 1474, 'n_words': 423}