List of usage examples for java.util Set removeAll
boolean removeAll(Collection<?> c);
From source file:com.networknt.light.rule.catalog.AbstractCatalogRule.java
public boolean updProduct(Object... objects) throws Exception { Map<String, Object> inputMap = (Map<String, Object>) objects[0]; Map<String, Object> data = (Map<String, Object>) inputMap.get("data"); String rid = (String) data.get("@rid"); String host = (String) data.get("host"); String error = null;// w w w.j av a 2 s. c o m Map<String, Object> payload = (Map<String, Object>) inputMap.get("payload"); OrientGraph graph = ServiceLocator.getInstance().getGraph(); try { // update product itself and we might have a new api to move product from one parent to another. Vertex product = DbService.getVertexByRid(graph, rid); if (product != null) { Map<String, Object> user = (Map<String, Object>) payload.get("user"); Map eventMap = getEventMap(inputMap); Map<String, Object> eventData = (Map<String, Object>) eventMap.get("data"); inputMap.put("eventMap", eventMap); eventData.put("productId", product.getProperty("productId")); eventData.put("name", data.get("name")); eventData.put("description", data.get("description")); eventData.put("variants", data.get("variants")); eventData.put("updateDate", new java.util.Date()); eventData.put("updateUserId", user.get("userId")); // tags Set<String> inputTags = data.get("tags") != null ? new HashSet<String>(Arrays.asList(((String) data.get("tags")).split("\\s*,\\s*"))) : new HashSet<String>(); Set<String> storedTags = new HashSet<String>(); for (Vertex vertex : (Iterable<Vertex>) product.getVertices(Direction.OUT, "HasTag")) { storedTags.add((String) vertex.getProperty("tagId")); } Set<String> addTags = new HashSet<String>(inputTags); Set<String> delTags = new HashSet<String>(storedTags); addTags.removeAll(storedTags); delTags.removeAll(inputTags); if (addTags.size() > 0) eventData.put("addTags", addTags); if (delTags.size() > 0) eventData.put("delTags", delTags); } else { error = "@rid " + rid + " cannot be found"; inputMap.put("responseCode", 404); } } catch (Exception e) { logger.error("Exception:", e); throw e; } finally { graph.shutdown(); } if (error != null) { inputMap.put("result", error); return false; } else { // update the branch tree as the last update time has changed. Map<String, Object> branchMap = ServiceLocator.getInstance().getMemoryImage("branchMap"); ConcurrentMap<Object, Object> cache = (ConcurrentMap<Object, Object>) branchMap.get("treeCache"); if (cache != null) { cache.remove(host + branchType); } return true; } }
From source file:HSqlManager.java
private static void checkPhage(Connection connection) throws SQLException, IOException { List<String[]> all = INSTANCE.readFileAllStrains(INSTANCE.path); List<String> clusters = all.stream().map(x -> x[0]).collect(Collectors.toList()); Set<String> phages = all.stream().map(x -> x[1]).collect(Collectors.toSet()); List<String> strains = all.stream().map(x -> x[2]).collect(Collectors.toList()); List<String> phageslist = all.stream().map(x -> x[1]).collect(Collectors.toList()); Set<String> dbphages = new HashSet<>(); Statement st = connection.createStatement(); PreparedStatement insertPhages = connection .prepareStatement("INSERT INTO Primerdb.Phages(Name, Cluster, Strain)" + " values(?,?,?);"); String sql = "SELECT * FROM Primerdb.Phages;"; ResultSet rs = st.executeQuery(sql); while (rs.next()) { dbphages.add(rs.getString("Name")); }/* www. j a v a 2 s.c o m*/ phages.removeAll(dbphages); List<String[]> phageinfo = new ArrayList<>(); if (phages.size() > 0) { System.out.println("Phages Added:"); phages.forEach(x -> { String[] ar = new String[3]; System.out.println(x); String cluster = clusters.get(phageslist.indexOf(x)); String strain = strains.get(phageslist.indexOf(x)); try { insertPhages.setString(1, x); insertPhages.setString(2, cluster); insertPhages.setString(3, strain); insertPhages.addBatch(); } catch (SQLException e) { e.printStackTrace(); } try { insertPhages.executeBatch(); } catch (SQLException e) { e.printStackTrace(); } ar[0] = x; ar[1] = cluster; ar[2] = strain; phageinfo.add(ar); }); newPhages = phageinfo; } else { System.out.println("No Phages added"); } st.close(); insertPhages.close(); }
From source file:com.ggvaidya.scinames.ui.DatasetDiffController.java
@SuppressWarnings({ "rawtypes", "unchecked" }) private String compareSets(Set a, Set b) { Set added = new HashSet(b); added.removeAll(a); Set removed = new HashSet(a); removed.removeAll(b);/*from ww w.j a va2 s . c om*/ return "+" + added.size() + ", -" + removed.size(); }
From source file:com.networknt.light.rule.AbstractBfnRule.java
public boolean updPost(String bfnType, Object... objects) throws Exception { Map<String, Object> inputMap = (Map<String, Object>) objects[0]; Map<String, Object> data = (Map<String, Object>) inputMap.get("data"); String rid = (String) data.get("@rid"); String host = (String) data.get("host"); String error = null;/*from w w w . j a v a 2s . c o m*/ Map<String, Object> payload = (Map<String, Object>) inputMap.get("payload"); OrientGraph graph = ServiceLocator.getInstance().getGraph(); try { // update post itself and we might have a new api to move post from one parent to another. Vertex post = DbService.getVertexByRid(graph, rid); if (post != null) { Map<String, Object> user = (Map<String, Object>) payload.get("user"); Map eventMap = getEventMap(inputMap); Map<String, Object> eventData = (Map<String, Object>) eventMap.get("data"); inputMap.put("eventMap", eventMap); eventData.put("postId", post.getProperty("postId")); eventData.put("title", data.get("title")); eventData.put("source", data.get("source")); eventData.put("summary", data.get("summary")); eventData.put("content", data.get("content")); eventData.put("updateDate", new java.util.Date()); eventData.put("updateUserId", user.get("userId")); // tags Set<String> inputTags = data.get("tags") != null ? new HashSet<String>(Arrays.asList(((String) data.get("tags")).split("\\s*,\\s*"))) : new HashSet<String>(); Set<String> storedTags = new HashSet<String>(); for (Vertex vertex : (Iterable<Vertex>) post.getVertices(Direction.OUT, "HasTag")) { storedTags.add((String) vertex.getProperty("tagId")); } Set<String> addTags = new HashSet<String>(inputTags); Set<String> delTags = new HashSet<String>(storedTags); addTags.removeAll(storedTags); delTags.removeAll(inputTags); if (addTags.size() > 0) eventData.put("addTags", addTags); if (delTags.size() > 0) eventData.put("delTags", delTags); } else { error = "@rid " + rid + " cannot be found"; inputMap.put("responseCode", 404); } } catch (Exception e) { logger.error("Exception:", e); throw e; } finally { graph.shutdown(); } if (error != null) { inputMap.put("result", error); return false; } else { // update the bfn tree as the last update time has changed. Map<String, Object> bfnMap = ServiceLocator.getInstance().getMemoryImage("bfnMap"); ConcurrentMap<Object, Object> cache = (ConcurrentMap<Object, Object>) bfnMap.get("treeCache"); if (cache != null) { cache.remove(host + bfnType); } return true; } }
From source file:com.github.aptd.simulation.TestCLanguageLabels.java
/** * test-case all resource strings/*from ww w .j a v a 2 s . com*/ * * @throws IOException throws on io errors */ @Test public void testResourceString() throws IOException { assumeTrue("no languages are defined for checking", !LANGUAGEPROPERY.isEmpty()); final Set<String> l_ignoredlabel = new HashSet<>(); // --- parse source and get label definition final Set<String> l_label = Collections.unmodifiableSet(Files.walk(Paths.get(SEARCHPATH)) .filter(Files::isRegularFile).filter(i -> i.toString().endsWith(".java")).flatMap(i -> { try { final CJavaVistor l_parser = new CJavaVistor(); l_parser.visit(JavaParser.parse(new FileInputStream(i.toFile())), null); return l_parser.labels().stream(); } catch (final IOException l_excpetion) { assertTrue(MessageFormat.format("io error on file [{0}]: {1}", i, l_excpetion.getMessage()), false); return Stream.empty(); } catch (final ParseProblemException l_exception) { // add label build by class path to the ignore list l_ignoredlabel.add(i.toAbsolutePath().toString() // remove path to class directory .replace(FileSystems.getDefault().provider().getPath(SEARCHPATH).toAbsolutePath() .toString(), "") // string starts with path separator .substring(1) // remove file extension .replace(".java", "") // replace separators with dots .replace("/", CLASSSEPARATOR) // convert to lower-case .toLowerCase() // remove package-root name .replace(CCommon.PACKAGEROOT + CLASSSEPARATOR, "")); System.err.println(MessageFormat.format("parsing error on file [{0}]:\n{1}", i, l_exception.getMessage())); return Stream.empty(); } }).collect(Collectors.toSet())); // --- check of any label is found assertFalse("translation labels are empty, check naming of translation method", l_label.isEmpty()); // --- check label towards the property definition if (l_ignoredlabel.size() > 0) System.err.println(MessageFormat.format( "labels that starts with {0} are ignored, because parsing errors are occurred", l_ignoredlabel)); LANGUAGEPROPERY.forEach((k, v) -> { try { final Properties l_property = new Properties(); l_property.load(new FileInputStream(new File(v))); final Set<String> l_parseditems = new HashSet<>(l_label); final Set<String> l_propertyitems = l_property.keySet().parallelStream().map(Object::toString) .collect(Collectors.toSet()); // --- check if all property items are within the parsed labels l_parseditems.removeAll(l_propertyitems); assertTrue(MessageFormat.format( "the following {1,choice,1#key|1<keys} in language [{0}] {1,choice,1#is|1<are} not existing within the language file:\n{2}", k, l_parseditems.size(), StringUtils.join(l_parseditems, ", ")), l_parseditems.isEmpty()); // --- check if all parsed labels within the property item and remove ignored labels l_propertyitems.removeAll(l_label); final Set<String> l_ignoredpropertyitems = l_propertyitems.parallelStream() .filter(j -> l_ignoredlabel.parallelStream().map(j::startsWith).allMatch(l -> false)) .collect(Collectors.toSet()); assertTrue(MessageFormat.format( "the following {1,choice,1#key|1<keys} in language [{0}] {1,choice,1#is|1<are} not existing within the source code:\n{2}", k, l_ignoredpropertyitems.size(), StringUtils.join(l_ignoredpropertyitems, ", ")), l_ignoredpropertyitems.isEmpty()); } catch (final IOException l_exception) { assertTrue(MessageFormat.format("io exception: {0}", l_exception.getMessage()), false); } }); }
From source file:de.flashpixx.rrd_antlr4.TestCLanguageLabels.java
/** * test-case all resource strings// w w w .j a v a 2 s .c o m * * @throws IOException throws on io errors */ @Test public void testResourceString() throws IOException { assumeTrue("no languages are defined for checking", !LANGUAGEPROPERY.isEmpty()); final Set<String> l_ignoredlabel = new HashSet<>(); // --- parse source and get label definition final Set<String> l_label = Collections.unmodifiableSet(Files.walk(Paths.get(SEARCHPATH)) .filter(Files::isRegularFile).filter(i -> i.toString().endsWith(".java")).flatMap(i -> { try { final CJavaVistor l_parser = new CJavaVistor(); l_parser.visit(JavaParser.parse(new FileInputStream(i.toFile())), null); return l_parser.labels().stream(); } catch (final IOException l_excpetion) { assertTrue(MessageFormat.format("io error on file [{0}]: {1}", i, l_excpetion.getMessage()), false); return Stream.<String>empty(); } catch (final ParseException l_exception) { // add label build by class path to the ignore list l_ignoredlabel.add(i.toAbsolutePath().toString() // remove path to class directory .replace(FileSystems.getDefault().provider().getPath(SEARCHPATH).toAbsolutePath() .toString(), "") // string starts with path separator .substring(1) // remove file extension .replace(".java", "") // replace separators with dots .replace("/", CLASSSEPARATOR) // convert to lower-case .toLowerCase() // remove package-root name .replace(CCommon.PACKAGEROOT + CLASSSEPARATOR, "")); System.err.println(MessageFormat.format("parsing error on file [{0}]:\n{1}", i, l_exception.getMessage())); return Stream.<String>empty(); } }).collect(Collectors.toSet())); // --- check of any label is found assertFalse("translation labels are empty, check naming of translation method", l_label.isEmpty()); // --- check label towards the property definition if (l_ignoredlabel.size() > 0) System.err.println(MessageFormat.format( "labels that starts with {0} are ignored, because parsing errors are occurred", l_ignoredlabel)); LANGUAGEPROPERY.entrySet().forEach(i -> { try { final Properties l_property = new Properties(); l_property.load(new FileInputStream(new File(i.getValue()))); final Set<String> l_parseditems = new HashSet<>(l_label); final Set<String> l_propertyitems = l_property.keySet().parallelStream().map(Object::toString) .collect(Collectors.toSet()); // --- check if all property items are within the parsed labels l_parseditems.removeAll(l_propertyitems); assertTrue(MessageFormat.format( "the following {1,choice,1#key|1<keys} in language [{0}] {1,choice,1#is|1<are} not existing within the language file:\n{2}", i.getKey(), l_parseditems.size(), StringUtils.join(l_parseditems, ", ")), l_parseditems.isEmpty()); // --- check if all parsed labels within the property item and remove ignored labels l_propertyitems.removeAll(l_label); final Set<String> l_ignoredpropertyitems = l_propertyitems.parallelStream() .filter(j -> l_ignoredlabel.parallelStream().map(j::startsWith).allMatch(l -> false)) .collect(Collectors.toSet()); assertTrue(MessageFormat.format( "the following {1,choice,1#key|1<keys} in language [{0}] {1,choice,1#is|1<are} not existing within the source code:\n{2}", i.getKey(), l_ignoredpropertyitems.size(), StringUtils.join(l_ignoredpropertyitems, ", ")), l_ignoredpropertyitems.isEmpty()); } catch (final IOException l_exception) { assertTrue(MessageFormat.format("io exception: {0}", l_exception.getMessage()), false); } }); }
From source file:com.twosigma.beaker.core.rest.UtilRest.java
private static Set<String> mergeListSetting(String settingsListName, JSONObject configs, JSONObject prefs) { Set<String> settings = new LinkedHashSet<>(); Set<String> settingsToRemove = new HashSet<>(); { // settings from config JSONArray s = (JSONArray) configs.get(settingsListName); if (s != null) { @SuppressWarnings("unchecked") Iterator<String> iterator = s.iterator(); while (iterator.hasNext()) { settings.add(iterator.next()); }/*from w w w . ja v a 2 s . c om*/ } } { // settings from preference JSONArray s = (JSONArray) prefs.get(settingsListName); if (s != null) { @SuppressWarnings("unchecked") Iterator<String> iterator = s.iterator(); while (iterator.hasNext()) { settings.add(iterator.next()); } } } { // to-remove settings from preference JSONArray s = (JSONArray) prefs.get(TO_REMOVE_PREFIX + settingsListName); if (s != null) { @SuppressWarnings("unchecked") Iterator<String> iterator = s.iterator(); while (iterator.hasNext()) { settingsToRemove.add(iterator.next()); } } } settings.removeAll(settingsToRemove); return settings; }
From source file:net.riezebos.thoth.configuration.PropertyBasedConfiguration.java
@Override public boolean isFragment(String path) { if (fragmentExtensions == null) { Set<String> fragmentExtensions = new HashSet<>(); fragmentExtensions.addAll(getDocumentExtensions()); fragmentExtensions.removeAll(getBookExtensions()); this.fragmentExtensions = fragmentExtensions; }//from www. jav a2 s .co m if (ThothUtil.getFileName(path).startsWith(".")) return false; String extension = ThothUtil.getExtension(path); if (extension == null) return false; else extension = extension.toLowerCase(); return fragmentExtensions.contains(extension); }
From source file:gov.nih.nci.caintegrator.application.query.QueryManagementServiceImpl.java
/** * {@inheritDoc}/* w w w . j a v a 2 s . c o m*/ */ @Override public Set<String> getAllSubjectsNotFoundInCriteria(Query query) throws InvalidCriterionException { if (query == null) { return new HashSet<String>(); } Set<String> allSubjectsInCriterion = query.getCompoundCriterion().getAllSubjectIds(); Set<String> allSubjectsNotFound = new HashSet<String>(allSubjectsInCriterion); if (!allSubjectsInCriterion.isEmpty()) { Set<String> allSubjectsInStudy = getAllSubjectsInStudy(query); allSubjectsNotFound.removeAll(allSubjectsInStudy); if (areNoQuerySubjectsInStudy(allSubjectsInCriterion, allSubjectsNotFound)) { String queryNameString = StringUtils.isNotBlank(query.getName()) ? "'" + query.getName() + "' " : ""; throw new InvalidCriterionException( "None of the Subject IDs in the query " + queryNameString + "were found in the study."); } } return allSubjectsNotFound; }