<commit_before>package uk.me.candle.translations;

import java.io.IOException;
import java.io.InputStream;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.text.MessageFormat;
import java.util.HashSet;
import java.util.Locale;
import java.util.MissingResourceException;
import java.util.Properties;
import java.util.Set;
import org.objectweb.asm.ClassAdapter;
import org.objectweb.asm.ClassReader;
import org.objectweb.asm.ClassVisitor;
import org.objectweb.asm.ClassWriter;
import org.objectweb.asm.MethodAdapter;
import org.objectweb.asm.MethodVisitor;
import org.objectweb.asm.Opcodes;
import org.objectweb.asm.Type;

/**
 * Handles translations.
 *
 * General usage:
 *
 * <ul>
 * <li>The bundle class must be public and abstract</li>
 * <li>Methods with no arguments the raw translation is returned.</li>
 * <li>Methods with arguments are passed to MessageFormat to format with the translation and the
 * arguments of the method as the parameters of the MessageFormat</li>
 * <li>Methods must be abstract and have a String return value.</li>
 * <li>Methods must be abstract and have a String return value.</li>
 * <li>Classes must have an accessible constructor that takes a java.util.Locale.</li>
 * </ul>
 *
 * Bundle class:
 * <pre>{@code
 *package com.example.foo
 *public abstract class Foo extends Bundle {
 *  public static Foo get() {
 *	   return BundleCache.get(Foo.class);
 *  }
 *  public static Foo get(Locale locale) {
 *	   return BundleCache.get(Foo.class, locale);
 *  }
 *  public Foo(Locale locale) {
 *	   super(locale);
 *  }
 *  public abstract String bar();
 *  public abstract String zit();
 *  public abstract String pony(String s);
 *  public abstract String iHaveSomeOranges(int i);
 *  public abstract String iHaveAFewArguments(Object o, boolean z, byte b, char c, short s, int i, long l, float f, double d);
 *}
 * }</pre>
 * Bundle resource:
 * <pre>{@code
 *bar=<NAME>
 *zit=zap
 *pony=my horsie''s name is {0}
 *iHaveSomeOranges=I have {0,choice,0#are no oranges|1# one orange|1&lt;are {0,number,integer} oranges}.
 *iHaveAFewArguments=o={0} z={1} b={2} c={3} s={4} i={5} l={6} f={7} d={8}
 * }</pre>
 *
 * When the class is loaded (without a properties specified in the load() method)  it will look for a properties
 * file in the same package as the class, with the same name as the class, but with the classname all lower-case, and
 * the language code appended to the end.
 *
 * In the above example, the Foo bundle will look for the English properties file at
 * {@code /com/example/foo/foo_en.properties }
 * the French will be:
 * {@code /com/example/foo/foo_fr.properties }
 *
 * Usage of the bundle is intended to be as simple as possible.
 *{@code
 *public class App {
 *
 *  public static void main(String[] args) {
 *    BundleCache.setThreadLocale(Locale.ENGLISH);
 *    System.out.println("I know a bar called " + Foo.get().bar());
 *    System.out.println(Foo.get().pony("Sparky"));
 *    System.out.println(Foo.get().iHaveSomeOranges(5));
 *    System.out.println(Foo.get().iHaveAFewArguments("obj", true, (byte)4, 'q', (short)6, 1, 9999, 9.5f, 4.4d));
 *  }
 *}
 * }
 *
 * This will produce the output:
 * {@code
 *I know a bar called <NAME>n
 *my horsie's name is Sparky
 *I have one orange.
 *o=obj z=true b=4 c=q s=6 i=1 l=9,999 f=9.5 d=4.4
 * }
 *
 *
 * @see java.text.MessageFormat
 * @author <NAME>
 */
public class Bundle {
	public enum LoadIgnoreMissing { YES, NO };
	public enum LoadIgnoreExtra { YES, NO };
	public enum LoadIgnoreParameterMisMatch { YES, NO };

	/**
	 * The locale for this bundle. Required for formatting numbers in the subclasses.
	 */
	private final Locale locale;
	/**
	 *
	 * default value for new creations if the options are not specified
	 */
	public static LoadIgnoreMissing LOAD_IGNORE_MISSING = LoadIgnoreMissing.YES;
	public static LoadIgnoreExtra LOAD_IGNORE_EXTRA = LoadIgnoreExtra.YES;
	public static LoadIgnoreParameterMisMatch LOAD_IGNORE_PARAM_MISMATCH = LoadIgnoreParameterMisMatch.YES;

	public Locale getLocale() {
		return locale;
	}

	public Bundle(Locale locale) {
		if (locale == null) {
			throw new NullPointerException("The locale cannot be null");
		}
		this.locale = locale;
	}

	/**
	 * Constructs a bundle implementation for the class and locale.
	 * @throws MissingResourceException if the resource cannot be found.
	 * @throws IOException if there is an error loading the properties
	 * @see #load(java.lang.Class, java.util.Locale, java.util.Properties, boolean, boolean, boolean)
	 */
	static <T extends Bundle> T load(Class<T> cls, Locale locale)
			throws IllegalAccessException, InstantiationException
			, NoSuchMethodException, IOException
			, IllegalArgumentException, InvocationTargetException
			{
		return load(cls, locale, LOAD_IGNORE_MISSING, LOAD_IGNORE_EXTRA, LOAD_IGNORE_PARAM_MISMATCH);
	}
	static <T extends Bundle> T load(Class<T> cls, Locale locale, BundleConfiguration configuration)
			throws IllegalAccessException, InstantiationException
			, NoSuchMethodException, IOException
			, IllegalArgumentException, InvocationTargetException
			{
		final Properties translations = new Properties();
		final String resourcePath =
				cls.getPackage().getName().replace(".", "/")
				+ "/"
				+ cls.getSimpleName().toLowerCase()
				+ "_"
				+ locale.getLanguage()
				+ ".properties";<commit_msg>fixed a filename case issue.<commit_after>package uk.me.candle.translations;

import java.io.IOException;
import java.io.InputStream;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.text.MessageFormat;
import java.util.HashSet;
import java.util.Locale;
import java.util.MissingResourceException;
import java.util.Properties;
import java.util.Set;
import org.objectweb.asm.ClassAdapter;
import org.objectweb.asm.ClassReader;
import org.objectweb.asm.ClassVisitor;
import org.objectweb.asm.ClassWriter;
import org.objectweb.asm.MethodAdapter;
import org.objectweb.asm.MethodVisitor;
import org.objectweb.asm.Opcodes;
import org.objectweb.asm.Type;

/**
 * Handles translations.
 *
 * General usage:
 *
 * <ul>
 * <li>The bundle class must be public and abstract</li>
 * <li>Methods with no arguments the raw translation is returned.</li>
 * <li>Methods with arguments are passed to MessageFormat to format with the translation and the
 * arguments of the method as the parameters of the MessageFormat</li>
 * <li>Methods must be abstract and have a String return value.</li>
 * <li>Methods must be abstract and have a String return value.</li>
 * <li>Classes must have an accessible constructor that takes a java.util.Locale.</li>
 * </ul>
 *
 * Bundle class:
 * <pre>{@code
 *package com.example.foo
 *public abstract class Foo extends Bundle {
 *  public static Foo get() {
 *	   return BundleCache.get(Foo.class);
 *  }
 *  public static Foo get(Locale locale) {
 *	   return BundleCache.get(Foo.class, locale);
 *  }
 *  public Foo(Locale locale) {
 *	   super(locale);
 *  }
 *  public abstract String bar();
 *  public abstract String zit();
 *  public abstract String pony(String s);
 *  public abstract String iHaveSomeOranges(int i);
 *  public abstract String iHaveAFewArguments(Object o, boolean z, byte b, char c, short s, int i, long l, float f, double d);
 *}
 * }</pre>
 * Bundle resource:
 * <pre>{@code
 *bar=<NAME>
 *zit=zap
 *pony=my horsie''s name is {0}
 *iHaveSomeOranges=I have {0,choice,0#are no oranges|1# one orange|1&lt;are {0,number,integer} oranges}.
 *iHaveAFewArguments=o={0} z={1} b={2} c={3} s={4} i={5} l={6} f={7} d={8}
 * }</pre>
 *
 * When the class is loaded (without a properties specified in the load() method)  it will look for a properties
 * file in the same package as the class, with the same name as the class, but with the classname all lower-case, and
 * the language code appended to the end.
 *
 * In the above example, the Foo bundle will look for the English properties file at
 * {@code /com/example/foo/foo_en.properties }
 * the French will be:
 * {@code /com/example/foo/foo_fr.properties }
 *
 * Usage of the bundle is intended to be as simple as possible.
 *{@code
 *public class App {
 *
 *  public static void main(String[] args) {
 *    BundleCache.setThreadLocale(Locale.ENGLISH);
 *    System.out.println("I know a bar called " + Foo.get().bar());
 *    System.out.println(Foo.get().pony("Sparky"));
 *    System.out.println(Foo.get().iHaveSomeOranges(5));
 *    System.out.println(Foo.get().iHaveAFewArguments("obj", true, (byte)4, 'q', (short)6, 1, 9999, 9.5f, 4.4d));
 *  }
 *}
 * }
 *
 * This will produce the output:
 * {@code
 *I know a bar called <NAME>
 *my horsie's name is Sparky
 *I have one orange.
 *o=obj z=true b=4 c=q s=6 i=1 l=9,999 f=9.5 d=4.4
 * }
 *
 *
 * @see java.text.MessageFormat
 * @author <NAME>
 */
public class Bundle {
	public enum LoadIgnoreMissing { YES, NO };
	public enum LoadIgnoreExtra { YES, NO };
	public enum LoadIgnoreParameterMisMatch { YES, NO };

	/**
	 * The locale for this bundle. Required for formatting numbers in the subclasses.
	 */
	private final Locale locale;
	/**
	 *
	 * default value for new creations if the options are not specified
	 */
	public static LoadIgnoreMissing LOAD_IGNORE_MISSING = LoadIgnoreMissing.YES;
	public static LoadIgnoreExtra LOAD_IGNORE_EXTRA = LoadIgnoreExtra.YES;
	public static LoadIgnoreParameterMisMatch LOAD_IGNORE_PARAM_MISMATCH = LoadIgnoreParameterMisMatch.YES;

	public Locale getLocale() {
		return locale;
	}

	public Bundle(Locale locale) {
		if (locale == null) {
			throw new NullPointerException("The locale cannot be null");
		}
		this.locale = locale;
	}

	/**
	 * Constructs a bundle implementation for the class and locale.
	 * @throws MissingResourceException if the resource cannot be found.
	 * @throws IOException if there is an error loading the properties
	 * @see #load(java.lang.Class, java.util.Locale, java.util.Properties, boolean, boolean, boolean)
	 */
	static <T extends Bundle> T load(Class<T> cls, Locale locale)
			throws IllegalAccessException, InstantiationException
			, NoSuchMethodException, IOException
			, IllegalArgumentException, InvocationTargetException
			{
		return load(cls, locale, LOAD_IGNORE_MISSING, LOAD_IGNORE_EXTRA, LOAD_IGNORE_PARAM_MISMATCH);
	}
	static <T extends Bundle> T load(Class<T> cls, Locale locale, BundleConfiguration configuration)
			throws IllegalAccessException, InstantiationException
			, NoSuchMethodException, IOException
			, IllegalArgumentException, InvocationTargetException
			{
		final Properties translations = new Properties();
		final String resourcePath =
				cls.getPackage().getName().replace(".", "/")
				+ "/"
				+ cls.getSimpleName()
				+ "_"
				+ locale.getLanguage()
				+ ".properties";
{'fraction_non_alphanumeric': 0.11592049043284414, 'fraction_numerical': 0.007059260635333457, 'mean_word_length': 4.275355218030377, 'pattern_counts': {'":': 0, '<': 53, '<?xml version=': 0, '>': 53, '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': '4258687', 'n_tokens_mistral': 3504, 'n_tokens_neox': 3285, 'n_words': 1053}