use of org.apache.felix.utils.resource.CapabilitySet in project karaf by apache.
the class RequirementSort method sort.
/**
* Sort {@link Resource} based on their {@link Requirement}s and {@link Capability}s.
*
* @param resources the resource to sort.
* @param <T> the resources type.
* @return sorted collection of resources.
*/
public static <T extends Resource> Collection<T> sort(Collection<T> resources) {
Set<String> namespaces = new HashSet<>();
for (Resource r : resources) {
for (Capability cap : r.getCapabilities(null)) {
namespaces.add(cap.getNamespace());
}
}
CapabilitySet capSet = new CapabilitySet(new ArrayList<>(namespaces));
for (Resource r : resources) {
for (Capability cap : r.getCapabilities(null)) {
capSet.addCapability(cap);
}
}
Set<T> sorted = new LinkedHashSet<>();
Set<T> visited = new LinkedHashSet<>();
for (T r : resources) {
visit(r, visited, sorted, capSet);
}
return sorted;
}
Aggregations