List of usage examples for java.util Collection removeAll
boolean removeAll(Collection<?> c);
From source file:com.garethahealy.camel.file.loadbalancer.example1.routes.Read99FilesWithThreeReadersTest.java
@Test public void readThreeFilesWithThreeReaders() throws InterruptedException, MalformedURLException { Map<String, String> answer = getRouteToEndpointPriority(); //Used for debugging purposes, in-case we need to know which endpoint has what priority LOG.info("EndpointSetup: " + answer.toString()); MockEndpoint first = getMockEndpoint("mock:endFirst"); first.setExpectedMessageCount(33);//from www . ja va2 s .c o m first.setResultWaitTime(TimeUnit.SECONDS.toMillis(15)); first.setAssertPeriod(TimeUnit.SECONDS.toMillis(1)); MockEndpoint second = getMockEndpoint("mock:endSecond"); second.setExpectedMessageCount(33); second.setResultWaitTime(TimeUnit.SECONDS.toMillis(15)); second.setAssertPeriod(TimeUnit.SECONDS.toMillis(1)); MockEndpoint third = getMockEndpoint("mock:endThird"); third.setExpectedMessageCount(33); third.setResultWaitTime(TimeUnit.SECONDS.toMillis(15)); third.setAssertPeriod(TimeUnit.SECONDS.toMillis(1)); //Wait for the files to be processed sleep(30); File firstDirectory = FileUtils.toFile(new URL("file:" + rootDirectory + "/.camel0")); File secondDirectory = FileUtils.toFile(new URL("file:" + rootDirectory + "/.camel1")); File thirdDirectory = FileUtils.toFile(new URL("file:" + rootDirectory + "/.camel2")); Assert.assertTrue(".camel0 doesnt exist", firstDirectory.exists()); Assert.assertTrue(".camel1 doesnt exist", secondDirectory.exists()); Assert.assertTrue(".camel2 doesnt exist", thirdDirectory.exists()); Collection<File> firstFiles = FileUtils.listFiles(firstDirectory, FileFilterUtils.fileFileFilter(), null); Collection<File> secondFiles = FileUtils.listFiles(secondDirectory, FileFilterUtils.fileFileFilter(), null); Collection<File> thirdFiles = FileUtils.listFiles(thirdDirectory, FileFilterUtils.fileFileFilter(), null); Assert.assertNotNull(firstFiles); Assert.assertNotNull(secondFiles); Assert.assertNotNull(thirdFiles); //Check the files are unique, and we haven't copied the same file twice int firstSize = firstFiles.size(); int secondSize = secondFiles.size(); int thirdSize = thirdFiles.size(); firstFiles.removeAll(secondFiles); firstFiles.removeAll(thirdFiles); secondFiles.removeAll(firstFiles); secondFiles.removeAll(thirdFiles); thirdFiles.removeAll(firstFiles); thirdFiles.removeAll(secondFiles); //If these numbers don't match, we duplicated a file Assert.assertEquals("duplicate copy in .camel0", new Integer(firstSize), new Integer(firstFiles.size())); Assert.assertEquals("duplicate copy in .camel1", new Integer(secondSize), new Integer(secondFiles.size())); Assert.assertEquals("duplicate copy in .camel2", new Integer(thirdSize), new Integer(thirdFiles.size())); //Check the expected copied amount is correct Assert.assertEquals(new Integer(33), new Integer(firstFiles.size())); Assert.assertEquals(new Integer(33), new Integer(secondFiles.size())); Assert.assertEquals(new Integer(33), new Integer(thirdFiles.size())); Assert.assertEquals(new Integer(99), new Integer(firstFiles.size() + secondFiles.size() + thirdFiles.size())); //Assert the endpoints last, as there seems to be a strange bug where they fail but the files have been processed, //so that would suggest the MockEndpoints are reporting a false-positive first.assertIsSatisfied(); second.assertIsSatisfied(); third.assertIsSatisfied(); }
From source file:forge.game.mana.ManaPool.java
public final List<Mana> clearPool(boolean isEndOfPhase) { // isEndOfPhase parameter: true = end of phase, false = mana drain effect List<Mana> cleared = new ArrayList<Mana>(); if (floatingMana.isEmpty()) { return cleared; }/*from w ww .ja v a 2 s . c o m*/ if (isEndOfPhase && owner.getGame().getStaticEffects().getGlobalRuleChange(GlobalRuleChange.manapoolsDontEmpty)) { return cleared; } final boolean convertToColorless = owner.hasKeyword("Convert unused mana to Colorless"); final List<Byte> keys = Lists.newArrayList(floatingMana.keySet()); if (isEndOfPhase) { for (final Byte c : Lists.newArrayList(keys)) { final String captName = StringUtils.capitalize(MagicColor.toLongString(c)); if (owner.hasKeyword( captName + " mana doesn't empty from your mana pool as steps and phases end.")) { keys.remove(c); } } } if (convertToColorless) { keys.remove(Byte.valueOf(MagicColor.COLORLESS)); } for (Byte b : keys) { Collection<Mana> cm = floatingMana.get(b); if (isEndOfPhase && !owner.getGame().getPhaseHandler().is(PhaseType.CLEANUP)) { final List<Mana> pMana = new ArrayList<Mana>(); for (final Mana mana : cm) { if (mana.getManaAbility() != null && mana.getManaAbility().isPersistentMana()) { pMana.add(mana); } } cm.removeAll(pMana); if (convertToColorless) { convertManaColor(b, MagicColor.COLORLESS); cm.addAll(pMana); } else { cleared.addAll(cm); cm.clear(); floatingMana.putAll(b, pMana); } } else { if (convertToColorless) { convertManaColor(b, MagicColor.COLORLESS); } else { cleared.addAll(cm); cm.clear(); } } } owner.updateManaForView(); owner.getGame().fireEvent(new GameEventManaPool(owner, EventValueChangeType.Cleared, null)); return cleared; }
From source file:co.turnus.analysis.buffers.util.AbstractTraceCutScheduler.java
private final void removeFiredUnconnectedSteps(Collection<Step> ancestors) { Set<Step> removables = Sets.newHashSet(); for (Step step : ancestors) { if (step.getAttribute(STEP_FIRED, false)) { boolean alive = false; for (Dependency outgoing : step.getOutgoings()) { Step target = outgoing.getTarget(); if (!target.getAttribute(STEP_FIRED, false)) { alive = true;//w ww. j a va2s . c om break; } } if (!alive) { removables.add(step); } } } ancestors.removeAll(removables); }
From source file:org.wso2.carbon.identity.application.authentication.framework.handler.provisioning.impl.DefaultProvisioningHandler.java
@Override public void handle(List<String> roles, String subject, Map<String, String> attributes, String provisioningUserStoreId, String tenantDomain) throws FrameworkException { RegistryService registryService = FrameworkServiceComponent.getRegistryService(); RealmService realmService = FrameworkServiceComponent.getRealmService(); try {/* ww w. j a v a2 s.c o m*/ int tenantId = realmService.getTenantManager().getTenantId(tenantDomain); UserRealm realm = AnonymousSessionUtil.getRealmByTenantDomain(registryService, realmService, tenantDomain); String userStoreDomain = getUserStoreDomain(provisioningUserStoreId, realm); String username = MultitenantUtils.getTenantAwareUsername(subject); UserStoreManager userStoreManager = getUserStoreManager(realm, userStoreDomain); // Remove userStoreManager domain from username if the userStoreDomain is not primary if (realm.getUserStoreManager().getRealmConfiguration().isPrimary()) { username = UserCoreUtil.removeDomainFromName(username); } String[] newRoles = new String[] {}; if (roles != null) { roles = removeDomainFromNamesExcludeInternal(roles); newRoles = roles.toArray(new String[roles.size()]); } if (log.isDebugEnabled()) { log.debug("User " + username + " contains roles : " + Arrays.toString(newRoles) + " going to be provisioned"); } // addingRoles = newRoles AND allExistingRoles Collection<String> addingRoles = getRolesToAdd(userStoreManager, newRoles); Map<String, String> userClaims = prepareClaimMappings(attributes); if (userStoreManager.isExistingUser(username)) { if (roles != null && !roles.isEmpty()) { // Update user Collection<String> currentRolesList = Arrays .asList(userStoreManager.getRoleListOfUser(username)); // addingRoles = (newRoles AND existingRoles) - currentRolesList) addingRoles.removeAll(currentRolesList); Collection<String> deletingRoles = new ArrayList<String>(); deletingRoles.addAll(currentRolesList); // deletingRoles = currentRolesList - newRoles deletingRoles.removeAll(Arrays.asList(newRoles)); // Exclude Internal/everyonerole from deleting role since its cannot be deleted deletingRoles.remove(realm.getRealmConfiguration().getEveryOneRoleName()); // TODO : Does it need to check this? // Check for case whether superadmin login handleFederatedUserNameEqualsToSuperAdminUserName(realm, username, userStoreManager, deletingRoles); updateUserWithNewRoleSet(username, userStoreManager, newRoles, addingRoles, deletingRoles); } if (!userClaims.isEmpty()) { userStoreManager.setUserClaimValues(username, userClaims, null); } } else { userStoreManager.addUser(username, generatePassword(), addingRoles.toArray(new String[addingRoles.size()]), userClaims, null); if (log.isDebugEnabled()) { log.debug("Federated user: " + username + " is provisioned by authentication framework with roles : " + Arrays.toString(addingRoles.toArray(new String[addingRoles.size()]))); } } PermissionUpdateUtil.updatePermissionTree(tenantId); } catch (org.wso2.carbon.user.api.UserStoreException | CarbonException e) { throw new FrameworkException("Error while provisioning user : " + subject, e); } }
From source file:org.malaguna.cmdit.service.reflection.ReflectionUtils.java
@SuppressWarnings({ "unchecked", "rawtypes" }) private void updateOldValue(Object oldObj, PropertyDescriptor desc, Object oldValue, Object newValue) { if (Collection.class.isAssignableFrom(desc.getPropertyType())) { Collection oldSetAux = (Collection) oldValue; Collection newSetAux = (Collection) newValue; if (oldSetAux == null) { setNewValue(oldObj, desc.getWriteMethod(), newSetAux); } else {/* w w w .j a v a 2s.co m*/ //oldSetAux.clear(); if (newSetAux != null) { Collection<?> intersection = CollectionUtils.intersection(oldSetAux, newSetAux); Collection<?> nuevos = CollectionUtils.removeAll(newSetAux, intersection); Collection<?> borrados = CollectionUtils.removeAll(oldSetAux, intersection); oldSetAux.removeAll(borrados); oldSetAux.addAll(nuevos); } } } else { setNewValue(oldObj, desc.getWriteMethod(), newValue); } }
From source file:com.haulmont.cuba.web.toolkit.ui.CubaTable.java
@Override public Collection<?> getSortableContainerPropertyIds() { Collection<?> ids = new ArrayList<>(super.getSortableContainerPropertyIds()); if (nonSortableProperties != null) { ids.removeAll(nonSortableProperties); }/*from w w w . ja va2 s . c o m*/ return ids; }
From source file:com.clematis.jsmodify.JSExecutionTracer.java
/** * This method parses the JSON file containing the trace objects and extracts the objects *//*from www .ja v a 2 s . co m*/ public static void extraxtTraceObjects() { try { ObjectMapper mapper = new ObjectMapper(); // Register the module that serializes the Guava Multimap mapper.registerModule(new GuavaModule()); Multimap<String, TraceObject> traceMap = mapper.<Multimap<String, TraceObject>>readValue( new File("clematis-output/ftrace/function.trace"), new TypeReference<TreeMultimap<String, TraceObject>>() { }); Collection<TraceObject> timingTraces = traceMap.get("TimingTrace"); Collection<TraceObject> domEventTraces = traceMap.get("DOMEventTrace"); Collection<TraceObject> XHRTraces = traceMap.get("XHRTrace"); Collection<TraceObject> functionTraces = traceMap.get("FunctionTrace"); Iterator<TraceObject> it3 = domEventTraces.iterator(); TraceObject next2; ArrayList<TraceObject> removeus = new ArrayList<TraceObject>(); /** while (it3.hasNext()) { next2 = it3.next(); if (next2 instanceof DOMEventTrace && (((DOMEventTrace) next2).getEventType().equals("mouseover") || (((DOMEventTrace) next2).getEventType().equals("mousemove")) || (((DOMEventTrace) next2).getEventType().equals("mouseout")) || (((DOMEventTrace) next2).getEventType().equals("mousedown")) || (((DOMEventTrace) next2).getEventType().equals("mouseup")))) { removeus.add(next2); } }*/ domEventTraces.removeAll(removeus); story = new Story(domEventTraces, functionTraces, timingTraces, XHRTraces); story.setOrderedTraceList(sortTraceObjects()); System.out.println(timingTraces.size()); Iterator<TraceObject> it = timingTraces.iterator(); TraceObject next; while (it.hasNext()) { next = it.next(); System.out.println("======="); System.out.println(next.getCounter()); } /* * ArrayList<TraceObject> bookmarkTraceObjects = new ArrayList<TraceObject>(); for * (TraceObject to : story.getOrderedTraceList()) { if (to instanceof DOMEventTrace) { * if (((DOMEventTrace)to).getEventType().equals("_BOOKMARK_")) { * bookmarkTraceObjects.add(to); * System.out.println("&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&"); } } } */ story.setEpisodes(buildEpisodes()); ArrayList<Episode> ss = story.getEpisodes(); Iterator<Episode> it2 = ss.iterator(); System.out.println("hhhmmm"); while (it2.hasNext()) { System.out.println("--------"); System.out.println(it2.next().getSource().getClass()); } System.out.println("# of trace objects: " + story.getOrderedTraceList().size()); System.out.println("# of episodes: " + story.getEpisodes().size()); /* * for (int i = 0; i < story.getEpisodes().size(); i ++) { Episode episode = * story.getEpisodes().get(i); if (episode.getSource() instanceof DOMEventTrace) { * DOMEventTrace source = (DOMEventTrace)episode.getSource(); * if(source.getTargetElement().contains("bookmarkButton")) { * System.out.println("***********"); if (i + 1 < story.getEpisodes().size()) { * story.getEpisodes().get(i).getSource().setIsBookmarked(true); // move isbookmarked to * episode System.out.println("* " + story.getEpisodes().get(i).getSource().toString()); * } } } } */ /* * for (int i = 0; i < story.getEpisodes().size(); i ++) { Episode episode = * story.getEpisodes().get(i); ArrayList<TraceObject> bookmarkObjects = new * ArrayList<TraceObject>(); for (int j = 0; j < episode.getTrace().getTrace().size(); j * ++) { if (episode.getTrace().getTrace().get(j) instanceof DOMEventTrace) { * DOMEventTrace domEventTrace = (DOMEventTrace)episode.getTrace().getTrace().get(j); if * (domEventTrace.getEventType().equals("_BOOKMARK_")) { * bookmarkObjects.add(domEventTrace); System.out.println("bookmark"); if (i + 1 < * story.getEpisodes().size()) { story.getEpisodes().get(i + * 1).getSource().setIsBookmarked(true); } } } } * episode.getTrace().getTrace().removeAll(bookmarkObjects); } for (Episode e : * story.getEpisodes()) { boolean bookmarkNextEpisode = false; // if * (e.getSource().getIsBookmarked()) System.out.println("============ " + * e.getSource().getIsBookmarked()); for (TraceObject to : e.getTrace().getTrace()) { if * (to instanceof DOMEventTrace) { if * (((DOMEventTrace)to).getEventType().equals("_BOOKMARK_")) * System.out.println("bookmark"); } } } */ /* * for (Episode episode : story.getEpisodes()) { if (episode.getSource() instanceof * DOMEventTrace) { if * (((DOMEventTrace)episode.getSource()).getTargetElement().contains("bookmarkButton")) * { System.out.print("**** " + ((DOMEventTrace)episode.getSource()).getEventType() + * " * "); } System.out.println("---- " + * ((DOMEventTrace)episode.getSource()).getTargetElement()); } } */// TODO TODO TODO project specific for photo gallery. eliminate unwanted episodes story.removeUselessEpisodes(); ss = story.getEpisodes(); it2 = ss.iterator(); System.out.println("hhhmmm2"); while (it2.hasNext()) { System.out.println("--------"); System.out.println(it2.next().getSource().getClass()); } ArrayList<Episode> bookmarkEpisodes = new ArrayList<Episode>(); for (int i = 0; i < story.getEpisodes().size(); i++) { Episode episode = story.getEpisodes().get(i); if (episode.getSource() instanceof DOMEventTrace) { DOMEventTrace source = (DOMEventTrace) episode.getSource(); if (source.getTargetElement().contains("bookmarkButton")) { bookmarkEpisodes.add(episode); if (i + 1 < story.getEpisodes().size()) { story.getEpisodes().get(i + 1).setIsBookmarked(true); // story.getEpisodes().get(i).getSource().setIsBookmarked(true); // move // isbookmarked to episode System.out.println("* episode # " + (i + 1) + " bookmarked"); } } } } story.removeUselessEpisodes(bookmarkEpisodes); // story.removeToolbarEpisodes(); System.out.println("# of episodes after trimming: " + story.getEpisodes().size()); DateFormat dateFormat = new SimpleDateFormat("EEE,d,MMM,HH-mm"); Date date = new Date(); System.out.println(dateFormat.format(date)); // dateFormat.format(date).toString() theTime = new String(dateFormat.format(date).toString()); System.out.println(theTime); // JavaScript episodes for JSUML2 Helper.directoryCheck(outputFolder + "/sequence_diagrams/"); PrintStream JSepisodes = new PrintStream(outputFolder + "/sequence_diagrams/allEpisodes.js"); for (Episode e : story.getEpisodes()) { // Create pic files for each episode's sequence diagram designSequenceDiagram(e, JSepisodes); } // Once all episodes have been saved to JS file, close JSepisodes.close(); // Create graph containing all episodes with embedded sequence diagrams EpisodeGraph eg = new EpisodeGraph(getOutputFolder(), story.getEpisodes()); eg.createGraph(); writeStoryToDisk(); } catch (Exception e) { e.printStackTrace(); } }
From source file:org.codehaus.mojo.truezip.internal.TrueZipFileSetManager.java
private Set findDeletableFiles(TrueZipFileSet fileSet, Set deletableDirectories) { TrueZipDirectoryScanner scanner = scan(fileSet); if (scanner == null) { return deletableDirectories; }// w w w . jav a 2 s . c o m Set includes = deletableDirectories; includes.addAll(Arrays.asList(scanner.getIncludedFiles())); Collection excludes = new ArrayList(Arrays.asList(scanner.getExcludedFiles())); Collection linksForDeletion = new ArrayList(); if (!fileSet.isFollowSymlinks()) { // we need to see which entries were only excluded because they're symlinks... scanner.setFollowSymlinks(true); scanner.scan(); List includedFilesAndSymlinks = Arrays.asList(scanner.getIncludedFiles()); linksForDeletion.addAll(excludes); linksForDeletion.retainAll(includedFilesAndSymlinks); excludes.removeAll(includedFilesAndSymlinks); } excludeParentDirectoriesOfExcludedPaths(excludes, includes); includes.addAll(linksForDeletion); return includes; }
From source file:org.codehaus.mojo.truezip.internal.TrueZipFileSetManager.java
private Set findDeletableDirectories(TrueZipFileSet fileSet) { TrueZipDirectoryScanner scanner = scan(fileSet); if (scanner == null) { return Collections.EMPTY_SET; }//from w ww.j ava 2 s .co m Set includes = new HashSet(Arrays.asList(scanner.getIncludedDirectories())); Collection excludes = new ArrayList(Arrays.asList(scanner.getExcludedDirectories())); Collection linksForDeletion = new ArrayList(); if (!fileSet.isFollowSymlinks()) { // we need to see which entries were only excluded because they're symlinks... scanner.setFollowSymlinks(true); scanner.scan(); List includedDirsAndSymlinks = Arrays.asList(scanner.getIncludedDirectories()); linksForDeletion.addAll(excludes); linksForDeletion.retainAll(includedDirsAndSymlinks); excludes.removeAll(includedDirsAndSymlinks); } excludeParentDirectoriesOfExcludedPaths(excludes, includes); includes.addAll(linksForDeletion); return includes; }
From source file:com.surevine.alfresco.esl.impl.webscript.visibility.SharedVisibilityReport.java
protected Collection<String> getUsersWithNoGroups() { if (_logger.isDebugEnabled()) { _logger.debug("Cache expires on " + _allUserNamesNextUpdate); }// w w w . j a v a2s.c om if (new Date().after(_allUserNamesNextUpdate)) { if (_logger.isDebugEnabled()) { _logger.debug("Refreshing users with no groups cache"); } Collection<String> newAllNames = new ArrayList<String>(2000); Iterator<NodeRef> peopleNodes = _personService.getAllPeople().iterator(); while (peopleNodes.hasNext()) { NodeRef nr = peopleNodes.next(); String userName = _nodeService.getProperty(nr, ContentModel.PROP_USERNAME).toString(); if (_logger.isDebugEnabled()) { _logger.debug(" Adding " + userName + " as a user with no groups"); } newAllNames.add(userName); } Collection<String> usersWithAGroup = AuthenticationUtil.runAs(new GetUsersWithAGroupWork(), _allGroupsUser); newAllNames.removeAll(usersWithAGroup); _usersWithNoGroups = newAllNames; _allUserNamesNextUpdate = new Date(new Date().getTime() + MILLIS_IN_HOUR); if (_logger.isDebugEnabled()) { _logger.debug("Users with no groups cache updated"); } } return _usersWithNoGroups; }