sortedByOrder
Sorts the elements by their Order: a topological sort of the before/after constraints, breaking ties by Order.value and then by input order.
before = [X::class]places the element before every element whose class isX;after = [X::class]after every such element. A constraint naming a class that is not in the collection is ignored.Among the elements whose constraints are satisfied, the one with the lowest value comes first; equal values keep their input order. Without constraints this is a stable sort by value.
Constraints that form a cycle fail fast with an IllegalStateException that names the cycle.
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]Return
a new list sorted by order with dependencies resolved
Type Parameters
the type of elements in the collection
See also
Throws
when the before/after constraints form a cycle