List of usage examples for com.google.common.collect Iterables removeIf
public static <T> boolean removeIf(Iterable<T> removeFrom, Predicate<? super T> predicate)
From source file:cz.cuni.mff.ms.brodecva.botnicek.ide.design.system.model.DefaultSystem.java
private void removeReferences(final Set<? extends RecurentArc> removed) { final Collection<Entry<EnterNode, RecurentArc>> entries = this.references.entries(); Iterables.removeIf(entries, new Predicate<Entry<EnterNode, RecurentArc>>() { @Override/*from w w w . j a va 2 s . c o m*/ public boolean apply(final Entry<EnterNode, RecurentArc> input) { final RecurentArc referring = input.getValue(); return removed.contains(referring); } }); }
From source file:ezbake.groups.service.EzGroupsService.java
/** * Request groups to which an user has data access. Requester must be an EzBake Admin and all groups to which an * user has data access will be returned. * * @param token EzSecurityToken user to determine if requester is authorized to perform this action * @param userGroupsRequest information needed to carry about the request for the users groups * @return a set of UserGroups containing information, including ID and name, of the groups to which an user has * data access/*from w ww .java 2s . c o m*/ * @throws EzSecurityTokenException thrown if EzGroups is unable to validate the token * @throws AuthorizationException thrown if the requester is not an EzBake Admin or authorization is denied * @throws GroupQueryException may be thrown if there is problem executing the query */ @Override public Set<UserGroup> requestUserGroups(EzSecurityToken token, UserGroupsRequest userGroupsRequest) throws EzSecurityTokenException, AuthorizationException, GroupQueryException, TException { try { validateToken(token); if (!EzSecurityTokenUtils.isEzAdmin(token)) { final String errMsg = String.format( "User '%s' not an EzBake Admin. Must be EzBake Admin to request groups for an user!", token.getTokenPrincipal().getPrincipal()); logger.error(errMsg); throw new AuthorizationException(errMsg, AuthorizationError.ACCESS_DENIED); } final String id = userGroupsRequest.getIdentifier(); final Set<Group> groupsUserBelongsTo = getUserGroups(BaseVertex.VertexType.USER, id, true); // root group should not be returned to the user Iterables.removeIf(groupsUserBelongsTo, IS_ROOT_GROUP); final Set<UserGroup> groups = getUserGroupsInfo(id, groupsUserBelongsTo); graph.commitTransaction(); return groups; } catch (TException | RuntimeException e) { graph.commitTransaction(true); throw e; } finally { graph.commitTransaction(); } }
From source file:org.apache.impala.planner.SingleNodePlanner.java
/** * Migrates unassigned conjuncts into an inline view. Conjuncts are not * migrated into the inline view if the view has a LIMIT/OFFSET clause or if the * view's stmt computes analytic functions (see IMPALA-1243/IMPALA-1900). * The reason is that analytic functions compute aggregates over their entire input, * and applying filters from the enclosing scope *before* the aggregate computation * would alter the results. This is unlike regular aggregate computation, which only * makes the *output* of the computation visible to the enclosing scope, so that * filters from the enclosing scope can be safely applied (to the grouping cols, say). *///from w w w. ja va2s .c om public void migrateConjunctsToInlineView(Analyzer analyzer, InlineViewRef inlineViewRef) throws ImpalaException { List<Expr> unassignedConjuncts = analyzer.getUnassignedConjuncts(inlineViewRef.getId().asList(), true); if (!canMigrateConjuncts(inlineViewRef)) { // mark (fully resolve) slots referenced by unassigned conjuncts as // materialized List<Expr> substUnassigned = Expr.substituteList(unassignedConjuncts, inlineViewRef.getBaseTblSmap(), analyzer, false); analyzer.materializeSlots(substUnassigned); return; } List<Expr> preds = Lists.newArrayList(); for (Expr e : unassignedConjuncts) { if (analyzer.canEvalPredicate(inlineViewRef.getId().asList(), e)) { preds.add(e); } } unassignedConjuncts.removeAll(preds); // Generate predicates to enforce equivalences among slots of the inline view // tuple. These predicates are also migrated into the inline view. analyzer.createEquivConjuncts(inlineViewRef.getId(), preds); // create new predicates against the inline view's unresolved result exprs, not // the resolved result exprs, in order to avoid skipping scopes (and ignoring // limit clauses on the way) List<Expr> viewPredicates = Expr.substituteList(preds, inlineViewRef.getSmap(), analyzer, false); // Remove unregistered predicates that reference the same slot on // both sides (e.g. a = a). Such predicates have been generated from slot // equivalences and may incorrectly reject rows with nulls (IMPALA-1412/IMPALA-2643). Predicate<Expr> isIdentityPredicate = new Predicate<Expr>() { @Override public boolean apply(Expr expr) { return org.apache.impala.analysis.Predicate.isEquivalencePredicate(expr) && ((BinaryPredicate) expr).isInferred() && expr.getChild(0).equals(expr.getChild(1)); } }; Iterables.removeIf(viewPredicates, isIdentityPredicate); // Migrate the conjuncts by marking the original ones as assigned, and // re-registering the substituted ones with new ids. analyzer.markConjunctsAssigned(preds); // Unset the On-clause flag of the migrated conjuncts because the migrated conjuncts // apply to the post-join/agg/analytic result of the inline view. for (Expr e : viewPredicates) e.setIsOnClauseConjunct(false); inlineViewRef.getAnalyzer().registerConjuncts(viewPredicates); // mark (fully resolve) slots referenced by remaining unassigned conjuncts as // materialized List<Expr> substUnassigned = Expr.substituteList(unassignedConjuncts, inlineViewRef.getBaseTblSmap(), analyzer, false); analyzer.materializeSlots(substUnassigned); }