<commit_before>package com.valkryst.VRadio;

import java.util.Collections;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;

public class Radio <D> {
    /** A HashMap of events mapped to listening receivers. */
    private final ConcurrentMap<String, Set<Receiver<D>>> receivers = new ConcurrentHashMap<>();

    /**
     * Transmits an event without data.
     *
     * @param event
     *         The event to transmit.
     */
    public final void transmit(final String event) {
        transmit(event, null);
    }

    /**
     * Transmits an event with data.
     *
     * Does nothing if the event is null or empty.
     *
     * @param event
     *         The event whose receivers are to be transmitted to.
     *
     * @param data
     *         The data to transmit to the receivers.
     */
    public final void transmit(final String event, final D data) {
        if (! isStringNullOrEmpty(event)) {
            this.receivers.getOrDefault(event, Collections.emptySet())
                          .forEach(receiver -> receiver.receive(event, data));
        }
    }

    /**
     * Adds a receiver to an event.
     *
     * Does nothing if the event is null or empty.
     * Does nothing if the receiver is null.
     *
     * @param event
     *         The event to add a receiver to.
     *
     * @param receiver
     *         The receiver to add.
     */
    public final void addReceiver(final String event, final Receiver<D> receiver) {
        if (areArgumentsInValidState(event, receiver)) {
            receivers.putIfAbsent(event, ConcurrentHashMap.newKeySet());
            receivers.get(event).add(receiver);
        }
    }

    /**
     * Removes a receiver from an event.
     *
     * Does nothing if the event is null or empty.
     * Does nothing if the receiver is null.
     *
     * @param event
     *         The event to remove a receiver from.
     *
     * @param receiver
     *         The receiver to remove.
     */
    public final void removeReceiver(final String event, final Receiver<D> receiver) {
        if (areArgumentsInValidState(event, receiver)) {
            this.receivers.getOrDefault(event, Collections.emptySet())
                          .remove(receiver);
        }
    }

    /**
     * Removes all receivers from an event.
     *
     * Does nothing if the event is null or empty.
     *
     * @param event
     *         The event to remove receivers from.
     */
    public final void removeReceivers(final String event) {
        if (! isStringNullOrEmpty(event)) {
            this.receivers.getOrDefault(event, Collections.emptySet())
                          .clear();
        }
    }

    /**
     * Determines if the string is non-null and non-empty and if the object is non-null.
     *
     * @param string
     *         The string to check.
     *
     * @param object
     *         The object to check.
     *
     * @return
     *         Whether or not the string is non-null and non-empty and if the object is non-null.
     */
    private boolean areArgumentsInValidState(final String string, final Object object) {
        boolean canProceed = isStringNullOrEmpty(string) == false;
        canProceed &= object != null;

        return canProceed;
    }

    /**
     * Determines whether or not a string is null or empty.
     *
     * @param string
     *         The string to check.
     *
     * @return
     *         Whether or not the string is null or empty.
     */
    private boolean isStringNullOrEmpty(final String string) {
        return string == null || string.isEmpty();
    }
}<commit_msg>Rewrites null/empty checks. Adds NPE/IllegalArg exception to transmit.<commit_after>package com.valkryst.VRadio;

import java.util.Collections;
import java.util.Objects;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;

public class Radio <D> {
    /** A HashMap of events mapped to listening receivers. */
    private final ConcurrentMap<String, Set<Receiver<D>>> receivers = new ConcurrentHashMap<>();

    /**
     * Transmits an event without data.
     *
     * @param event
     *        The event to transmit.
     */
    public final void transmit(final String event) {
        transmit(event, null);
    }

    /**
     * Transmits an event with data.
     *
     * Does nothing if the event is null or empty.
     *
     * @param event
     *         The event whose receivers are to be transmitted to.
     *
     * @param data
     *         The data to transmit to the receivers.
     *
     * @throws NullPointerException
     *        If the event is null.
     *
     * @throws IllegalArgumentException
     *        If the event is empty.
     */
    public final void transmit(final String event, final D data) {
        Objects.requireNonNull(event);

        if (event.isEmpty()) {
            throw new IllegalArgumentException("The event cannot be empty.");
        }

        this.receivers.getOrDefault(event, Collections.emptySet())
                      .forEach(receiver -> receiver.receive(event, data));
    }

    /**
     * Adds a receiver to an event.
     *
     * Does nothing if the event is null or empty.
     * Does nothing if the receiver is null.
     *
     * @param event
     *         The event to add a receiver to.
     *
     * @param receiver
     *         The receiver to add.
     */
    public final void addReceiver(final String event, final Receiver<D> receiver) {
        if (event != null && event.isEmpty()) {
            if (receiver != null) {
                receivers.putIfAbsent(event, ConcurrentHashMap.newKeySet());
                receivers.get(event).add(receiver);
            }
        }
    }

    /**
     * Removes a receiver from an event.
     *
     * Does nothing if the event is null or empty.
     * Does nothing if the receiver is null.
     *
     * @param event
     *         The event to remove a receiver from.
     *
     * @param receiver
     *         The receiver to remove.
     */
    public final void removeReceiver(final String event, final Receiver<D> receiver) {
        if (event != null && event.isEmpty()) {
            if (receiver != null) {
                this.receivers.getOrDefault(event, Collections.emptySet())
                              .remove(receiver);
            }
        }
    }

    /**
     * Removes all receivers from an event.
     *
     * Does nothing if the event is null or empty.
     *
     * @param event
     *         The event to remove receivers from.
     */
    public final void removeReceivers(final String event) {
        if (event != null && event.isEmpty() == false) {
            this.receivers.getOrDefault(event, Collections.emptySet())
                    .clear();
        }
    }
}
{'fraction_non_alphanumeric': 0.09142607174103237, 'fraction_numerical': 0.0, 'mean_word_length': 1.848421926910299, 'pattern_counts': {'":': 0, '<': 17, '<?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': '4804487', 'n_tokens_mistral': 1871, 'n_tokens_neox': 1835, 'n_words': 609}