<commit_before>package com.apixandru.games.rummikub.client;

import com.apixandru.games.rummikub.api.BoardCallback;
import com.apixandru.games.rummikub.api.GameEventListener;
import com.apixandru.games.rummikub.api.PlayerCallback;
import com.apixandru.games.rummikub.brotocol.Packet;
import com.apixandru.games.rummikub.brotocol.PacketHandler;
import com.apixandru.games.rummikub.brotocol.PacketReader;
import com.apixandru.games.rummikub.brotocol.game.server.PacketCardPlaced;
import com.apixandru.games.rummikub.brotocol.game.server.PacketCardRemoved;
import com.apixandru.games.rummikub.brotocol.game.server.PacketGameOver;
import com.apixandru.games.rummikub.brotocol.game.server.PacketNewTurn;
import com.apixandru.games.rummikub.brotocol.game.server.PacketReceiveCard;
import com.apixandru.games.rummikub.client.game.CardPlacedHandler;
import com.apixandru.games.rummikub.client.game.CardRemovedHandler;
import com.apixandru.games.rummikub.client.game.GameOverHandler;
import com.apixandru.games.rummikub.client.game.NewTurnHandler;
import com.apixandru.games.rummikub.client.game.ReceiveCardHandler;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.Closeable;
import java.io.EOFException;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.atomic.AtomicBoolean;

import static java.util.Collections.singleton;

/**
 * @param <H> hint type
 * @author <NAME>
 * @since January 04, 2016
 */
final class PlayerCallbackAdapter<H> implements Runnable {

    private final Logger log = LoggerFactory.getLogger(PlayerCallbackAdapter.class);

    private final PacketReader reader;

    private final Map<Class, PacketHandler> handlers = new HashMap<>();

    private final PlayerCallback<H> playerCallback;
    private final GameEventListener gameEventListener;

    private final ConnectionListener connectionListener;

    private final AtomicBoolean continueReading = new AtomicBoolean(true);

    PlayerCallbackAdapter(final ConnectorBuilder<H> connector,
                          final PacketReader reader) {
        this.reader = reader;

        this.playerCallback = connector.callback;
        BoardCallback boardCallback = connector.boardCallback;
        this.gameEventListener = connector.gameEventListener;

        this.connectionListener = connector.connectionListener;

        handlers.put(PacketCardPlaced.class, new CardPlacedHandler(boardCallback));
        handlers.put(PacketCardRemoved.class, new CardRemovedHandler(boardCallback));
        handlers.put(PacketNewTurn.class, new NewTurnHandler(singleton(gameEventListener)));
        handlers.put(PacketGameOver.class, new GameOverHandler(gameEventListener, continueReading));
        handlers.put(PacketReceiveCard.class, new ReceiveCardHandler<>(playerCallback, connector.hints));
    }

    @Override
    @SuppressWarnings("unchecked")
    public void run() {
        try (final Closeable closeMe = this.reader) {
            while (continueReading.get()) {
                final Packet input = reader.readPacket();
                final PacketHandler packetHandler = handlers.get(input.getClass());
                packetHandler.handle(input);
            }
        } catch (final EOFException e) {
            log.debug("Server was shutdown?", e);
            this.connectionListener.onConnectionLost();
        } catch (final IOException e) {
            log.error("Unknown exception", e);
            this.connectionListener.onConnectionLost();
        }
    }

}<commit_msg>refactor after moving packets<commit_after>package com.apixandru.games.rummikub.client;

import com.apixandru.games.rummikub.brotocol.Packet;
import com.apixandru.games.rummikub.brotocol.PacketHandler;
import com.apixandru.games.rummikub.brotocol.PacketReader;
import com.apixandru.games.rummikub.brotocol.game.server.PacketCardPlaced;
import com.apixandru.games.rummikub.brotocol.game.server.PacketCardRemoved;
import com.apixandru.games.rummikub.brotocol.game.server.PacketGameOver;
import com.apixandru.games.rummikub.brotocol.game.server.PacketNewTurn;
import com.apixandru.games.rummikub.brotocol.game.server.PacketReceiveCard;
import com.apixandru.games.rummikub.client.game.CardPlacedHandler;
import com.apixandru.games.rummikub.client.game.CardRemovedHandler;
import com.apixandru.games.rummikub.client.game.GameOverHandler;
import com.apixandru.games.rummikub.client.game.NewTurnHandler;
import com.apixandru.games.rummikub.client.game.ReceiveCardHandler;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.Closeable;
import java.io.EOFException;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.atomic.AtomicBoolean;

import static java.util.Collections.singleton;

/**
 * @param <H> hint type
 * @author <NAME>
 * @since January 04, 2016
 */
final class PlayerCallbackAdapter<H> implements Runnable {

    private final Logger log = LoggerFactory.getLogger(PlayerCallbackAdapter.class);

    private final PacketReader reader;

    private final Map<Class, PacketHandler> handlers = new HashMap<>();

    private final ConnectionListener connectionListener;

    private final AtomicBoolean continueReading = new AtomicBoolean(true);

    PlayerCallbackAdapter(final ConnectorBuilder<H> connector,
                          final PacketReader reader) {
        this.reader = reader;

        this.connectionListener = connector.connectionListener;

        handlers.put(PacketCardPlaced.class, new CardPlacedHandler(connector.boardCallback));
        handlers.put(PacketCardRemoved.class, new CardRemovedHandler(connector.boardCallback));
        handlers.put(PacketNewTurn.class, new NewTurnHandler(singleton(connector.gameEventListener)));
        handlers.put(PacketGameOver.class, new GameOverHandler(connector.gameEventListener, continueReading));
        handlers.put(PacketReceiveCard.class, new ReceiveCardHandler<>(connector.callback, connector.hints));
    }

    @Override
    @SuppressWarnings("unchecked")
    public void run() {
        try (final Closeable closeMe = this.reader) {
            while (continueReading.get()) {
                final Packet input = reader.readPacket();
                final PacketHandler packetHandler = handlers.get(input.getClass());
                packetHandler.handle(input);
            }
        } catch (final EOFException e) {
            log.debug("Server was shutdown?", e);
            this.connectionListener.onConnectionLost();
        } catch (final IOException e) {
            log.error("Unknown exception", e);
            this.connectionListener.onConnectionLost();
        }
    }

}
{'fraction_non_alphanumeric': 0.09745127436281859, 'fraction_numerical': 0.0023988005997001498, 'mean_word_length': 4.104055087987758, 'pattern_counts': {'":': 0, '<': 18, '<?xml version=': 0, '>': 18, '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': '6749226', 'n_tokens_mistral': 2011, 'n_tokens_neox': 1917, 'n_words': 330}