List of usage examples for java.util List retainAll
boolean retainAll(Collection<?> c);
From source file:edu.uci.ics.hyracks.algebricks.rewriter.rules.IntroduceProjectsRule.java
protected boolean introduceProjects(AbstractLogicalOperator parentOp, int parentInputIndex, Mutable<ILogicalOperator> opRef, Set<LogicalVariable> parentUsedVars, IOptimizationContext context) throws AlgebricksException { AbstractLogicalOperator op = (AbstractLogicalOperator) opRef.getValue(); boolean modified = false; usedVars.clear();// w w w .j ava2s.com VariableUtilities.getUsedVariables(op, usedVars); // In the top-down pass, maintain a set of variables that are used in op and all its parents. HashSet<LogicalVariable> parentsUsedVars = new HashSet<LogicalVariable>(); parentsUsedVars.addAll(parentUsedVars); parentsUsedVars.addAll(usedVars); // Descend into children. for (int i = 0; i < op.getInputs().size(); i++) { Mutable<ILogicalOperator> inputOpRef = op.getInputs().get(i); if (introduceProjects(op, i, inputOpRef, parentsUsedVars, context)) { modified = true; } } if (modified) { context.computeAndSetTypeEnvironmentForOperator(op); } // In the bottom-up pass, determine which live variables are not used by op's parents. // Such variables are be projected away. liveVars.clear(); VariableUtilities.getLiveVariables(op, liveVars); producedVars.clear(); VariableUtilities.getProducedVariables(op, producedVars); liveVars.removeAll(producedVars); projectVars.clear(); for (LogicalVariable liveVar : liveVars) { if (parentsUsedVars.contains(liveVar)) { projectVars.add(liveVar); } } // Some of the variables that are live at this op are not used above. if (projectVars.size() != liveVars.size()) { // Add a project operator under each of op's qualifying input branches. for (int i = 0; i < op.getInputs().size(); i++) { ILogicalOperator childOp = op.getInputs().get(i).getValue(); liveVars.clear(); VariableUtilities.getLiveVariables(childOp, liveVars); List<LogicalVariable> vars = new ArrayList<LogicalVariable>(); vars.addAll(projectVars); // Only retain those variables that are live in the i-th input branch. vars.retainAll(liveVars); if (vars.size() != liveVars.size()) { ProjectOperator projectOp = new ProjectOperator(vars); projectOp.getInputs().add(new MutableObject<ILogicalOperator>(childOp)); op.getInputs().get(i).setValue(projectOp); context.computeAndSetTypeEnvironmentForOperator(projectOp); modified = true; } } } else if (op.getOperatorTag() == LogicalOperatorTag.PROJECT) { // Check if the existing project has become useless. liveVars.clear(); VariableUtilities.getLiveVariables(op.getInputs().get(0).getValue(), liveVars); ProjectOperator projectOp = (ProjectOperator) op; List<LogicalVariable> projectVars = projectOp.getVariables(); if (liveVars.size() == projectVars.size() && liveVars.containsAll(projectVars)) { boolean eliminateProject = true; // For UnionAll the variables must also be in exactly the correct order. if (parentOp.getOperatorTag() == LogicalOperatorTag.UNIONALL) { eliminateProject = canEliminateProjectBelowUnion((UnionAllOperator) parentOp, projectOp, parentInputIndex); } if (eliminateProject) { // The existing project has become useless. Remove it. parentOp.getInputs().get(parentInputIndex).setValue(op.getInputs().get(0).getValue()); } } } if (modified) { context.computeAndSetTypeEnvironmentForOperator(op); } return modified; }
From source file:org.apache.solr.cloud.OverseerCollectionMessageHandler.java
static List<String> getLiveOrLiveAndCreateNodeSetList(final Set<String> liveNodes, final ZkNodeProps message, final Random random) { // TODO: add smarter options that look at the current number of cores per // node?/*w w w .j a v a2s.c o m*/ // for now we just go random (except when createNodeSet and createNodeSet.shuffle=false are passed in) List<String> nodeList; final String createNodeSetStr = message.getStr(CREATE_NODE_SET); final List<String> createNodeList = (createNodeSetStr == null) ? null : StrUtils.splitSmart((CREATE_NODE_SET_EMPTY.equals(createNodeSetStr) ? "" : createNodeSetStr), ",", true); if (createNodeList != null) { nodeList = new ArrayList<>(createNodeList); nodeList.retainAll(liveNodes); if (message.getBool(CREATE_NODE_SET_SHUFFLE, CREATE_NODE_SET_SHUFFLE_DEFAULT)) { Collections.shuffle(nodeList, random); } } else { nodeList = new ArrayList<>(liveNodes); Collections.shuffle(nodeList, random); } return nodeList; }
From source file:com.actian.services.knime.core.operators.DeriveGroupNodeDialogPane.java
@Override public void refresh(PortMetadata[] specs) { this.inType = ((RecordMetadata) specs[0]).getType(); List<String> inputFields = Arrays.asList(this.inType.getNames()); List<String> currentKeyFields = new ArrayList<>(); currentKeyFields.addAll(Arrays.asList(this.settings.keys.getStringArrayValue())); List<String> nonKeyFields = new ArrayList<>(); nonKeyFields.addAll(inputFields);/*from w w w . j a v a 2 s . c o m*/ nonKeyFields.removeAll(currentKeyFields); currentKeyFields.retainAll(inputFields); this.columnSelect.setExcludeList(nonKeyFields); this.columnSelect.setIncludeList(currentKeyFields); this.expression.setText(this.settings.expression.getStringValue()); }
From source file:com.googlecode.msidor.springframework.integration.files.CompositeCascadeFileListFilter.java
/** * Contrary to the original implementation, this method matches files against filters based on results of previous match. * @see #fileFilters/*from w w w. j a v a 2 s. com*/ */ @Override public List<F> filterFiles(F[] files) { Assert.notNull(files, "'files' should not be null"); List<F> results = new ArrayList<F>(Arrays.asList(files)); for (FileListFilter<F> fileFilter : this.fileFilters) { if (results.size() > 0) { F[] filesToFilter = toArray(results); List<F> currentResults = fileFilter.filterFiles(filesToFilter); results.retainAll(currentResults); } } return results; }
From source file:org.thingsboard.server.dao.timeseries.BaseTimeseriesService.java
@Override public ListenableFuture<List<TsKvEntry>> findLatest(TenantId tenantId, EntityId entityId, Collection<String> keys) { validate(entityId);/*from www. j a v a 2s .co m*/ List<ListenableFuture<TsKvEntry>> futures = Lists.newArrayListWithExpectedSize(keys.size()); keys.forEach(key -> Validator.validateString(key, "Incorrect key " + key)); if (entityId.getEntityType().equals(EntityType.ENTITY_VIEW)) { EntityView entityView = entityViewService.findEntityViewById(tenantId, (EntityViewId) entityId); List<String> filteredKeys = new ArrayList<>(keys); if (entityView.getKeys() != null && entityView.getKeys().getTimeseries() != null && !entityView.getKeys().getTimeseries().isEmpty()) { filteredKeys.retainAll(entityView.getKeys().getTimeseries()); } List<ReadTsKvQuery> queries = filteredKeys.stream().map(key -> { long endTs = entityView.getEndTimeMs() != 0 ? entityView.getEndTimeMs() : Long.MAX_VALUE; return new BaseReadTsKvQuery(key, entityView.getStartTimeMs(), endTs, 1, "DESC"); }).collect(Collectors.toList()); if (queries.size() > 0) { return timeseriesDao.findAllAsync(tenantId, entityView.getEntityId(), queries); } else { return Futures.immediateFuture(new ArrayList<>()); } } keys.forEach(key -> futures.add(timeseriesDao.findLatest(tenantId, entityId, key))); return Futures.allAsList(futures); }
From source file:ru.savvy.jpafilterbuilder.FieldFilterHelper.java
public Accessor getAccessor(final String fieldName, final String fieldType) { initIfEmpty(fieldName);/*w w w .ja v a 2 s . com*/ return new Accessor() { @Override public String getSwitchOptions() { List<Option> currentSwitch = new ArrayList<>(getAllSwitches(fieldType).values()); currentSwitch.retainAll(fields.get(fieldName).getOptions()); if (!currentSwitch.isEmpty()) { return currentSwitch.get(0).name(); } else { return null; } } @Override public void setSwitchOptions(String option) { if (option != null && option.length() > 0) { fields.get(fieldName).getOptions().removeAll(getAllSwitches(fieldType).values()); fields.get(fieldName).getOptions().add(Option.valueOf(option)); } } @Override public List<String> getOptions() { List<Option> currentOptions = new ArrayList<>(getAllOptions(fieldType).values()); currentOptions.retainAll(fields.get(fieldName).getOptions()); List<String> result = new ArrayList<>(); for (Option o : currentOptions) { result.add(o.name()); } return result; } @Override public void setOptions(List<String> options) { if (options != null) { fields.get(fieldName).getOptions().removeAll(getAllOptions(fieldType).values()); for (String o : options) { fields.get(fieldName).getOptions().add(Option.valueOf(o)); } } } @Override public String getFieldName() { return fieldName; } @Override public Object getValue() { return fields.get(fieldName).getValue(); } /** * does not accept empty or blank strings * * @param value */ @Override public void setValue(Object value) { if (value != null && (value instanceof String) && ((String) value).trim().isEmpty()) { value = null; } fields.get(fieldName).setValue(value); } }; }
From source file:com.atolcd.alfresco.web.scripts.shareStats.SelectUsersGet.java
@SuppressWarnings("unchecked") public List<String> selectConnectedUsers(AuditQueryParameters params, AtolAuthorityParameters atolAuthorityParameters) { List<String> users = new ArrayList<String>(); users = (List<String>) this.sqlSessionTemplate.selectList(SELECT_CONNECTED_USERS, params); Set<String> usersSet = this.selectSiteMembers(atolAuthorityParameters); users.retainAll(usersSet); return users; }
From source file:org.alfresco.repo.content.transform.ContentTransformerHelper.java
/** * Returns a comma separated String of mimetype file extensions. *///from ww w .ja v a2s .c o m private String getExtensions(List<String> origMimetypes) { // Only use the mimetypes we have registered List<String> mimetypes = new ArrayList<String>(origMimetypes); mimetypes.retainAll(getMimetypeService().getMimetypes()); StringBuilder sb = new StringBuilder(); int j = mimetypes.size(); int i = 1; for (String mimetype : mimetypes) { sb.append(getMimetypeService().getExtension(mimetype)); if (i < j) { sb.append(++i < j ? ", " : " or "); } } return sb.toString(); }
From source file:org.extremecomponents.tree.ProcessTreeRowsCallback.java
public Collection sortRows(TableModel model, Collection rows) throws Exception { boolean sorted = model.getLimit().isSorted(); if (!sorted) { return rows; }// w w w . j ava2s. c o m List parents = new ArrayList(); for (Iterator iter = rows.iterator(); iter.hasNext();) { TreeNode node = (TreeNode) iter.next(); if (node.getParent() == null) parents.add(node); } List output = new ArrayList(); Sort sort = model.getLimit().getSort(); String property = sort.getProperty(); String sortOrder = sort.getSortOrder(); subSort(parents, property, sortOrder); // First sort the parents recursiveSort(output, parents, property, sortOrder); output.retainAll(rows); // Only keep the original nodes rows.clear(); rows.addAll(output); return rows; }
From source file:org.apache.hyracks.algebricks.rewriter.rules.IntroduceProjectsRule.java
protected boolean introduceProjects(AbstractLogicalOperator parentOp, int parentInputIndex, Mutable<ILogicalOperator> opRef, Set<LogicalVariable> parentUsedVars, IOptimizationContext context) throws AlgebricksException { AbstractLogicalOperator op = (AbstractLogicalOperator) opRef.getValue(); boolean modified = false; usedVars.clear();//from ww w .j a v a 2 s. c om VariableUtilities.getUsedVariables(op, usedVars); // In the top-down pass, maintain a set of variables that are used in op and all its parents. // This is a necessary step for the newly created project operator during this optimization, // since we already have all information from collectUsedVars() method for the other operators. HashSet<LogicalVariable> parentsUsedVars = new HashSet<>(); parentsUsedVars.addAll(parentUsedVars); parentsUsedVars.addAll(usedVars); if (allUsedVarsAfterOpMap.get(op) != null) { parentsUsedVars.addAll(allUsedVarsAfterOpMap.get(op)); } // Descend into children. for (int i = 0; i < op.getInputs().size(); i++) { Mutable<ILogicalOperator> inputOpRef = op.getInputs().get(i); if (introduceProjects(op, i, inputOpRef, parentsUsedVars, context)) { modified = true; } } if (modified) { context.computeAndSetTypeEnvironmentForOperator(op); } // In the bottom-up pass, determine which live variables are not used by op's parents. // Such variables are be projected away. liveVars.clear(); VariableUtilities.getLiveVariables(op, liveVars); producedVars.clear(); VariableUtilities.getProducedVariables(op, producedVars); liveVars.removeAll(producedVars); projectVars.clear(); for (LogicalVariable liveVar : liveVars) { if (parentsUsedVars.contains(liveVar)) { projectVars.add(liveVar); } } // Some of the variables that are live at this op are not used above. if (projectVars.size() != liveVars.size()) { // Add a project operator under each of op's qualifying input branches. for (int i = 0; i < op.getInputs().size(); i++) { ILogicalOperator childOp = op.getInputs().get(i).getValue(); liveVars.clear(); VariableUtilities.getLiveVariables(childOp, liveVars); List<LogicalVariable> vars = new ArrayList<>(); vars.addAll(projectVars); // Only retain those variables that are live in the i-th input branch. vars.retainAll(liveVars); if (vars.size() != liveVars.size()) { ProjectOperator projectOp = new ProjectOperator(vars); projectOp.getInputs().add(new MutableObject<ILogicalOperator>(childOp)); op.getInputs().get(i).setValue(projectOp); context.computeAndSetTypeEnvironmentForOperator(projectOp); modified = true; } } } else if (op.getOperatorTag() == LogicalOperatorTag.PROJECT) { // Check if the existing project has become useless. liveVars.clear(); VariableUtilities.getLiveVariables(op.getInputs().get(0).getValue(), liveVars); ProjectOperator projectOp = (ProjectOperator) op; List<LogicalVariable> projectVarsTemp = projectOp.getVariables(); if (liveVars.size() == projectVarsTemp.size() && liveVars.containsAll(projectVarsTemp)) { boolean eliminateProject = true; // For UnionAll the variables must also be in exactly the correct order. if (parentOp.getOperatorTag() == LogicalOperatorTag.UNIONALL) { eliminateProject = canEliminateProjectBelowUnion((UnionAllOperator) parentOp, projectOp, parentInputIndex); } if (eliminateProject) { // The existing project has become useless. Remove it. parentOp.getInputs().get(parentInputIndex).setValue(op.getInputs().get(0).getValue()); } } } if (modified) { context.computeAndSetTypeEnvironmentForOperator(op); } return modified; }