All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.ybo.trackingplugin.tasks.utils.TextExtractor.kt Maven / Gradle / Ivy

Go to download

gradle plugin allowing to add automatic logs (or other process) at the start of each traced method

There is a newer version: 0.6.2
Show newest version
package com.ybo.trackingplugin.tasks.utils

import com.ybo.trackingplugin.tasks.data.TraceAnnotationMark
import com.ybo.trackingplugin.tasks.utils.impl.patterns.PatternName

/**
 * object than has some patterns to search in text, and extract their manifestation in the text
 * as objects.
 *It delivers them as a sorted list.
 */
class TextExtractor(
    private val patternProducer: PatternProducer,
    private val patternSearcher: PatternSearcher,
    private val resultSorter: ResultSorter = NoSortSorter(),
) {

    fun extract(
        text: String,
        mark: TraceAnnotationMark? = null,
    ): List {
        return patternProducer
            .produce()
            .let { producedPatterns ->
                patternSearcher.search(text, producedPatterns, mark)
            }.flatMap { group ->
                group.results
            }.let {
                resultSorter.sort(it)
            }
    }

    private class NoSortSorter : ResultSorter {
        override fun sort(list: List): List {
            return list
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy