Last active
June 21, 2020 11:01
-
-
Save saurabharora90/2795b0ff9000e333f1db7fdcd165a12b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private val initializedModules = HashSet<Class<out ModuleInitializer>>() | |
fun getInitializerCompletable(): Completable { | |
val completableList = mutableListOf<Completable>() | |
map.forEach { (clazz, moduleInitializer) -> | |
completableList.addAll(getCompletableForModule(clazz, moduleInitializer)) | |
} | |
return Completable.concat(completableList) | |
} | |
private fun getCompletableForModule( | |
clazz: Class<out ModuleInitializer>, | |
moduleToInitialize: ModuleInitializer | |
): List<Completable> { | |
if (moduleToInitialize.dependencies().isEmpty() && initializedModules.contains(clazz)) { | |
return emptyList() | |
} else { | |
val completableList = mutableListOf<Completable>() | |
moduleToInitialize.dependencies().forEach { | |
completableList.addAll(getCompletableForModule(it, map.getValue(it))) | |
} | |
if (!initializedModules.contains(clazz)) { | |
initializedModules.add(clazz) | |
completableList.add(moduleToInitialize.initialize(context)) | |
} | |
return completableList | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
map[it]!!
could be replaced withmap.getValue(it)
if you want to avoid using!!
. :) Also, you get a more detailed exception instead of an NPE this way.