apply method
Applies this ordering rule to the provided list of `PropertySource`s.
Implementations must treat sources as immutable input and return a
new list representing the reordered sequence. The returned list may:
- preserve the original order,
- apply custom sorting algorithms,
- enforce precedence or override relationships,
- remove or merge duplicates,
- or otherwise reorganize the collection.
Parameters
- sources – The list of property sources to be ordered.
Returns
A newly constructed list representing the result of applying this rule.
Important
This method must never modify the original sources list.
Implementation
@override
List<PropertySource> apply(List<PropertySource> sources) {
final list = List<PropertySource>.of(sources);
final aIndex = list.indexWhere((s) => s.getName() == before);
final bIndex = list.indexWhere((s) => s.getName() == after);
if (aIndex == -1 || bIndex == -1) return list;
// If already correct, keep it
if (aIndex < bIndex) return list;
// Move "before" to the correct position
final a = list.removeAt(aIndex);
list.insert(bIndex, a);
return list;
}