List of usage examples for java.util Set removeAll
boolean removeAll(Collection<?> c);
From source file:ditl.graphs.cli.Reachability.java
private void clean() throws IOException { final Set<String> to_keep = new HashSet<String>(); final Set<String> to_remove = new HashSet<String>(); Collections.sort(created_families, new Comparator<ReachabilityFamily>() { @Override// w w w .j a va 2 s .c o m public int compare(ReachabilityFamily f1, ReachabilityFamily f2) { if (f1.delay() < f2.delay()) return -1; if (f1.delay() > f2.delay()) return 1; return 0; } }); final Iterator<ReachabilityFamily> i = created_families.iterator(); while (i.hasNext()) { final ReachabilityFamily family = i.next(); if (!i.hasNext() && prune_last) to_remove.addAll(family.prunableNames()); else if (i.hasNext() && prune) to_remove.addAll(family.prunableNames()); if (families_to_keep.contains(family.delay()) || !delete) to_keep.add(family.mainName()); else if (delete) to_remove.add(family.mainName()); } to_remove.removeAll(to_keep); for (final String name : to_remove) dest_store.deleteTrace(name); }
From source file:kr.co.bitnine.octopus.meta.jdo.JDOMetaContext.java
private void updateColumnsOfTable(Table rawTable, MTable mTable) throws MetaException { Map<String, MColumn> oldColumns = new HashMap<>(); for (MetaColumn col : mTable.getColumns()) oldColumns.put(col.getName(), (MColumn) col); Set<String> oldColumnNames = new TreeSet<>(oldColumns.keySet()); Set<String> newColumnNames = new TreeSet<>(); for (Column rawColumn : getRawTableColumns(rawTable)) { String colName = rawColumn.getName(); newColumnNames.add(colName);/*www .j av a 2s . c o m*/ /* NOTE: column order could be wrong! */ if (!oldColumns.containsKey(colName)) addColumn(rawColumn, mTable); } // remove old columns oldColumnNames.removeAll(newColumnNames); for (String name : oldColumnNames) pm.deletePersistent(oldColumns.get(name)); }
From source file:com.tesora.dve.sql.schema.PETable.java
protected void updateExistingTriggers(SchemaContext sc, UserTable ut) throws PEException { HashMap<String, UserTrigger> persistent = new HashMap<String, UserTrigger>(); HashMap<String, PETrigger> trans = new HashMap<String, PETrigger>(); for (PETableTriggerEventInfo trig : triggers.values()) { for (PETrigger pet : trig.get()) { trans.put(pet.getName().getUnqualified().getUnquotedName().get(), pet); }//from w ww .j a va2 s . co m } for (UserTrigger trig : ut.getTriggers()) persistent.put(trig.getName(), trig); // anything that exists in persistent but not in trans has been deleted // anything that exists in trans but not persistent has been added Set<String> persTrigNames = persistent.keySet(); Set<String> transTrigNames = trans.keySet(); if (persTrigNames.equals(transTrigNames)) return; // nothing to do if (persTrigNames.size() < transTrigNames.size()) { // added transTrigNames.removeAll(persTrigNames); for (String s : transTrigNames) { ut.getTriggers().add(trans.get(s).persistTree(sc)); } } else { // dropped persTrigNames.removeAll(transTrigNames); for (String s : persTrigNames) { ut.getTriggers().remove(trans.get(s).persistTree(sc)); } } }
From source file:de.tudarmstadt.ukp.clarin.webanno.tsv.WebannoCustomTsvWriter.java
private void convertToTsv(JCas aJCas, OutputStream aOs, String aEncoding) throws IOException, ResourceInitializationException, CASRuntimeException, CASException { tokenIds = new HashMap<Integer, String>(); setTokenId(aJCas, tokenIds);//ww w. jav a2 s. c o m tokenPositions = new TreeMap<Integer, Integer>(); setTokenPosition(aJCas, tokenPositions); Map<Integer, Integer> getTokensPerSentence = new TreeMap<Integer, Integer>(); setTokenSentenceAddress(aJCas, getTokensPerSentence); // list of annotation types Set<Type> allTypes = new LinkedHashSet<Type>(); for (Annotation a : select(aJCas, Annotation.class)) { if (!(a instanceof Token || a instanceof Sentence || a instanceof DocumentMetaData || a instanceof TagsetDescription || a instanceof CoreferenceLink)) { allTypes.add(a.getType()); } } Set<Type> relationTypes = new LinkedHashSet<Type>(); // get all arc types for (Type type : allTypes) { if (type.getFeatures().size() == 0) { continue; } for (Feature feature : type.getFeatures()) { if (feature.getShortName().equals(GOVERNOR)) { relationTypes.add(type); break; } } } allTypes.removeAll(relationTypes); // relation annotations Map<Type, String> relationTypesMap = new HashMap<Type, String>(); for (Type type : relationTypes) { if (type.getName().equals(Dependency.class.getName())) { relationTypesMap.put(type, POS.class.getName()); continue; } for (AnnotationFS anno : CasUtil.select(aJCas.getCas(), type)) { for (Feature feature : type.getFeatures()) { if (feature.getShortName().equals(GOVERNOR)) { relationTypesMap.put(type, anno.getFeatureValue(feature).getType().getName()); } } } } // all span annotation first Map<Feature, Type> spanFeatures = new LinkedHashMap<Feature, Type>(); allTypes: for (Type type : allTypes) { if (type.getFeatures().size() == 0) { continue; } for (Feature feature : type.getFeatures()) { // coreference annotation not supported if (feature.getShortName().equals(FIRST) || feature.getShortName().equals(NEXT)) { continue allTypes; } } IOUtils.write(" # " + type.getName(), aOs, aEncoding); for (Feature feature : type.getFeatures()) { if (feature.toString().equals("uima.cas.AnnotationBase:sofa") || feature.toString().equals("uima.tcas.Annotation:begin") || feature.toString().equals("uima.tcas.Annotation:end")) { continue; } spanFeatures.put(feature, type); IOUtils.write(" | " + feature.getShortName(), aOs, aEncoding); } } // write all relation annotation first Set<Feature> relationFeatures = new LinkedHashSet<Feature>(); for (Type type : relationTypes) { IOUtils.write(" # " + type.getName(), aOs, aEncoding); for (Feature feature : type.getFeatures()) { if (feature.toString().equals("uima.cas.AnnotationBase:sofa") || feature.toString().equals("uima.tcas.Annotation:begin") || feature.toString().equals("uima.tcas.Annotation:end") || feature.getShortName().equals(GOVERNOR) || feature.getShortName().equals(DEPENDENT)) { continue; } relationFeatures.add(feature); IOUtils.write(" | " + feature.getShortName(), aOs, aEncoding); } // Add the attach type for the realtion anotation IOUtils.write(" | AttachTo=" + relationTypesMap.get(type), aOs, aEncoding); } IOUtils.write("\n", aOs, aEncoding); Map<Feature, Map<Integer, String>> allAnnos = new HashMap<Feature, Map<Integer, String>>(); allTypes: for (Type type : allTypes) { for (Feature feature : type.getFeatures()) { // coreference annotation not supported if (feature.getShortName().equals(FIRST) || feature.getShortName().equals(NEXT)) { continue allTypes; } } for (Feature feature : type.getFeatures()) { if (feature.toString().equals("uima.cas.AnnotationBase:sofa") || feature.toString().equals("uima.tcas.Annotation:begin") || feature.toString().equals("uima.tcas.Annotation:end")) { continue; } Map<Integer, String> tokenAnnoMap = new TreeMap<Integer, String>(); setTokenAnnos(aJCas.getCas(), tokenAnnoMap, type, feature); allAnnos.put(feature, tokenAnnoMap); } } // get tokens where dependents are drown to Map<Feature, Map<Integer, String>> relAnnos = new HashMap<Feature, Map<Integer, String>>(); for (Type type : relationTypes) { for (Feature feature : type.getFeatures()) { if (feature.toString().equals("uima.cas.AnnotationBase:sofa") || feature.toString().equals("uima.tcas.Annotation:begin") || feature.toString().equals("uima.tcas.Annotation:end") || feature.getShortName().equals(GOVERNOR) || feature.getShortName().equals(DEPENDENT)) { continue; } Map<Integer, String> tokenAnnoMap = new HashMap<Integer, String>(); setRelationFeatureAnnos(aJCas.getCas(), tokenAnnoMap, type, feature); relAnnos.put(feature, tokenAnnoMap); } } // get tokens where dependents are drown from - the governor Map<Type, Map<Integer, String>> governorAnnos = new HashMap<Type, Map<Integer, String>>(); for (Type type : relationTypes) { Map<Integer, String> govAnnoMap = new HashMap<Integer, String>(); setRelationGovernorPos(aJCas.getCas(), govAnnoMap, type); governorAnnos.put(type, govAnnoMap); } int sentId = 1; for (Sentence sentence : select(aJCas, Sentence.class)) { IOUtils.write("#id=" + sentId++ + "\n", aOs, aEncoding); IOUtils.write("#text=" + sentence.getCoveredText().replace("\n", "") + "\n", aOs, aEncoding); for (Token token : selectCovered(Token.class, sentence)) { IOUtils.write(tokenIds.get(token.getAddress()) + "\t" + token.getCoveredText() + "\t", aOs, aEncoding); // all span annotations on this token for (Feature feature : spanFeatures.keySet()) { String annos = allAnnos.get(feature).get(token.getAddress()); if (annos == null) { if (multipleSpans.contains(spanFeatures.get(feature).getName())) { IOUtils.write("O\t", aOs, aEncoding); } else { IOUtils.write("_\t", aOs, aEncoding); } } else { IOUtils.write(annos + "\t", aOs, aEncoding); } } // for all relation features for (Type type : relationTypes) { for (Feature feature : type.getFeatures()) { if (feature.toString().equals("uima.cas.AnnotationBase:sofa") || feature.toString().equals("uima.tcas.Annotation:begin") || feature.toString().equals("uima.tcas.Annotation:end") || feature.getShortName().equals(GOVERNOR) || feature.getShortName().equals(DEPENDENT)) { continue; } String annos = relAnnos.get(feature).get(token.getAddress()); if (annos == null) { IOUtils.write("_\t", aOs, aEncoding); } else { IOUtils.write(annos + "\t", aOs, aEncoding); } } // the governor positions String govPos = governorAnnos.get(type).get(token.getAddress()); if (govPos == null) { IOUtils.write("_\t", aOs, aEncoding); } else { IOUtils.write(governorAnnos.get(type).get(token.getAddress()) + "\t", aOs, aEncoding); } } IOUtils.write("\n", aOs, aEncoding); } IOUtils.write("\n", aOs, aEncoding); } }
From source file:edu.cornell.mannlib.vitro.webapp.visualization.coauthorship.CoAuthorshipQueryRunner.java
private void removeLowQualityNodesAndEdges(Set<Collaborator> nodes, Map<String, Activity> biboDocumentURLToVO, Map<String, Set<Collaborator>> biboDocumentURLToCoAuthors, Set<Collaboration> edges) { Set<Collaborator> nodesToBeRemoved = new HashSet<Collaborator>(); for (Map.Entry<String, Set<Collaborator>> currentBiboDocumentEntry : biboDocumentURLToCoAuthors .entrySet()) {/*from w ww . j a v a 2s. c om*/ if (currentBiboDocumentEntry.getValue().size() > MAX_AUTHORS_PER_PAPER_ALLOWED) { Activity currentBiboDocument = biboDocumentURLToVO.get(currentBiboDocumentEntry.getKey()); Set<Collaboration> edgesToBeRemoved = new HashSet<Collaboration>(); for (Collaboration currentEdge : edges) { Set<Activity> currentCollaboratorDocuments = currentEdge.getCollaborationActivities(); if (currentCollaboratorDocuments.contains(currentBiboDocument)) { currentCollaboratorDocuments.remove(currentBiboDocument); if (currentCollaboratorDocuments.isEmpty()) { edgesToBeRemoved.add(currentEdge); } } } edges.removeAll(edgesToBeRemoved); for (Collaborator currentCoAuthor : currentBiboDocumentEntry.getValue()) { currentCoAuthor.getCollaboratorActivities().remove(currentBiboDocument); if (currentCoAuthor.getCollaboratorActivities().isEmpty()) { nodesToBeRemoved.add(currentCoAuthor); } } } } nodes.removeAll(nodesToBeRemoved); }
From source file:dr.evomodel.continuous.ContinuousDiffusionStatistic.java
public boolean inClade(MutableTreeModel tree, NodeRef node, TaxonList taxonList) throws TreeUtils.MissingTaxonException { Set leafSubSet;/*from w w w. j a v a2s . c om*/ leafSubSet = TreeUtils.getLeavesForTaxa(tree, taxonList); NodeRef mrca = TreeUtils.getCommonAncestorNode(tree, leafSubSet); Set mrcaLeafSet = TreeUtils.getDescendantLeaves(tree, mrca); Set nodeLeafSet = TreeUtils.getDescendantLeaves(tree, node); if (!nodeLeafSet.isEmpty()) { nodeLeafSet.removeAll(mrcaLeafSet); } if (nodeLeafSet.isEmpty()) { return true; } else { } return false; }
From source file:edu.cmu.cs.lti.discoursedb.api.browsing.controller.BrowsingRestController.java
Set<DiscoursePart> exportDiscoursePartRecursively(DiscoursePart dp, String bratDirectory, Set<DiscoursePart> exported) throws IOException { if (exported.contains(dp)) { return exported; }/* w w w . java 2s . com*/ Set<DiscoursePart> kids = discoursePartRelationRepository.findAllBySource(dp).stream() .map(dpr -> dpr.getTarget()).collect(Collectors.toSet()); //logger.info("Recursive export: " + dp.getId() + " contains " + kids.size() + " kids"); kids.removeAll(exported); //logger.info("Recursive export: " + dp.getId() + " contains " + kids.size() + " NEW kids"); Set<DiscoursePart> exportedNow = exported; //NB: used to do this only if len(kids) == 0; but sometimes DPs can contain contributions *and* other DPs bratService.exportDiscoursePart(dp, bratDirectory, true); exportedNow.add(dp); logger.info("Recursive export: " + dp.getId() + " contains " + kids.size() + " NEW kids"); for (DiscoursePart k : kids) { String kidname = bratService.discoursePart2BratName(dp); //dp.getClass().getAnnotation(Table.class).name() + "_"+dp.getId(); //delete me //logger.info("About to recurse: kidname = " + kidname + " filename = " + (new File(bratDirectory,kidname)).toString()); exportedNow.addAll(exportDiscoursePartRecursively(k, (new File(bratDirectory, kidname + "_")).toString(), exportedNow)); } return exportedNow; }
From source file:com.ibm.jaggr.core.impl.AbstractAggregatorImpl.java
/** * Adds the specified extension to the list of registered extensions. * * @param ext/* w w w . j a v a2s. co m*/ * The extension to add * @param before * Reference to an existing extension that the * new extension should be placed before in the list. If null, * then the new extension is added to the end of the list */ protected void registerExtension(IAggregatorExtension ext, IAggregatorExtension before) { final String sourceMethod = "registerExtension"; //$NON-NLS-1$ boolean isTraceLogging = log.isLoggable(Level.FINER); if (isTraceLogging) { log.entering(AbstractAggregatorImpl.class.getName(), sourceMethod, new Object[] { ext, before }); } // validate type String id = ext.getExtensionPointId(); if (IHttpTransportExtensionPoint.ID.equals(id)) { if (before != null) { throw new IllegalArgumentException(before.getExtensionPointId()); } httpTransportExtension = ext; } else { List<IAggregatorExtension> list; if (IResourceFactoryExtensionPoint.ID.equals(id)) { list = resourceFactoryExtensions; } else if (IModuleBuilderExtensionPoint.ID.equals(id)) { list = moduleBuilderExtensions; } else if (IServiceProviderExtensionPoint.ID.equals(id)) { list = serviceProviderExtensions; } else { throw new IllegalArgumentException(id); } if (before == null) { list.add(ext); } else { // find the extension to insert the item in front of boolean inserted = false; for (int i = 0; i < list.size(); i++) { if (list.get(i) == before) { resourceFactoryExtensions.add(i, ext); inserted = true; break; } } if (!inserted) { throw new IllegalArgumentException(); } } // If this is a service provider extension the register the specified service if // one is indicated. if (IServiceProviderExtensionPoint.ID.equals(id)) { String interfaceName = ext.getAttribute(IServiceProviderExtensionPoint.SERVICE_ATTRIBUTE); if (interfaceName != null) { try { Dictionary<String, String> props = new Hashtable<String, String>(); // Copy init-params from extension to service dictionary Set<String> attributeNames = new HashSet<String>(ext.getAttributeNames()); attributeNames.removeAll(Arrays.asList( new String[] { "class", IServiceProviderExtensionPoint.SERVICE_ATTRIBUTE })); //$NON-NLS-1$ for (String propName : attributeNames) { props.put(propName, ext.getAttribute(propName)); } // Set name property to aggregator name props.put("name", getName()); //$NON-NLS-1$ registrations.add( getPlatformServices().registerService(interfaceName, ext.getInstance(), props)); } catch (Exception e) { if (log.isLoggable(Level.WARNING)) { log.log(Level.WARNING, e.getMessage(), e); } } } } } if (isTraceLogging) { log.exiting(AbstractAggregatorImpl.class.getName(), sourceMethod); } }
From source file:com.mirth.connect.client.ui.editors.filter.FilterPane.java
/** * @return Returns true if the filter has unsupported rule types and an alert was generated, * false otherwise.//from w ww. j a v a 2 s . co m */ private boolean alertUnsupportedRuleTypes(Filter filter) { if (LoadedExtensions.getInstance().getFilterRulePlugins().values().size() == 0) { parent.alertError(this, "No filter rule plugins loaded.\r\nPlease install plugins and try again."); return true; } Set<String> types = new HashSet<String>(); for (Rule rule : filter.getRules()) { types.add(rule.getType()); } types.removeAll(LoadedExtensions.getInstance().getFilterRulePlugins().keySet()); if (!types.isEmpty()) { if (types.size() == 1) { parent.alertError(this, "The \"" + types.toArray()[0] + "\" rule plugin is required by this filter. Please install this plugin and try again."); } else { parent.alertError(this, "The following rule type plugins are required by this filter: " + StringUtils.join(types, ", ") + ". Please install these plugins and try again."); } return true; } return false; }
From source file:com.hurence.logisland.plugin.PluginManager.java
private static void installPlugin(String artifact, String logislandHome) { Optional<ModuleInfo> moduleInfo = findPluginMeta().entrySet().stream() .filter(e -> artifact.equals(e.getKey().getArtifact())).map(Map.Entry::getKey).findFirst(); if (moduleInfo.isPresent()) { System.err/*from w w w .ja v a2s. c om*/ .println("A component already matches the artifact " + artifact + ". Please remove it first."); System.exit(-1); } try { IvySettings settings = new IvySettings(); settings.load(new File(logislandHome, "conf/ivy.xml")); Ivy ivy = Ivy.newInstance(settings); ivy.bind(); System.out.println("\nDownloading dependencies. Please hold on...\n"); String parts[] = Arrays.stream(artifact.split(":")).map(String::trim).toArray(a -> new String[a]); if (parts.length != 3) { throw new IllegalArgumentException( "Unrecognized artifact format. It should be groupId:artifactId:version"); } ModuleRevisionId revisionId = new ModuleRevisionId(new ModuleId(parts[0], parts[1]), parts[2]); Set<ArtifactDownloadReport> toBePackaged = downloadArtifacts(ivy, revisionId, new String[] { "default", "compile", "runtime" }); ArtifactDownloadReport artifactJar = toBePackaged.stream() .filter(a -> a.getArtifact().getModuleRevisionId().equals(revisionId)).findFirst() .orElseThrow(() -> new IllegalStateException("Unable to find artifact " + artifact + ". Please check the name is correct and the repositories on ivy.xml are correctly configured")); Manifest manifest = new JarFile(artifactJar.getLocalFile()).getManifest(); File libDir = new File(logislandHome, "lib"); if (manifest.getMainAttributes().containsKey(ManifestAttributes.MODULE_ARTIFACT)) { org.apache.commons.io.FileUtils.copyFileToDirectory(artifactJar.getLocalFile(), libDir); //we have a logisland plugin. Just copy it System.out.println(String.format("Found logisland plugin %s version %s\n" + "It will provide:", manifest.getMainAttributes().getValue(ManifestAttributes.MODULE_NAME), manifest.getMainAttributes().getValue(ManifestAttributes.MODULE_VERSION))); Arrays.stream(manifest.getMainAttributes().getValue(ManifestAttributes.MODULE_EXPORTS).split(",")) .map(String::trim).forEach(s -> System.out.println("\t" + s)); } else { System.out.println("Repackaging artifact and its dependencies"); Set<ArtifactDownloadReport> environment = downloadArtifacts(ivy, revisionId, new String[] { "provided" }); Set<ArtifactDownloadReport> excluded = toBePackaged.stream() .filter(adr -> excludeGroupIds.stream() .anyMatch(s -> s.matches(adr.getArtifact().getModuleRevisionId().getOrganisation())) || excludedArtifactsId.stream().anyMatch( s -> s.matches(adr.getArtifact().getModuleRevisionId().getName()))) .collect(Collectors.toSet()); toBePackaged.removeAll(excluded); environment.addAll(excluded); Repackager rep = new Repackager(artifactJar.getLocalFile(), new LogislandPluginLayoutFactory()); rep.setMainClass(""); File destFile = new File(libDir, "logisland-component-" + artifactJar.getLocalFile().getName()); rep.repackage(destFile, callback -> toBePackaged.stream().filter(adr -> adr.getLocalFile() != null) .filter(adr -> !adr.getArtifact().getModuleRevisionId().equals(revisionId)) .map(adr -> new Library(adr.getLocalFile(), LibraryScope.COMPILE)).forEach(library -> { try { callback.library(library); } catch (IOException e) { throw new UncheckedIOException(e); } })); Thread.currentThread().setContextClassLoader(new URLClassLoader( environment.stream().filter(adr -> adr.getLocalFile() != null).map(adr -> { try { return adr.getLocalFile().toURI().toURL(); } catch (Exception e) { throw new RuntimeException(e); } }).toArray(a -> new URL[a]), Thread.currentThread().getContextClassLoader())); //now clean up package and write the manifest String newArtifact = "com.hurence.logisland.repackaged:" + parts[1] + ":" + parts[2]; LogislandRepackager.execute(destFile.getAbsolutePath(), "BOOT-INF/lib-provided", parts[2], newArtifact, "Logisland Component for " + artifact, "Logisland Component for " + artifact, new String[] { "org.apache.kafka.*" }, new String[0], "org.apache.kafka.connect.connector.Connector"); } System.out.println("Install done!"); } catch (Exception e) { System.err.println("Unable to install artifact " + artifact); e.printStackTrace(); System.exit(-1); } }