List of usage examples for java.util Set removeAll
boolean removeAll(Collection<?> c);
From source file:com.xpn.xwiki.plugin.workspacesmanager.apps.WorkspaceApplicationManager.java
public Set<String> getAvailableApplicationsNames(String spaceName, XWikiContext context) throws WorkspacesManagerException { Set<String> availableApps = getAllWorkspacesApps(context); Set<String> installedApps = getApplicationsForSpace(spaceName, context).keySet(); availableApps.removeAll(installedApps); return availableApps; }
From source file:edu.uci.ics.hyracks.algebricks.core.algebra.util.OperatorPropertiesUtil.java
/** * Adds the free variables of the plan rooted at that operator to the * collection provided./* ww w. jav a 2s.c o m*/ * * @param op * @param vars * - The collection to which the free variables will be added. */ public static void getFreeVariablesInSelfOrDesc(AbstractLogicalOperator op, Set<LogicalVariable> freeVars) throws AlgebricksException { HashSet<LogicalVariable> produced = new HashSet<LogicalVariable>(); VariableUtilities.getProducedVariables(op, produced); for (LogicalVariable v : produced) { freeVars.remove(v); } HashSet<LogicalVariable> used = new HashSet<LogicalVariable>(); VariableUtilities.getUsedVariables(op, used); for (LogicalVariable v : used) { if (!freeVars.contains(v)) { freeVars.add(v); } } if (op.hasNestedPlans()) { AbstractOperatorWithNestedPlans s = (AbstractOperatorWithNestedPlans) op; for (ILogicalPlan p : s.getNestedPlans()) { for (Mutable<ILogicalOperator> r : p.getRoots()) { getFreeVariablesInSelfOrDesc((AbstractLogicalOperator) r.getValue(), freeVars); } } s.getUsedVariablesExceptNestedPlans(freeVars); HashSet<LogicalVariable> produced2 = new HashSet<LogicalVariable>(); s.getProducedVariablesExceptNestedPlans(produced2); freeVars.removeAll(produced); } for (Mutable<ILogicalOperator> i : op.getInputs()) { getFreeVariablesInSelfOrDesc((AbstractLogicalOperator) i.getValue(), freeVars); } }
From source file:HSqlManager.java
public static void commonClusterNewPhages(Connection connection, int bps) throws SQLException, IOException, ClassNotFoundException, IllegalAccessException, InstantiationException { Connection db = connection;//from w ww.j a v a 2 s . c om String base = new File("").getAbsolutePath(); db.setAutoCommit(false); PreparedStatement st = db.prepareStatement("UPDATE Primerdb.Primers SET CommonP = False," + " UniqueP = False" + " WHERE Cluster = ? and " + "Strain = ? and Sequence = ? and Bp =?"); Statement stat = db.createStatement(); if (newPhages != null) { List<String[]> phages = newPhages; phages.forEach(x -> { try { CSV.writeDataCSV(x[0], Fasta.process(x[0], bps), bps); CSV.writeDataCSV(x[0], Fasta.processPrimers(x[0], bps), bps); } catch (IOException e) { e.printStackTrace(); } Set<CharSequence> primers = new HashSet<>(); try { ResultSet rs = stat.executeQuery( "SELECT * FROM Primerdb.Primers WHERE" + " Sequence = '" + x[1] + "' and Clusters = '" + x[2] + "' and CommonP = True" + "and Bp =" + Integer.valueOf(bps)); while (rs.next()) { primers.add((CharSequence) rs.getString("Sequence")); } primers.removeAll(CSV.readCSV(base + "/PhageData/" + Integer.toString(bps) + x[0] + ".csv")); if (primers.size() != 0) { primers.forEach(y -> { try { //finish update st.setString(1, x[1]); st.setString(2, x[2]); st.setString(3, y.toString()); st.setInt(4, bps); st.addBatch(); } catch (SQLException e) { e.printStackTrace(); } }); st.executeBatch(); db.commit(); } } catch (SQLException e) { e.printStackTrace(); } }); } System.out.println("Common Updated"); st.close(); }
From source file:org.codehaus.groovy.grails.plugins.searchable.compass.config.DefaultGrailsDomainClassMappingSearchableCompassConfigurator.java
/** * Configure Compass ready for it to be built * * @param compassConfiguration runtime configuration instance * @param configurationContext a context allowing flexible parameter passing *//* w w w .j a va 2s . c om*/ public void configure(CompassConfiguration compassConfiguration, Map configurationContext) { Assert.notNull(grailsApplication, "grailsApplication cannot be null"); Assert.notNull(classMappingConfigurators, "classMappingConfigurators cannot be null"); // determine which classes are mapped by which strategy Map classesByStrategy = new HashMap(); Collection grailsDomainClasses = SearchableUtils.getGrailsDomainClasses(grailsApplication); Set notMapped = new HashSet(grailsDomainClasses); for (int i = 0; i < classMappingConfigurators.length; i++) { SearchableGrailsDomainClassMappingConfigurator configurator = classMappingConfigurators[i]; Collection classes = configurator.getMappedBy(notMapped); if (classes != null) { notMapped.removeAll(classes); if (LOG.isDebugEnabled()) { for (Iterator iter = classes.iterator(); iter.hasNext();) { GrailsDomainClass grailsDomainClass = (GrailsDomainClass) iter.next(); LOG.debug("Mapping class [" + grailsDomainClass.getClazz().getName() + "] with strategy [" + configurator.getName() + "]"); } } classesByStrategy.put(classMappingConfigurators[i], classes); } } if (LOG.isDebugEnabled() && !notMapped.isEmpty()) { for (Iterator iter = notMapped.iterator(); iter.hasNext();) { GrailsDomainClass grailsDomainClass = (GrailsDomainClass) iter.next(); LOG.debug("No mapping strategy found for class [" + grailsDomainClass.getClazz() + "]: assuming this class is not searchable"); } } // map classes in the order defined by the classMappingConfigurators for (int i = 0; i < classMappingConfigurators.length; i++) { SearchableGrailsDomainClassMappingConfigurator classMappingConfigurator = classMappingConfigurators[i]; Collection classes = (Collection) classesByStrategy.get(classMappingConfigurator); if (classes != null && !classes.isEmpty()) { classMappingConfigurator.configureMappings(compassConfiguration, configurationContext, classes); } } }
From source file:edu.umd.ks.cm.util.spring.CmToSisExportAdvice.java
@Transactional(readOnly = false, noRollbackFor = { DoesNotExistException.class }, rollbackFor = { Throwable.class }) public void updateSisCourseInfoCluSetUpdate(ProceedingJoinPoint pjp, ContextInfo contextInfo) throws Throwable { if (true) {// w w w . j a v a 2s. com return; } // If the enablePushToSis environment variable is false, do not write course to SIS // (allows us to turn off push for public environment) if (!enablePushToSis) { return; } Object[] args = pjp.getArgs(); String newCluSetId = (String) args[0]; // Modified cluSetId CluSetInfo newCluSetInfo = (CluSetInfo) args[1]; // Modified cluSetInfo // Make sure it's a CluSet we care about (Hardcoded) String cluSetName = newCluSetInfo.getName(); // "cluSetName" will now be a long description name (was just the code before) // So, get and check the new map which contains hardcoded set description names. Map<String, String> CoreGenCluSetCodeToDescriptionMap = coreGenedClusetMapper .getCodeToDescriptionMap(contextInfo); Boolean weCare = CoreGenCluSetCodeToDescriptionMap.containsValue(cluSetName); if (weCare) { // Obtain new Ids Set<String> newCluIds = new HashSet<String>(newCluSetInfo.getCluIds()); List<String> listNewCluIds = newCluSetInfo.getCluIds(); // Obtain old ("current") Ids via luService call List<String> listOldCluIds = luService.getAllCluIdsInCluSet(newCluSetId, contextInfo); Set<String> oldCluIds = new HashSet<String>(listOldCluIds); // Removed Courses (old - new) Set<String> removedCluIds = new HashSet<String>(oldCluIds); removedCluIds.removeAll(newCluIds); System.out.println("Removed these clu IDs: " + removedCluIds); for (String cluId : removedCluIds) { // Translate from VerIndId to current Ver Id to get current courseInfo obj VersionDisplayInfo vdi = courseService .getCurrentVersion(CourseServiceConstants.COURSE_NAMESPACE_URI, cluId, contextInfo); CourseInfo courseInfo = courseService.getCourse(vdi.getId(), contextInfo); //sisCmDao.updateSisCourseInfo(courseInfo, "P");//FIXME we should test to see if there is a pushed record before we update vs create } // Added Courses (new - old) Set<String> addedCluIds = new HashSet<String>(newCluIds); addedCluIds.removeAll(oldCluIds); System.out.println("Added these clu IDs: " + addedCluIds); for (String cluId : addedCluIds) { // Translate from VerIndId to current Ver Id to get current courseInfo obj VersionDisplayInfo vdi = courseService .getCurrentVersion(CourseServiceConstants.COURSE_NAMESPACE_URI, cluId, contextInfo); CourseInfo courseInfo = courseService.getCourse(vdi.getId(), contextInfo); //sisCmDao.updateSisCourseInfo(courseInfo, "P");//FIXME we should test to see if there is a pushed record before we update vs create } } // end if weCare }
From source file:edu.uci.ics.hyracks.algebricks.rewriter.rules.EliminateSubplanWithInputCardinalityOneRule.java
@Override public boolean rewritePre(Mutable<ILogicalOperator> opRef, IOptimizationContext context) throws AlgebricksException { if (!invoked) { rootRef = opRef;/*from w ww.j a v a 2s . c o m*/ invoked = true; } AbstractLogicalOperator op = (AbstractLogicalOperator) opRef.getValue(); if (op.getInputs().size() <= 0) { return false; } boolean changed = false; for (Mutable<ILogicalOperator> subplanRef : op.getInputs()) { AbstractLogicalOperator op1 = (AbstractLogicalOperator) subplanRef.getValue(); if (op1.getOperatorTag() != LogicalOperatorTag.SUBPLAN) { continue; } SubplanOperator subplan = (SubplanOperator) op1; Set<LogicalVariable> usedVarsUp = new ListSet<LogicalVariable>(); OperatorPropertiesUtil.getFreeVariablesInPath(rootRef.getValue(), subplan, usedVarsUp); // TODO(buyingyi): figure out the rewriting for subplan operators with multiple subplans. if (subplan.getNestedPlans().size() != 1) { continue; } ILogicalOperator subplanInputOperator = subplan.getInputs().get(0).getValue(); Set<LogicalVariable> subplanInputVars = new ListSet<LogicalVariable>(); VariableUtilities.getLiveVariables(subplanInputOperator, subplanInputVars); int subplanInputVarSize = subplanInputVars.size(); subplanInputVars.removeAll(usedVarsUp); // Makes sure the free variables are only used in the subplan. if (subplanInputVars.size() < subplanInputVarSize) { continue; } Set<LogicalVariable> freeVars = new ListSet<LogicalVariable>(); OperatorPropertiesUtil.getFreeVariablesInSubplans(subplan, freeVars); boolean cardinalityOne = isCardinalityOne(subplan.getInputs().get(0), freeVars); if (cardinalityOne) { /** If the cardinality of freeVars in the subplan is one, the subplan can be removed. */ ILogicalPlan plan = subplan.getNestedPlans().get(0); List<Mutable<ILogicalOperator>> rootRefs = plan.getRoots(); // TODO(buyingyi): investigate the case of multi-root plans. if (rootRefs.size() != 1) { continue; } Set<Mutable<ILogicalOperator>> ntsSet = new ListSet<Mutable<ILogicalOperator>>(); findNts(rootRefs.get(0), ntsSet); /** Replaces nts with the input operator of the subplan. */ for (Mutable<ILogicalOperator> nts : ntsSet) { nts.setValue(subplanInputOperator); } subplanRef.setValue(rootRefs.get(0).getValue()); changed = true; } else { continue; } } return changed; }
From source file:net.morimekta.idltool.cmd.RemoteStatus.java
/** * Show standard status for a remote./*from w w w.j a v a 2s . c om*/ * * @param first If this is the first remote to print diffs. * @param sourceSha1sums The remote file to sha1sum map. * @param targetSha1sums The local file to sha1sum map. * @return If the next remote is the first to print diffs. */ private boolean showStatus(boolean first, @Nonnull String remoteName, @Nonnull File sourceDirectory, @Nonnull Map<String, String> sourceSha1sums, @Nonnull File targetDirectory, @Nonnull Map<String, String> targetSha1sums) throws IOException { Set<String> removedFiles = new TreeSet<>(targetSha1sums.keySet()); removedFiles.removeAll(sourceSha1sums.keySet()); Set<String> addedFiles = new TreeSet<>(sourceSha1sums.keySet()); addedFiles.removeAll(targetSha1sums.keySet()); Set<String> updatedFiles = new TreeSet<>(sourceSha1sums.keySet()); updatedFiles.removeAll(addedFiles); updatedFiles = updatedFiles.stream().filter(f -> !targetSha1sums.get(f).equals(sourceSha1sums.get(f))) .collect(Collectors.toSet()); Set<String> allFiles = new TreeSet<>(); allFiles.addAll(removedFiles); allFiles.addAll(addedFiles); allFiles.addAll(updatedFiles); if (allFiles.size() == 0) { return first; } int longestName = allFiles.stream().mapToInt(String::length).max().orElse(0); int diffSeparatorLength = Math.max(72, longestName + 6 + remoteName.length()); if (!first) { System.out.println(); } System.out.println(String.format("%sUpdates on %s%s", Color.BOLD, remoteName, Color.CLEAR)); for (String file : allFiles) { String paddedFile = StringUtils.rightPad(file, longestName); File sourceFile = new File(sourceDirectory, file); File targetFile = new File(targetDirectory, file); if (diff) { System.out.println(); System.out.println(Color.DIM + Strings.times("#", diffSeparatorLength) + Color.CLEAR); paddedFile = remoteName + "/" + paddedFile; } if (removedFiles.contains(file)) { System.out.println(String.format(" %s%s%s (%sD%s)%s", Color.YELLOW, paddedFile, Color.CLEAR, Color.RED, Color.CLEAR, getDiffStats(sourceFile, targetFile))); } else if (addedFiles.contains(file)) { System.out.println(String.format(" %s%s%s (%sA%s)%s", Color.YELLOW, paddedFile, Color.CLEAR, Color.GREEN, Color.CLEAR, getDiffStats(sourceFile, targetFile))); } else { System.out.println(String.format(" %s%s%s %s", Color.YELLOW, paddedFile, Color.CLEAR, getDiffStats(sourceFile, targetFile))); } if (diff) { System.out.println(Color.DIM + Strings.times("-", diffSeparatorLength) + Color.CLEAR); printDiffLines(sourceFile, targetFile); System.out.println(Color.DIM + Strings.times("#", diffSeparatorLength) + Color.CLEAR); } } return false; }
From source file:eu.openanalytics.rsb.component.JobProcessor.java
public void process(final MultiFilesJob job) throws Exception { process(job, new JobRunner() { @Override/*ww w. j a v a 2 s. com*/ public AbstractResult<File[]> runOn(final RServi rServi) throws Exception { final Set<String> filesUploadedToR = new HashSet<String>(); // locate and upload the R script final File rScriptFile = getRScriptFile(job); uploadFileToR(rServi, rScriptFile, filesUploadedToR); // optionally uploads a Sweave file final String sweaveFileFromCatalog = (String) getUploadableJobMeta(job) .get(Constants.SWEAVE_FILE_CONFIGURATION_KEY); if (sweaveFileFromCatalog != null) { final File sweaveFile = getCatalogManager().internalGetCatalogFile(CatalogSection.SWEAVE_FILES, job.getApplicationName(), sweaveFileFromCatalog); if (!sweaveFile.isFile()) { throw new IllegalArgumentException("Invalid catalog Sweave file reference in job: " + job); } uploadFileToR(rServi, sweaveFile, filesUploadedToR); } // upload the job files (except the R Script which has already been // taken care of) for (final File jobFile : job.getFiles()) { if (!jobFile.equals(rScriptFile)) { uploadFileToR(rServi, jobFile, filesUploadedToR); } } // upload the configuration file to R uploadPropertiesToR(rServi, getUploadableJobMeta(job), filesUploadedToR); // hit R executeScriptOnR(rServi, rScriptFile.getName()); final MultiFilesResult result = job.buildSuccessResult(); // download the result files but not the uploaded ones nor the log // file final Set<String> filesToDownload = getFilesInRWorkspace(rServi); filesToDownload.removeAll(filesUploadedToR); filesToDownload.remove(Constants.DEFAULT_R_LOG_FILE); for (final String fileToDownload : filesToDownload) { final File resultFile = result.createNewResultFile(fileToDownload); final FileOutputStream fos = new FileOutputStream(resultFile); rServi.downloadFile(fos, fileToDownload, 0, null); IOUtils.closeQuietly(fos); } return result; } private Map<String, Serializable> getUploadableJobMeta(final Job job) { final Map<String, Serializable> meta = new HashMap<String, Serializable>(job.getMeta()); if ((JobProcessor.this.getConfiguration().isPropagateSecurityContext()) && (StringUtils.isNotBlank(job.getUserName()))) { meta.put("rsbSecure", true); meta.put("rsbUserPrincipal", job.getUserName()); } return meta; } private File getRScriptFile(final MultiFilesJob job) { final String rScriptFromCatalog = (String) getUploadableJobMeta(job) .get(Constants.R_SCRIPT_CONFIGURATION_KEY); return rScriptFromCatalog != null ? getRScriptFileFromCatalog(rScriptFromCatalog, job) : getRScriptFileFromJob(job); } private File getRScriptFileFromCatalog(final String rScriptFromCatalog, final MultiFilesJob job) { final File rScriptFile = getCatalogManager().internalGetCatalogFile(CatalogSection.R_SCRIPTS, job.getApplicationName(), rScriptFromCatalog); if ((rScriptFile == null) || (!rScriptFile.isFile())) { throw new IllegalArgumentException("No R script has been found for job: " + job + ", in the catalog under the name: " + rScriptFromCatalog); } else { return rScriptFile; } } private File getRScriptFileFromJob(final MultiFilesJob job) { if ((job.getRScriptFile() == null) || (!job.getRScriptFile().isFile())) { throw new IllegalArgumentException("No R script has been found for job: " + job); } else { return job.getRScriptFile(); } } }, false); }
From source file:com.datatorrent.contrib.dimensions.DimensionsQueryExecutor.java
private void applyRolling(List<Map<String, EventKey>> keysEventKeys, List<Map<String, GPOMutable>> keys, List<Map<String, GPOMutable>> results, List<Map<String, GPOMutable>> rolledKeys, List<Map<String, GPOMutable>> rolledResults, DimensionalConfigurationSchema configurationSchema, DataQueryDimensional query) {//from www. j a v a2 s . c o m for (int offset = 0; offset < keys.size() - (query.getSlidingAggregateSize() - 1); offset++) { int index = offset + (query.getSlidingAggregateSize() - 1); Map<String, EventKey> bucketKeysEventKeys = keysEventKeys.get(index); Map<String, GPOMutable> bucketKeys = keys.get(index); Set<String> aggregators = Sets.newHashSet(bucketKeys.keySet()); for (int rollingIndex = 0; rollingIndex < query.getSlidingAggregateSize(); rollingIndex++) { //Get aggregators for rolling bucket Map<String, GPOMutable> key = keys.get(offset + rollingIndex); aggregators.retainAll(key.keySet()); } Set<String> unNeededAggregators = Sets.newHashSet(bucketKeys.keySet()); unNeededAggregators.removeAll(aggregators); for (String unNeededAggregator : unNeededAggregators) { bucketKeys.remove(unNeededAggregator); } Map<String, GPOMutable> result = Maps.newHashMap(); if (!aggregators.isEmpty()) { for (int rollingIndex = 0; rollingIndex < query.getSlidingAggregateSize(); rollingIndex++) { Map<String, GPOMutable> currentResult = results.get(offset + rollingIndex); for (String aggregator : aggregators) { IncrementalAggregator incrementalAggregator = configurationSchema.getAggregatorRegistry() .getNameToIncrementalAggregator().get(aggregator); GPOMutable aggregate = result.get(aggregator); GPOMutable currentAggregate = currentResult.get(aggregator); EventKey currentEventKey = bucketKeysEventKeys.get(aggregator); if (aggregate == null) { result.put(aggregator, currentAggregate); } else { incrementalAggregator.aggregate(new Aggregate(currentEventKey, aggregate), new Aggregate(currentEventKey, currentAggregate)); } } } } rolledKeys.add(bucketKeys); rolledResults.add(result); } }
From source file:dr.evomodel.continuous.ContinuousDiffusionStatistic.java
private static boolean onAncestralPathTaxa(Tree tree, NodeRef node, TaxonList taxonList) throws TreeUtils.MissingTaxonException { if (tree.isExternal(node)) return false; Set leafSet = TreeUtils.getDescendantLeaves(tree, node); int size = leafSet.size(); Set targetSet = TreeUtils.getLeavesForTaxa(tree, taxonList); leafSet.retainAll(targetSet);//from w w w. j a va 2 s .c o m if (leafSet.size() > 0) { // if all leaves below are in target then check just above. if (leafSet.size() == size) { Set superLeafSet = TreeUtils.getDescendantLeaves(tree, tree.getParent(node)); superLeafSet.removeAll(targetSet); // the branch is on ancestral path if the super tree has some non-targets in it return (superLeafSet.size() > 0); } else return true; } else return false; }