<commit_before>package com.github.dreamhead.moco.parser.model.websocket;

import com.fasterxml.jackson.annotation.JsonAutoDetect;
import com.github.dreamhead.moco.Moco;
import com.github.dreamhead.moco.MocoWebSockets;
import com.github.dreamhead.moco.ResponseHandler;
import com.github.dreamhead.moco.parser.model.FileContainer;
import com.github.dreamhead.moco.parser.model.TextContainer;

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

import static com.github.dreamhead.moco.Moco.with;
import static com.github.dreamhead.moco.parser.model.DynamicResponseHandlerFactory.asFileResource;
import static com.github.dreamhead.moco.util.Iterables.head;
import static com.github.dreamhead.moco.util.Iterables.tail;

@JsonAutoDetect(fieldVisibility = JsonAutoDetect.Visibility.ANY)
public class WebsocketResponseSetting {
    private TextContainer text;
    private FileContainer file;
    private TextContainer broadcast;

    public ResponseHandler asResponseHandler() {
        List<ResponseHandler> handlers = new ArrayList<>();
        if (text != null) {
            handlers.add(with(this.text.asResource()));
        }

        if (file != null) {
            handlers.add(with(asFileResource("file", this.file)));
        }

        if (broadcast != null) {
            handlers.add(MocoWebSockets.broadcast(broadcast.asResource()));
        }

        final ResponseHandler[] responseHandlers = handlers.toArray(new ResponseHandler[0]);

        return Moco.and(head(responseHandlers), tail(responseHandlers));<commit_msg>replaced and implementation in websocket response setting<commit_after>package com.github.dreamhead.moco.parser.model.websocket;

import com.fasterxml.jackson.annotation.JsonAutoDetect;
import com.github.dreamhead.moco.Moco;
import com.github.dreamhead.moco.MocoWebSockets;
import com.github.dreamhead.moco.ResponseHandler;
import com.github.dreamhead.moco.handler.AndResponseHandler;
import com.github.dreamhead.moco.parser.model.FileContainer;
import com.github.dreamhead.moco.parser.model.TextContainer;

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

import static com.github.dreamhead.moco.Moco.with;
import static com.github.dreamhead.moco.parser.model.DynamicResponseHandlerFactory.asFileResource;
import static com.github.dreamhead.moco.util.Iterables.head;
import static com.github.dreamhead.moco.util.Iterables.tail;

@JsonAutoDetect(fieldVisibility = JsonAutoDetect.Visibility.ANY)
public class WebsocketResponseSetting {
    private TextContainer text;
    private FileContainer file;
    private TextContainer broadcast;

    public ResponseHandler asResponseHandler() {
        List<ResponseHandler> handlers = new ArrayList<>();
        if (text != null) {
            handlers.add(with(this.text.asResource()));
        }

        if (file != null) {
            handlers.add(with(asFileResource("file", this.file)));
        }

        if (broadcast != null) {
            handlers.add(MocoWebSockets.broadcast(broadcast.asResource()));
        }

        return AndResponseHandler.and(handlers);
{'fraction_non_alphanumeric': 0.10692030173827484, 'fraction_numerical': 0.00032797638570022957, 'mean_word_length': 4.249569707401033, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, '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': '3146703', 'n_tokens_mistral': 914, 'n_tokens_neox': 865, 'n_words': 145}