public void testIsNotNullPredicate() { assertNotNull(PredicateUtils.notNullPredicate()); assertSame(PredicateUtils.notNullPredicate(), PredicateUtils.notNullPredicate()); assertEquals(false, PredicateUtils.notNullPredicate().evaluate(null)); assertEquals(true, PredicateUtils.notNullPredicate().evaluate(cObject)); assertEquals(true, PredicateUtils.notNullPredicate().evaluate(cString)); assertEquals(true, PredicateUtils.notNullPredicate().evaluate(cInteger)); }
@SuppressWarnings("unchecked") private Iterator<Resource> getResourceInheritanceChainInternal(final Collection<String> bucketNames, final String configName, final Iterator<String> paths, final ResourceResolver resourceResolver) { // find all matching items among all configured paths Iterator<Resource> matchingResources = IteratorUtils.transformedIterator(paths, new Transformer() { @Override public Object transform(Object input) { String path = (String)input; for (String bucketName : bucketNames) { final String name = bucketName + "/" + configName; final String configPath = buildResourcePath(path, name); Resource resource = resourceResolver.getResource(configPath); if (resource != null) { log.trace("+ Found matching config resource for inheritance chain: {}", configPath); return resource; } else { log.trace("- No matching config resource for inheritance chain: {}", configPath); } } return null; } }); Iterator<Resource> result = IteratorUtils.filteredIterator(matchingResources, PredicateUtils.notNullPredicate()); if (result.hasNext()) { return result; } return null; }
/** * Searches the resource hierarchy upwards for all config references and returns them. */ @SuppressWarnings("unchecked") private Iterator<String> findConfigRefs(@NotNull final Resource startResource, @NotNull final Collection<String> bucketNames) { // collect all context path resources (but filter out those without config reference) final Iterator<ContextResource> contextResources = new FilterIterator(contextPathStrategy.findContextResources(startResource), new Predicate() { @Override public boolean evaluate(Object object) { ContextResource contextResource = (ContextResource)object; return StringUtils.isNotBlank(contextResource.getConfigRef()); } }); // get config resource path for each context resource, filter out items where not reference could be resolved final Iterator<String> configPaths = new TransformIterator(contextResources, new Transformer() { @Override public Object transform(Object input) { final ContextResource contextResource = (ContextResource)input; String val = checkPath(contextResource, contextResource.getConfigRef(), bucketNames); if (val != null) { log.trace("+ Found reference for context path {}: {}", contextResource.getResource().getPath(), val); } return val; } }); return new FilterIterator(configPaths, PredicateUtils.notNullPredicate()); }