<commit_before>package com.jamerlan.commands.impl.in;

import com.jamerlan.ServerState;
import com.jamerlan.commands.Command;
import com.jamerlan.model.Battle;
import com.jamerlan.model.User;
import com.jamerlan.utils.CommandParser;
import com.jamerlan.utils.SearchBattle;
import com.jamerlan.utils.SearchUser;

import java.io.IOException;
import java.io.PrintWriter;

/**
 JOINEDBATTLE battleID userName [scriptPassword]
 */
public class JoinedBattle implements Command{
    private String line;
    private ServerState serverState;

    public JoinedBattle(String line, ServerState serverState) {
        this.line = line;
        this.serverState = serverState;
    }

    @Override
    public void execute(PrintWriter writer) throws IOException {
        CommandParser parser = new CommandParser(line);
        String commandName = parser.getString(" ");

        int battleId = parser.getInt(" ");
        String userName = parser.getString();

        SearchBattle searchBattle = new SearchBattle();
        Battle battle = searchBattle.byBattleId(serverState, battleId);
        SearchUser searchUser = new SearchUser();
        User user = searchUser.byUserName(serverState, userName);
        battle.getUsers().add(user);
    }
}<commit_msg>in/JoinedBattle refactored<commit_after>package com.jamerlan.commands.impl.in;

import com.jamerlan.ServerState;
import com.jamerlan.commands.Command;
import com.jamerlan.model.Battle;
import com.jamerlan.model.User;
import com.jamerlan.utils.CommandParser;
import com.jamerlan.utils.SearchBattle;
import com.jamerlan.utils.SearchUser;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.Optional;

/**
 JOINEDBATTLE battleID userName [scriptPassword]
 */
public class JoinedBattle implements Command{
    private String line;
    private ServerState serverState;

    public JoinedBattle(String line, ServerState serverState) {
        this.line = line;
        this.serverState = serverState;
    }

    @Override
    public void execute(PrintWriter writer) throws IOException {
        CommandParser parser = new CommandParser(line);
        String commandName = parser.getString(" ");

        int battleId = parser.getInt(" ");
        String userName = parser.getString();

        Optional<User> user = serverState.getUsersOnline().stream().filter(user1 -> user1.getUserName().equals(userName)).findAny();
        serverState.getBattles().stream().filter(battle -> battle.getBattleId()==battleId).findAny().ifPresent(battle -> user.ifPresent(user1 -> battle.getUsers().add(user1)));
    }
}
{'fraction_non_alphanumeric': 0.10626702997275204, 'fraction_numerical': 0.001557026080186843, 'mean_word_length': 3.9806201550387597, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 8, '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': '530836', 'n_tokens_mistral': 730, 'n_tokens_neox': 736, 'n_words': 156}