com.ybo.trackingplugin.tasks.utils.TextExtractor.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of traceplugin Show documentation
Show all versions of traceplugin Show documentation
gradle plugin allowing to add automatic logs (or other process) at the start of each traced method
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
}
}
}