List of usage examples for com.google.common.collect Iterators filter
@SuppressWarnings("unchecked") @GwtIncompatible("Class.isInstance") @CheckReturnValue public static <T> UnmodifiableIterator<T> filter(Iterator<?> unfiltered, Class<T> desiredType)
From source file:org.fcrepo.kernel.api.utils.iterators.RdfStream.java
/** * Filter the RDF triples while maintaining context. * * @param predicate the predicate/* w ww .j ava 2 s.co m*/ * @return RdfStream */ public RdfStream filter(final Predicate<? super Triple> predicate) { return withThisContext(Iterators.filter(this, predicate::test)); }
From source file:org.openengsb.core.common.internal.VirtualConnectorManager.java
private Iterator<Registration> getFactoriesForDomainProviderForRemoval(final DomainProvider provider) { Iterator<Registration> consumingIterator = Iterators.consumingIterator(registeredFactories.iterator()); return Iterators.filter(consumingIterator, new Predicate<Registration>() { @Override// w w w . j a va 2 s. co m public boolean apply(Registration input) { return ObjectUtils.equals(input.domainProvider, provider); } }); }
From source file:org.apache.jackrabbit.oak.security.user.UserPrincipalProvider.java
@Nonnull @Override//from w w w. j a v a 2 s . c o m public Iterator<? extends Principal> findPrincipals(final String nameHint, final int searchType) { try { AuthorizableType type = AuthorizableType.getType(searchType); StringBuilder statement = new StringBuilder() .append(QueryUtil.getSearchRoot(type, config.getParameters())).append("//element(*,") .append(QueryUtil.getNodeTypeName(type)).append(')').append("[jcr:like(@rep:principalName,'") .append(buildSearchPattern(nameHint)).append("')]"); Result result = root.getQueryEngine().executeQuery(statement.toString(), javax.jcr.query.Query.XPATH, NO_BINDINGS, namePathMapper.getSessionLocalMappings()); Iterator<Principal> principals = Iterators.filter( Iterators.transform(result.getRows().iterator(), new ResultRowToPrincipal()), Predicates.notNull()); if (matchesEveryone(nameHint, searchType)) { principals = Iterators.concat(principals, Iterators.singletonIterator(EveryonePrincipal.getInstance())); return Iterators.filter(principals, new EveryonePredicate()); } else { return principals; } } catch (ParseException e) { log.debug(e.getMessage()); return Iterators.emptyIterator(); } }
From source file:jflowmap.ColorSchemes.java
public final static List<ColorSchemes> ofType(final Type type) { return ImmutableList.copyOf(Iterators.filter(Iterators.forArray(values()), new Predicate<ColorSchemes>() { public boolean apply(ColorSchemes cs) { return cs.type == type; }// w w w . ja va 2 s . c o m })); }
From source file:org.eclipse.sirius.business.api.control.SiriusUncontrolCommand.java
private boolean airdResourceHasNoRepresentations(final Resource childAirdResource) { return Iterators.size(Iterators.filter(EcoreUtil.getAllProperContents(childAirdResource, true), DRepresentation.class)) == 0; }
From source file:org.obeonetwork.dsl.uml2.design.api.services.CompositeStructureDiagramServices.java
/** * Get provided interfaces.// w w w .j av a 2s . c o m * * @param diagram * Diagram * @return The interfaces realized by ports visible on the diagram */ public Collection<EObject> getPortInterfaceRealization(DDiagram diagram) { final Set<EObject> result = Sets.newLinkedHashSet(); if (diagram instanceof DSemanticDecorator) { final Session sess = SessionManager.INSTANCE.getSession(((DSemanticDecorator) diagram).getTarget()); final Iterator<EObject> it = Iterators.transform( Iterators.filter(diagram.eAllContents(), AbstractDNode.class), new Function<AbstractDNode, EObject>() { public EObject apply(AbstractDNode input) { return input.getTarget(); } }); while (it.hasNext()) { final EObject displayedAsANode = it.next(); if (displayedAsANode != null) { for (final Setting xRef : sess.getSemanticCrossReferencer() .getInverseReferences(displayedAsANode)) { EObject eObject = xRef.getEObject(); if (eObject instanceof DNode) { eObject = ((DNode) eObject).getTarget(); } if (sess.getModelAccessor().eInstanceOf(eObject, "Port")) { //$NON-NLS-1$ final Port port = (Port) eObject; result.addAll(port.getProvideds()); } } } } } return result; }
From source file:org.apache.jackrabbit.oak.spi.security.authentication.external.impl.principal.ExternalGroupPrincipalProvider.java
@Nonnull @Override//from ww w .j ava2s. c om public Iterator<? extends Principal> findPrincipals(@Nullable String nameHint, int searchType) { if (PrincipalManager.SEARCH_TYPE_NOT_GROUP != searchType) { Result result = findPrincipals(Strings.nullToEmpty(nameHint), false); if (result != null) { return Iterators.filter(new GroupPrincipalIterator(nameHint, result), Predicates.notNull()); } } return Iterators.emptyIterator(); }
From source file:com.google.devtools.kythe.platform.indexpack.Archive.java
/** Returns an {@link Iterator} of the units stored in the archive with a given format key. */ public <T> Iterator<T> readUnits(final String formatKey, final Class<T> cls) throws IOException { Preconditions.checkNotNull(formatKey); return Iterators.filter(Iterators.transform(Files.newDirectoryStream(unitDir, "*" + UNIT_SUFFIX).iterator(), new Function<Path, T>() { @Override/*w w w .ja v a 2s . c o m*/ public T apply(Path path) { try { String name = path.getFileName().toString(); if (!name.endsWith(UNIT_SUFFIX)) { throw new IllegalStateException("Received path without unit suffix: " + path); } String key = name.substring(0, name.length() - UNIT_SUFFIX.length()); return readUnit(key, formatKey, cls); } catch (IOException ioe) { throw Throwables.propagate(ioe); } } }), new Predicate<T>() { @Override public boolean apply(T unit) { return unit != null; } }); }
From source file:com.google.devtools.build.lib.profiler.statistics.PhaseStatistics.java
/** * Iterator over all {@link ProfilerTask}s that were executed at least once and have a total * duration greater than 0.//from w w w .j a v a2 s .c o m */ @Override public Iterator<ProfilerTask> iterator() { return Iterators.filter(taskCounts.keySet().iterator(), new Predicate<ProfilerTask>() { @Override public boolean apply(ProfilerTask taskType) { return getTotalDurationNanos(taskType) > 0 && wasExecuted(taskType); } }); }
From source file:com.google.javascript.jscomp.TypedScope.java
public Iterator<TypedVar> getDeclarativelyUnboundVarsWithoutTypes() { return Iterators.filter(getVars(), DECLARATIVELY_UNBOUND_VARS_WITHOUT_TYPES); }