<commit_before>package pirateboat.info

import lombok.extern.slf4j.Slf4j
import org.springframework.stereotype.Service
import pirateboat.multifileHoster.MultifileHosterService
import pirateboat.torrent.Torrent
import pirateboat.utilities.LoggerDelegate
import java.util.function.Consumer

@Service
class TorrentMetaService(private val multifileHosterService: MultifileHosterService) {
    companion object {
        private val logger by LoggerDelegate()
    }

    val localStatusStorage = HashMap<String, String>()

    var activeTorrents: MutableList<Torrent> = ArrayList()

    fun refreshTorrents() {
        val remoteTorrents = multifileHosterService.remoteTorrents
        remoteTorrents.forEach(Consumer { torrent: Torrent ->
            if (isReadyForDownloadStatus(torrent.status)) {
                val localStatus = localStatusStorage[torrent.torrentId]
                logger.info("previous: ${torrent.status} after ${localStatus ?: torrent.status}")
                torrent.status = localStatus ?: torrent.status
            } else {
                localStatusStorage.remove(torrent.torrentId)
            }
        })
        activeTorrents = ArrayList()
        activeTorrents.addAll(remoteTorrents)
    }

    private fun isReadyForDownloadStatus(status: String?): Boolean {
        return status != null && status.toLowerCase().matches(Regex("finished|seeding|ready"))
    }

    fun updateTorrent(torrentUpdate: Torrent) {
        localStatusStorage[torrentUpdate.torrentId] = torrentUpdate.status
        localStatusStorage[torrentUpdate.remoteId] = torrentUpdate.status
    }
}<commit_msg>fix NPE<commit_after>package pirateboat.info

import lombok.extern.slf4j.Slf4j
import org.springframework.stereotype.Service
import pirateboat.multifileHoster.MultifileHosterService
import pirateboat.torrent.Torrent
import pirateboat.utilities.LoggerDelegate
import java.util.function.Consumer

@Service
class TorrentMetaService(private val multifileHosterService: MultifileHosterService) {
    companion object {
        private val logger by LoggerDelegate()
    }

    val localStatusStorage = HashMap<String, String>()

    var activeTorrents: MutableList<Torrent> = ArrayList()

    fun refreshTorrents() {
        val remoteTorrents = multifileHosterService.remoteTorrents
        remoteTorrents.forEach(Consumer { torrent: Torrent ->
            if (isReadyForDownloadStatus(torrent.status)) {
                val localStatus = localStatusStorage[torrent.torrentId]
                logger.info("previous: ${torrent.status} after ${localStatus ?: torrent.status}")
                torrent.status = localStatus ?: torrent.status
            } else {
                localStatusStorage.remove(torrent.torrentId)
            }
        })
        activeTorrents = ArrayList()
        activeTorrents.addAll(remoteTorrents)
    }

    private fun isReadyForDownloadStatus(status: String?): Boolean {
        return status != null && status.toLowerCase().matches(Regex("finished|seeding|ready"))
    }

    fun updateTorrent(torrentUpdate: Torrent) {
        localStatusStorage[torrentUpdate.torrentId] = torrentUpdate.status
        torrentUpdate.remoteId?.let {
            localStatusStorage[torrentUpdate.remoteId] = torrentUpdate.status
        }
    }
}
{'fraction_non_alphanumeric': 0.0853211009174312, 'fraction_numerical': 0.0012232415902140672, 'mean_word_length': 3.3906040268456374, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5623250', 'n_tokens_mistral': 917, 'n_tokens_neox': 881, 'n_words': 156}