/** * Partition a list of resources based on their ResourceKey matching * a given rule. * * The rules will be traversed in descending priority, and the first rule * which matches the key of the resource will be associated with that * resource (and all other resources who match). */ public synchronized TraceTagRulePartitions partition(Collection<Resource> resources) { Set<Resource> leftToPartition = new HashSet<Resource>(resources); TraceTagRulePartitions res = new TraceTagRulePartitions(); for (TraceTagRule rule : getRules()) { if (rule instanceof EndPointAwareTraceTagRule) { ResourceKeyMatcher matcher = ((EndPointAwareTraceTagRule)rule).getRequiredEndPoint(); res.createPartition(rule); for (Iterator<Resource> i=leftToPartition.iterator(); i.hasNext(); ) { Resource resource = i.next(); if (matcher.matches(resource.getKey())) { res.addResource(rule, resource); i.remove(); } } } } res.addUnmatchedResources(leftToPartition); return res; }