<commit_before>package io.luna.net.msg;

import static com.google.common.base.Preconditions.checkState;

/**
 * A repository that contains data related to incoming {@link GameMessage}s.
 *
 * @author lare96 <http://github.org/lare96>
 */
public final class MessageRepository {

    /**
     * An array of integers that contain the incoming message sizes.
     */
    private final int[] sizes = new int[257];

    /**
     * An array of {@link InboundGameMessage}s that act as listeners for incoming messages.
     */
    private final InboundGameMessage[] inboundHandlers = new InboundGameMessage[257];

    /**
     * Creates a new {@link MessageRepository}.
     */
    public MessageRepository() {
        String threadName = Thread.currentThread().getName();
        checkState(threadName.equals("LunaMainThread"), "can only be done during initialization");
    }

    /**
     * Adds a new {@link InboundGameMessage} handler along with its size.
     *
     * @param opcode The opcode of the message handler.
     * @param size The size of the message.
     * @param inboundMessageName The class name of the {@link InboundGameMessage}, implicitly prefixed with the {@code
     * io.luna.net.msg.in} package.
     * @throws ReflectiveOperationException If any errors occur while instantiating the {@link InboundGameMessage}.
     */
    public void addHandler(int opcode, int size, String inboundMessageName) throws ReflectiveOperationException {
        String threadName = Thread.currentThread().getName();
        checkState(threadName.equals("LunaInitializationThread"), "can only be done during initialization");

        Class<?> inboundMessageClass = Class.forName("io.luna.net.msg.in." + inboundMessageName);

        sizes[opcode] = size;
        inboundHandlers[opcode] = (InboundGameMessage) inboundMessageClass.newInstance();
    }<commit_msg>ThreadUtils method instead of repetitive code.<commit_after>package io.luna.net.msg;

import io.luna.util.ThreadUtils;

/**
 * A repository that contains data related to incoming {@link GameMessage}s.
 *
 * @author lare96 <http://github.org/lare96>
 */
public final class MessageRepository {

    /**
     * An array of integers that contain the incoming message sizes.
     */
    private final int[] sizes = new int[257];

    /**
     * An array of {@link InboundGameMessage}s that act as listeners for incoming messages.
     */
    private final InboundGameMessage[] inboundHandlers = new InboundGameMessage[257];

    /**
     * Creates a new {@link MessageRepository}.
     */
    public MessageRepository() {
        ThreadUtils.ensureInitThread();
    }

    /**
     * Adds a new {@link InboundGameMessage} handler along with its size.
     *
     * @param opcode The opcode of the message handler.
     * @param size The size of the message.
     * @param inboundMessageName The class name of the {@link InboundGameMessage}, implicitly prefixed with the {@code
     * io.luna.net.msg.in} package.
     * @throws ReflectiveOperationException If any errors occur while instantiating the {@link InboundGameMessage}.
     */
    public void addHandler(int opcode, int size, String inboundMessageName) throws ReflectiveOperationException {
        ThreadUtils.ensureInitThread();

        Class<?> inboundMessageClass = Class.forName("io.luna.net.msg.in." + inboundMessageName);
        sizes[opcode] = size;
        inboundHandlers[opcode] = (InboundGameMessage) inboundMessageClass.newInstance();
    }
{'fraction_non_alphanumeric': 0.0994236311239193, 'fraction_numerical': 0.005763688760806916, 'mean_word_length': 3.377049180327869, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, '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': '4148606', 'n_tokens_mistral': 951, 'n_tokens_neox': 927, 'n_words': 294}