List of usage examples for org.apache.commons.collections CollectionUtils subtract
public static Collection subtract(final Collection a, final Collection b)
From source file:com.nagarro.core.v2.controller.CustomerGroupsController.java
private void setUserListForCustomerGroupInternal(final String groupId, List<String> members) { if (members == null) { members = new ArrayList<>(); }/*w w w. jav a2 s.co m*/ final UserGroupData userGroup = customerGroupFacade.getCustomerGroup(groupId, Collections.singleton(UserGroupOption.MEMBERS)); final HashSet<String> oldMembers = new HashSet(); for (final PrincipalData member : userGroup.getMembers()) { oldMembers.add(member.getUid()); } final HashSet<String> newMembers = new HashSet(); for (final String member : members) { newMembers.add(member); } final Collection<String> membersToRemove = CollectionUtils.subtract(oldMembers, newMembers); checkMembers(membersToRemove, "You cannot remove user from group :" + sanitize(groupId) + "."); final Collection<String> membersToAdd = CollectionUtils.subtract(newMembers, oldMembers); checkMembers(membersToAdd, "You cannot add user to group :" + sanitize(groupId) + "."); for (final String memberToRemove : membersToRemove) { customerGroupFacade.removeUserFromCustomerGroup(groupId, memberToRemove); } for (final String memberToAdd : membersToAdd) { customerGroupFacade.addUserToCustomerGroup(groupId, memberToAdd); } }
From source file:edu.scripps.fl.pubchem.promiscuity.PCPromiscuityMain.java
private OverallListsAndMaps setOverallVariables() throws Exception { OverallListsAndMaps overall = new OverallListsAndMaps(); String db = params.getDatabase(); List<String> linkNames = Arrays.asList(new String[] { db + "_pcassay", db + "_pcassay_active" }); ELinkWebSession session = ELinkWebSession.newInstance(db, "pcassay", linkNames, params.getIds(), ""); log.info("Number of ids in compound to pcassay link request: " + String.valueOf(params.getIds().size())); session.run();/*from w w w .ja v a 2 s. c om*/ overall.setCompoundToAIDsMap(session.getELinkResultsAsMap()); OverallListsAndMapsFactory overallFactory = new OverallListsAndMapsFactory(); overall.setAllAIDs(session.getAllIds(db + "_pcassay")); log.info("Number of All AIDs: " + overall.getAllAIDs().size()); String shortDB = db.substring(2, db.length()); List<Long> proteinAssays = overallFactory.aidListEsearch(params.getIds(), "pcassay_protein_target[Filter]", shortDB); overall.setAllProteinAIDs(proteinAssays); overall.setAidProteinMap(overallFactory.getAIDProteinMap(new ArrayList<Long>(proteinAssays))); List<Long> noProteinAIDs = (List<Long>) CollectionUtils.subtract(overall.getAllAIDs(), proteinAssays); overall.setAllNoProteinAIDs(noProteinAIDs); log.info("Number of aids returned from eSummary request: " + overall.getAidProteinMap().keySet().size()); if (params.getPerProteinMode()) { overall.setAllProteins(overallFactory.allProteinSet(overall.getAidProteinMap())); overall.setProteinAIDMap( overallFactory.proteinAIDMap(overall.getAidProteinMap(), overall.getAllProteins())); if (!params.getSimpleMode()) advancedCounts(overallFactory, overall, session, shortDB); } else advancedCounts(overallFactory, overall, session, shortDB); if (db.equalsIgnoreCase("pcsubstance")) { session = ELinkWebSession.newInstance(db, "pccompound", Arrays.asList(new String[] { "pcsubstance_pccompound_same" }), params.getIds(), ""); session.run(); overall.setSIDToCIDMap(session.getELinkResultsAsMap()); } log.info("Set up all overall lists"); return overall; }
From source file:com.yahoo.pulsar.broker.service.PersistentQueueE2ETest.java
@Test public void testReplayOnConsumerDisconnect() throws Exception { final String topicName = "persistent://prop/use/ns-abc/shared-topic3"; final String subName = "sub3"; final int numMsgs = 100; final List<String> messagesProduced = Lists.newArrayListWithCapacity(numMsgs); final List<String> messagesConsumed = new BlockingArrayQueue<>(numMsgs); ConsumerConfiguration conf1 = new ConsumerConfiguration(); conf1.setSubscriptionType(SubscriptionType.Shared); conf1.setMessageListener((consumer, msg) -> { try {//w w w.ja v a 2 s . c o m consumer.acknowledge(msg); messagesConsumed.add(new String(msg.getData())); } catch (Exception e) { fail("Should not fail"); } }); ConsumerConfiguration conf2 = new ConsumerConfiguration(); conf2.setSubscriptionType(SubscriptionType.Shared); conf2.setMessageListener((consumer, msg) -> { try { // do nothing } catch (Exception e) { fail("Should not fail"); } }); Consumer consumer1 = pulsarClient.subscribe(topicName, subName, conf1); // consumer2 does not ack messages Consumer consumer2 = pulsarClient.subscribe(topicName, subName, conf2); List<CompletableFuture<MessageId>> futures = Lists.newArrayListWithCapacity(numMsgs * 2); Producer producer = pulsarClient.createProducer(topicName); for (int i = 0; i < numMsgs; i++) { String message = "msg-" + i; futures.add(producer.sendAsync(message.getBytes())); messagesProduced.add(message); } FutureUtil.waitForAll(futures).get(); producer.close(); consumer2.close(); for (int n = 0; n < 10 && messagesConsumed.size() < numMsgs; n++) { Thread.sleep(ASYNC_EVENT_COMPLETION_WAIT); } // 1. consumer1 gets all messages assertTrue(CollectionUtils.subtract(messagesProduced, messagesConsumed).isEmpty()); consumer1.close(); admin.persistentTopics().delete(topicName); }
From source file:com.bluexml.side.form.clazz.utils.SynchronizeWithClass.java
@SuppressWarnings("unchecked") Collection<AbstractClass> getAllClassesFromReferedModels(FormCollection fc) { Set<AbstractClass> existing = new HashSet<AbstractClass>(); Set<AbstractClass> all = new HashSet<AbstractClass>(); EList<FormContainer> forms = fc.getForms(); for (FormContainer formContainer : forms) { if (formContainer instanceof ClassReference) { ClassReference cr = (ClassReference) formContainer; AbstractClass real_class = cr.getReal_class(); if (real_class instanceof Clazz) { existing.add(real_class); }//from ww w. j a v a2 s . co m } } List<Model> lm = new ArrayList<Model>(); for (AbstractClass abstractClass : existing) { EObject rootContainer2 = CommonServices.getRootContainer(abstractClass); if (rootContainer2 instanceof Model) { Model rootContainer = (Model) rootContainer2; lm.add(rootContainer); } } for (Model package1 : lm) { EList<Clazz> allClasses = package1.getAllClasses(); all.addAll(allClasses); } return CollectionUtils.subtract(all, existing); }
From source file:de.hybris.platform.ycommercewebservices.v2.controller.CustomerGroupsController.java
private void setUserListForCustomerGroupInternal(final String groupId, List<String> members) { if (members == null) { members = new ArrayList<>(); }/*from w ww . j ava 2 s .c o m*/ final UserGroupData userGroup = customerGroupFacade.getCustomerGroup(groupId, Collections.singleton(UserGroupOption.MEMBERS)); final HashSet<String> oldMembers = new HashSet(); for (final PrincipalData member : userGroup.getMembers()) { oldMembers.add(member.getUid()); } final HashSet<String> newMembers = new HashSet(); for (final String member : members) { newMembers.add(member); } final Collection<String> membersToRemove = CollectionUtils.subtract(oldMembers, newMembers); checkMembers(membersToRemove, "You cannot remove user from group :" + groupId + "."); final Collection<String> membersToAdd = CollectionUtils.subtract(newMembers, oldMembers); checkMembers(membersToAdd, "You cannot add user to group :" + groupId + "."); for (final String memberToRemove : membersToRemove) { customerGroupFacade.removeUserFromCustomerGroup(groupId, memberToRemove); } for (final String memberToAdd : membersToAdd) { customerGroupFacade.addUserToCustomerGroup(groupId, memberToAdd); } }
From source file:fm.last.commons.test.LastAssertions.java
/** * Asserts that the contents of the files are equivalent - i.e. the same lines but not necessarily in the same order. * This allows you to compare files with contents that might be sorted differently. * /*w ww . j ava 2 s. c om*/ * @param expected File containing expected data. * @param expectedFileEncoding Encoding of expected file. * @param actual File to compare. * @param actualFileEncoding Encoding of actual file. * @throws IOException If an error occurs comparing the file contents. */ public static void assertFilesEquivalent(File expected, Charset expectedFileEncoding, File actual, Charset actualFileEncoding) throws IOException { expectedFileEncoding = resolveToDefault(expectedFileEncoding); actualFileEncoding = resolveToDefault(actualFileEncoding); List<String> expectedLines = FileUtils.readLines(expected, expectedFileEncoding); List<String> actualLines = FileUtils.readLines(actual, actualFileEncoding); int expectedLineCount = expectedLines.size(); int actualLineCount = actualLines.size(); Collection<String> difference; if (expectedLineCount >= actualLineCount) { difference = CollectionUtils.subtract(expectedLines, actualLines); } else { difference = CollectionUtils.subtract(actualLines, expectedLines); } assertEquals("Unexpected difference: " + difference, 0, difference.size()); }
From source file:RestoreService.java
/** * execute restore process/*w w w. j av a 2s. com*/ * * @throws Exception */ public void run() throws Exception { // load index Collection<File> bckIdxCollection = FileUtils.listFiles(repository.getMetaPath(), new WildcardFileFilter(bckIdxName + "*"), TrueFileFilter.INSTANCE); // TODO Lebeda - check only one index file // find files ro restore Set<VOBackupFile> oldFileSet = repository.collectBackupedFilesFromIndex(bckIdxCollection); Set<VOBackupFile> restoreFileSet = new HashSet<>(); for (final String path : pathToRestoreList) { //noinspection unchecked restoreFileSet.addAll((Collection<VOBackupFile>) CollectionUtils.select(oldFileSet, new Predicate() { @Override public boolean evaluate(Object object) { VOBackupFile voBackupFile = (VOBackupFile) object; return StringUtils.startsWithIgnoreCase(voBackupFile.getPath(), path + File.separator); } })); } // create directory if not exists for (String pathForRestore : pathToRestoreList) { pathForRestore = changedPathToRestore(pathForRestore, targetPath); File baseFile = new File(pathForRestore); if (!baseFile.exists()) { //noinspection ResultOfMethodCallIgnored baseFile.mkdirs(); // TODO Lebeda - oetit hodnotu } } // find files in directory List<VOBackupFile> newFileList = new ArrayList<>(); for (String pathForRestore : pathToRestoreList) { pathForRestore = changedPathToRestore(pathForRestore, targetPath); //noinspection unchecked final Collection<File> fileColection = FileUtils.listFiles(new File(pathForRestore), TrueFileFilter.INSTANCE, TrueFileFilter.INSTANCE); for (File file : fileColection) { newFileList.add(new VOBackupFile(file)); } } // delete files not in index (new or changed) //noinspection unchecked final Collection<VOBackupFile> toDelete = (Collection<VOBackupFile>) CollectionUtils.subtract(newFileList, restoreFileSet); for (VOBackupFile voBackupFile : toDelete) { FileUtils.forceDelete(new File(voBackupFile.getPath())); logger.debug("deleted file: {}", voBackupFile.getPath()); } // restore files not in direcroty //noinspection unchecked final Collection<VOBackupFile> toRestore = (Collection<VOBackupFile>) CollectionUtils .subtract(restoreFileSet, newFileList); final Collection<VOBackupFile> toTime = new ArrayList<>(); for (VOBackupFile voBackupFile : toRestore) { String path = changedPathToRestore(voBackupFile.getPath(), targetPath); if (!voBackupFile.isSymLink()) { if (voBackupFile.isDirectory()) { File dir = new File(path); dir.mkdirs(); // TODO Lebeda - zajistit oeten toTime.add(voBackupFile); setAdvancedAttributes(voBackupFile, dir); } else if (voBackupFile.getSize() == 0) { File file = new File(path); file.createNewFile(); // TODO Lebeda - oetit file.setLastModified(voBackupFile.getModify().getTime()); setAdvancedAttributes(voBackupFile, file); } else if (StringUtils.isNotBlank(voBackupFile.getFileHash())) { repository.restoreFile(voBackupFile, path); } else { // TODO Lebeda - chyba // LoggerTools.log("unable to restore ${it}") } } } // symlinks restore at end for (VOBackupFile voBackupFile : toRestore) { String path = changedPathToRestore(voBackupFile.getPath(), targetPath); if (voBackupFile.isSymLink()) { Files.createSymbolicLink(Paths.get(path), Paths.get(voBackupFile.getSymlinkTarget())); } } for (VOBackupFile voBackupFile : toTime) { String path = changedPathToRestore(voBackupFile.getPath(), targetPath); File dir = new File(path); dir.setLastModified(voBackupFile.getModify().getTime()); } }
From source file:gov.nih.nci.cabig.caaers.web.security.FabricatedAuthenticationFilter.java
/** * @param httpRequest/*from ww w . j a v a 2s . co m*/ * the request object will have 3 attributes: * cl - a map of transformed Strings which are context roles display names * ol - a map of transformed Strings which are original (all) roles display names * roles - a map of applicable context role codes visible to the entire app, any JSP check "${roles.ae-reporter} for example" */ private void prepareRolesCollections(HttpServletRequest httpRequest) { // START Roles Map<String, String> roles = new HashMap<String, String>(); for (UserGroupType r : UserGroupType.values()) { roles.put(r.getCsmName(), r.getDisplayName()); } List ol = new ArrayList(); List cl = new ArrayList(); Map<String, String> authorities = new HashMap<String, String>(); Map originalRoles = new HashMap<String, String>(); Authentication originalAuthentication = SecurityUtils.getOriginalAuthentication(); if (originalAuthentication != null && originalAuthentication.getAuthorities() != null && originalAuthentication.getAuthorities().length > 0) { for (GrantedAuthority ga : originalAuthentication.getAuthorities()) { ol.add(roles.get(ga.getAuthority())); originalRoles.put(ga.getAuthority(), roles.get(ga.getAuthority())); } } Authentication contextualAuthentication = SecurityUtils.getAuthentication(); if (contextualAuthentication != null && contextualAuthentication.getAuthorities() != null && contextualAuthentication.getAuthorities().length > 0) { for (GrantedAuthority ga : contextualAuthentication.getAuthorities()) { cl.add(roles.get(ga.getAuthority())); authorities.put(ga.getAuthority(), roles.get(ga.getAuthority())); } } ol = (List) CollectionUtils.subtract(ol, cl); httpRequest.setAttribute("cl", cl); httpRequest.setAttribute("ol", ol); httpRequest.setAttribute("roles", authorities); httpRequest.setAttribute("originalRoles", originalRoles); // END Roles }
From source file:de.tudarmstadt.ukp.dkpro.tc.fstore.simple.SparseFeatureStore.java
@SuppressWarnings("unchecked") @Override//from w w w .j a v a2 s . com public void setFeatureNames(TreeSet<String> featureNames) { if (featureNames == null) { throw new IllegalArgumentException("param featureNames is null"); } if (featureNames.isEmpty()) { throw new IllegalStateException("Cannot set empty feature space"); } if (!isSettingFeatureNamesAllowed()) { throw new IllegalStateException("Setting feature names is not allowed."); } Set<String> deletedFeatures = new HashSet<>( (Collection<String>) CollectionUtils.subtract(this.allFeatureNames, featureNames)); log.debug(deletedFeatures.size() + " features from test data not seen in training data, " + "removing features from the store."); this.allFeatureNames = featureNames; // update all instances to they do not contain old features for (Map<String, Object> instance : this.instanceList) { for (String deletedFeature : deletedFeatures) { if (instance.containsKey(deletedFeature)) { instance.remove(deletedFeature); } } } }
From source file:edu.scripps.fl.pubchem.promiscuity.PCPromiscuityMain.java
private void advancedCounts(OverallListsAndMapsFactory overallFactory, OverallListsAndMaps overall, ELinkWebSession session, String shortDB) throws Exception { // all aids in each desired assay count category Map<String, List<Long>> overallTotalAIDMap = new HashMap<String, List<Long>>(searchNames.length); for (int ii = 0; ii < searchTerms.length; ii++) { String searchTerm = searchTerms[ii]; log.info("Advanced search: " + searchTerm); List<Long> list = overallFactory.aidListEsearch(params.getIds(), searchTerm, shortDB); overallTotalAIDMap.put(searchNames[ii], list); }/*from w ww. jav a2s . co m*/ overall.setAdvancedCountTotalAIDMap(overallTotalAIDMap); // eLink request for summary aids related to not ChEMBL aids String linkNeighbor = "pcassay_pcassay_neighbor_list"; log.info("Number of ChEMBL AIDs: " + overall.getAdvancedCountTotalAIDMap().get(PCPromiscuityFactory.chemblName).size()); List<Long> notChEMBLAIDs = (List<Long>) CollectionUtils.subtract(overall.getAllAIDs(), overall.getAdvancedCountTotalAIDMap().get(PCPromiscuityFactory.chemblName)); session = ELinkWebSession.newInstance("pcassay", "pcassay", Arrays.asList(new String[] { linkNeighbor }), notChEMBLAIDs, "summary[activityoutcomemethod]"); log.info("Number of ids in link request: " + String.valueOf(notChEMBLAIDs.size())); session.run(); overall.setAllSummaries(session.getAllIds(linkNeighbor)); overall.setSummaryProteinMap( overallFactory.getAIDProteinMap(new ArrayList<Long>(overall.getAllSummaries()))); Map<Long, List<ELinkResult>> aidToSummaryMap = session.getELinkResultsAsMap(); overall.setSummaryToAIDsMap(overallFactory.getSummaryToAIDsMap(aidToSummaryMap)); overall.setMlpSummaries( overallFactory.aidtoAIDListEsearch(new ArrayList<Long>(overall.getAllSummaries()), searchTerms[0])); }