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

com.likethesalad.tools.resource.collector.ResourceCollector.kt Maven / Gradle / Ivy

There is a newer version: 2.4.0
Show newest version
package com.likethesalad.tools.resource.collector

import com.likethesalad.tools.resource.api.collection.ResourceCollection
import com.likethesalad.tools.resource.collector.extractor.ResourceExtractor
import com.likethesalad.tools.resource.collector.extractor.ResourceExtractorProvider
import com.likethesalad.tools.resource.collector.merger.ResourceMerger
import com.likethesalad.tools.resource.collector.source.ResourceSource
import com.likethesalad.tools.resource.collector.source.ResourceSourceProvider

abstract class ResourceCollector {

    fun collect(): ResourceCollection {
        val collections = mutableListOf()

        val sources = getSourceProvider().getSources()
        val extractors = getExtractorProvider().getExtractors()
        for (source in sources) {
            collections.addAll(getCollectionsFromSource(extractors, source))
        }

        return getMerger().merge(collections)
    }

    private fun getCollectionsFromSource(
        extractors: List>,
        source: ResourceSource,
    ): List {
        val collections = mutableListOf()

        for (extractor in extractors) {
            extractor.extract(source)?.let { collection ->
                if (!collection.isEmpty()) {
                    collections.add(collection)
                }
            }
        }

        return collections
    }

    abstract fun getSourceProvider(): ResourceSourceProvider

    abstract fun getExtractorProvider(): ResourceExtractorProvider

    abstract fun getMerger(): ResourceMerger
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy