<commit_before>package net.twasi.core.api.ws;

import com.google.gson.JsonElement;
import net.twasi.core.api.ws.models.TwasiWebsocketClient;

import java.util.ArrayList;
import java.util.List;

public abstract class TwasiWebsocketListenerEndpoint extends TwasiWebsocketEndpoint {

    protected final List<TwasiWebsocketClient> listeners = new ArrayList<>();

    final void addListener(TwasiWebsocketClient client) {
        listeners.add(client);
    }

    final void removeListener(TwasiWebsocketClient client) {
        listeners.remove(client);
    }

    protected final void publish(JsonElement ob) {
        publish(ob.toString());
    }

    protected final void publish(String s) {
        listeners.forEach(l -> l.getConnection().send(s));
    }

    public boolean allowAnonymousListening() {
        return false;
    }

}<commit_msg>+ Way more flexible publish methods for TwasiWebsocketListenerEndpoint<commit_after>package net.twasi.core.api.ws;

import com.google.gson.JsonElement;
import net.twasi.core.api.ws.models.TwasiWebsocketClient;

import java.util.ArrayList;
import java.util.List;
import java.util.function.Predicate;
import java.util.stream.Stream;

public abstract class TwasiWebsocketListenerEndpoint extends TwasiWebsocketEndpoint {

    protected final List<TwasiWebsocketClient> listeners = new ArrayList<>();

    final void addListener(TwasiWebsocketClient client) {
        listeners.add(client);
    }

    final void removeListener(TwasiWebsocketClient client) {
        listeners.remove(client);
    }

    protected final void publish(JsonElement ob) {
        publish(ob.toString());
    }

    protected final void publish(String s) {
        listeners.forEach(l -> l.getConnection().send(s));
    }

    protected final void publish(Stream<TwasiWebsocketClient> stream, JsonElement ob) {
        publish(stream, ob.toString());
    }

    protected final void publish(Stream<TwasiWebsocketClient> stream, String s) {
        stream.forEach(l -> l.getConnection().send(s));
    }

    protected final void publish(Predicate<TwasiWebsocketClient> filter, JsonElement ob) {
        publish(filter, ob.toString());
    }

    protected final void publish(Predicate<TwasiWebsocketClient> filter, String s) {
        publish(listeners.stream().filter(filter), s);
    }

    public boolean allowAnonymousListening() {
        return false;
    }

}
{'fraction_non_alphanumeric': 0.09928780896522832, 'fraction_numerical': 0.0, 'mean_word_length': 3.7664670658682633, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 14, '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': '2562902', 'n_tokens_mistral': 670, 'n_tokens_neox': 694, 'n_words': 147}