<commit_before>package com.jenjinstudios.core.io;

import com.jenjinstudios.core.xml.ArgumentType;
import com.jenjinstudios.core.xml.DisabledMessageType;
import com.jenjinstudios.core.xml.MessageType;
import com.jenjinstudios.core.xml.Messages;

import javax.xml.bind.JAXBContext;
import javax.xml.bind.Unmarshaller;
import java.io.InputStream;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.stream.Stream;

/**
 * The {@code MessageRegistry} class is central to the Jenjin's dynamic messaging system.  An instance of the registry
 * by calling {@code getInstance}; this method returns the same immutable instance each time it is called.  This
 * instance can be used to retrieve "empty" {@code Message} objects, which are prepared to accept arguments and be
 * written to a {@code MessageOutputStream}.
 * <p>
 * The first time the {@code getInstance} method is called, this class recursively searches for existing Messages.xml
 * files in the working directory and the classpath, registering any files found.
 * <p>
 * The addition of a duplicate file is non-deterministic; the behavior is undefined if two message types with the same
 * id are added to the registry.
 *
 * @author <NAME>
 */
public class MessageRegistry
{
	private static final Logger LOGGER = Logger.getLogger(MessageRegistry.class.getName());
	private static MessageRegistry messageRegistry;
	private final Map<Short, MessageType> messageTypesByID = new TreeMap<>();
	private final Map<String, MessageType> messageTypesByName = new TreeMap<>();

	private MessageRegistry() {
		registerXmlMessages();
	}

	/**
	 * Get an immutable instance of this class.  This method only creates a new instance once; each time it is called
	 * thereafter returns the same instance that has already been created.
	 *
	 * @return An immutable, static {@code MessageRegistry}.
	 */
	public static MessageRegistry getInstance() {
		if (messageRegistry == null)
		{
			messageRegistry = new MessageRegistry();
		}
		return messageRegistry;
	}

	/**
	 * Get the {@code MessageType} with the given unique name.
	 *
	 * @param name The name of the {@code MessageType}.
	 *
	 * @return The {@code MessageType} with the given unique name.
	 */
	public MessageType getMessageType(String name) {
		synchronized (messageTypesByName)
		{
			return messageTypesByName.get(name);
		}
	}

	/**
	 * Get the {@code MessageType} with the given unique id.
	 *
	 * @param id The id of the {@code MessageType}.
	 *
	 * @return The {@code MessageType} with the given unique id.
	 */
	public MessageType getMessageType(short id) {
		synchronized (messageTypesByID)
		{
			return messageTypesByID.get(id);
		}
	}

	public Message createMessage(String name) {
		Message message = null;
		MessageType messageType = getMessageType(name);
		if (messageType == null)
		{
			LOGGER.log(Level.INFO, "Requested non-existant message {0}, refreshing XML registry", name);
			// Try again after re-registering XML files
			registerXmlMessages();
			messageType = getMessageType(name);
		}
		if (messageType != null)
		{
			message = new Message(messageType);
		} else
		{
			LOGGER.log(Level.WARNING, "Couldn't find {0} even after refreshing XML registry.", name);
		}
		return message;
	}<commit_msg>Added createMessage JavaDoc<commit_after>package com.jenjinstudios.core.io;

import com.jenjinstudios.core.xml.ArgumentType;
import com.jenjinstudios.core.xml.DisabledMessageType;
import com.jenjinstudios.core.xml.MessageType;
import com.jenjinstudios.core.xml.Messages;

import javax.xml.bind.JAXBContext;
import javax.xml.bind.Unmarshaller;
import java.io.InputStream;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.stream.Stream;

/**
 * The {@code MessageRegistry} class is central to the Jenjin's dynamic messaging system.  An instance of the registry
 * by calling {@code getInstance}; this method returns the same immutable instance each time it is called.  This
 * instance can be used to retrieve "empty" {@code Message} objects, which are prepared to accept arguments and be
 * written to a {@code MessageOutputStream}.
 * <p>
 * The first time the {@code getInstance} method is called, this class recursively searches for existing Messages.xml
 * files in the working directory and the classpath, registering any files found.
 * <p>
 * The addition of a duplicate file is non-deterministic; the behavior is undefined if two message types with the same
 * id are added to the registry.
 *
 * @author <NAME>
 */
public class MessageRegistry
{
	private static final Logger LOGGER = Logger.getLogger(MessageRegistry.class.getName());
	private static MessageRegistry messageRegistry;
	private final Map<Short, MessageType> messageTypesByID = new TreeMap<>();
	private final Map<String, MessageType> messageTypesByName = new TreeMap<>();

	private MessageRegistry() {
		registerXmlMessages();
	}

	/**
	 * Get an immutable instance of this class.  This method only creates a new instance once; each time it is called
	 * thereafter returns the same instance that has already been created.
	 *
	 * @return An immutable, static {@code MessageRegistry}.
	 */
	public static MessageRegistry getInstance() {
		if (messageRegistry == null)
		{
			messageRegistry = new MessageRegistry();
		}
		return messageRegistry;
	}

	/**
	 * Get the {@code MessageType} with the given unique name.
	 *
	 * @param name The name of the {@code MessageType}.
	 *
	 * @return The {@code MessageType} with the given unique name.
	 */
	public MessageType getMessageType(String name) {
		synchronized (messageTypesByName)
		{
			return messageTypesByName.get(name);
		}
	}

	/**
	 * Get the {@code MessageType} with the given unique id.
	 *
	 * @param id The id of the {@code MessageType}.
	 *
	 * @return The {@code MessageType} with the given unique id.
	 */
	public MessageType getMessageType(short id) {
		synchronized (messageTypesByID)
		{
			return messageTypesByID.get(id);
		}
	}

	/**
	 * Create a new "empty" {@code Message} that corresponds to the MessageType with the given name.
	 *
	 * @param name The name of the {@code MessageType} of which the return {@code Message} will be.
	 *
	 * @return A new "empty" {@code Message} of the type specified by {@code name}.
	 */
	public Message createMessage(String name) {
		Message message = null;
		MessageType messageType = getMessageType(name);
		if (messageType == null)
		{
			LOGGER.log(Level.INFO, "Requested non-existant message {0}, refreshing XML registry", name);
			// Try again after re-registering XML files
			registerXmlMessages();
			messageType = getMessageType(name);
		}
		if (messageType != null)
		{
			message = new Message(messageType);
		} else
		{
			LOGGER.log(Level.WARNING, "Couldn't find {0} even after refreshing XML registry.", name);
		}
		return message;
	}
{'fraction_non_alphanumeric': 0.09660872043317184, 'fraction_numerical': 0.0005699629524080935, 'mean_word_length': 4.222470238095238, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 14}, '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': '1892222', 'n_tokens_mistral': 2106, 'n_tokens_neox': 1970, 'n_words': 726}