<commit_before>package com.beolnix.marvin.im;

import com.beolnix.marvin.im.api.IMSession;
import com.beolnix.marvin.im.api.IMSessionManager;
import com.beolnix.marvin.im.api.IMSessionState;
import org.apache.log4j.Logger;

import java.util.Map;

/**
 * Created by beolnix on 04/11/15.
 */
public class IMSessionsWatchDog {

    // dependencies
    private final IMSessionManager sessionManager;

    // constants
    private static final Logger logger = Logger.getLogger(IMSessionManagerImpl.class);

    public IMSessionsWatchDog(IMSessionManager sessionManager) {
        this.sessionManager = sessionManager;
    }

    public void checkSessions() {
        Map<String, IMSession> sessionMap = sessionManager.getIMSessions();
        for (IMSession imSession : sessionMap.values()) {
            if (isStateBad(imSession.getState())) {
                logger.warn("The state of bot '" + imSession.getBotName()
                        + "' is: " + imSession.getState() + ". Try to connect it once again.");
                imSession.connect();
            }
        }
    }

    private boolean isStateBad(IMSessionState state) {
        if (state == null) {
            return true;
        }

        return state != IMSessionState.CONNECTED &&
                state != IMSessionState.CONNECTING;
    }
}<commit_msg>refactoring: checkSessions method of IMSessionsWatchDog<commit_after>package com.beolnix.marvin.im;

import com.beolnix.marvin.im.api.IMSession;
import com.beolnix.marvin.im.api.IMSessionManager;
import com.beolnix.marvin.im.api.IMSessionState;
import org.apache.log4j.Logger;

import java.util.Map;

/**
 * Created by beolnix on 04/11/15.
 */
public class IMSessionsWatchDog {

    // dependencies
    private final IMSessionManager sessionManager;

    // constants
    private static final Logger logger = Logger.getLogger(IMSessionManagerImpl.class);

    public IMSessionsWatchDog(IMSessionManager sessionManager) {
        this.sessionManager = sessionManager;
    }

    public void checkSessions() {
        sessionManager.getIMSessions().values().stream()
                .filter(this::isStateGood)
                .forEach( imSession -> {
                    logger.warn("The  bot '" + imSession.getBotName()
                            + "' is in '" + imSession.getState() + "' state. Try to connect it once again.");
                    imSession.connect();
                });
    }

    private boolean isStateGood(IMSession imSession) {
        IMSessionState state = imSession.getState();
        if (state == null) {
            return false;
        }

        return state == IMSessionState.CONNECTED ||
                state == IMSessionState.CONNECTING;
    }
}
{'fraction_non_alphanumeric': 0.10432852386237514, 'fraction_numerical': 0.005179430262671106, 'mean_word_length': 2.4711168164313224, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 5, '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': '4823241', 'n_tokens_mistral': 814, 'n_tokens_neox': 757, 'n_words': 157}