sortedByOrder
Sorts an iterable collection based on Order annotations and dependencies.
This extension function sorts the collection by considering both the numeric order value and the before/after dependencies specified in @Order annotations. Items are first sorted by their order value, then repositioned according to their before/after relationships.
Example usage:
@Order(1)
class FirstProcessor
@Order(2, before = [ThirdProcessor::class])
class SecondProcessor
@Order(3)
class ThirdProcessor
val processors = listOf(ThirdProcessor(), FirstProcessor(), SecondProcessor())
val sorted = processors.sortedByOrder()
// Result: [FirstProcessor, SecondProcessor, ThirdProcessor]Content copied to clipboard
Return
a new list sorted by order with dependencies resolved
Parameters
T
the type of elements in the collection