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.redhat.rhn.frontend.taglibs.list.helper.ListRhnSetHelper.java
/** {@inheritDoc} */ public Collection getRemovedKeys() { Set setValues = set.getElementValues(); Set preSelectedValues = getPreSelected(); Collection result = CollectionUtils.subtract(preSelectedValues, setValues); return result; }
From source file:gov.nih.nci.caarray.web.action.CollaboratorsAction.java
/** * Adds the selected users to the current collaborator group. * @return success/*www . j a v a2 s . c om*/ * @throws CSTransactionException on CSM error * @throws CSObjectNotFoundException on CSM error */ @SuppressWarnings({ "unchecked", "PMD" }) @SkipValidation public String addUsers() throws CSTransactionException, CSObjectNotFoundException { if (getUsers() != null && !getUsers().isEmpty()) { ServiceLocatorFactory.getPermissionsManagementService().addUsers(getTargetGroup(), getUsers()); String s = "Users"; if (getUsers().size() == 1) { User u = SecurityUtils.getAuthorizationManager().getUserById(getUsers().get(0).toString()); s = u.getFirstName() + " " + u.getLastName() + " (" + u.getLoginName() + ")"; } ActionHelper.saveMessage(getText("collaboration.group.added", new String[] { s })); } setAllUsers((List<User>) CollectionUtils.subtract( ServiceLocatorFactory.getPermissionsManagementService().getUsers(getTargetUser()), getTargetGroup().getGroup().getUsers())); return Action.SUCCESS; }
From source file:net.sourceforge.fenixedu.domain.student.importation.ExportExistingStudentsFromImportationProcess.java
public static List<ExportExistingStudentsFromImportationProcess> readUndoneJobs( final ExecutionYear executionYear) { return new ArrayList( CollectionUtils.subtract(executionYear.getDgesBaseProcessSet(), readDoneJobs(executionYear))); }
From source file:com.rubenlaguna.en4j.mainmodule.NoteListTopComponent.java
private RepeatableTask createUpdateAllNotesTask() { Runnable runnable = new Runnable() { @Override/*from w ww.j av a 2 s . c om*/ @SuppressWarnings(value = "SleepWhileHoldingLock") public void run() { updateAllNotes(); NoteListTopComponent.this.refresh(); } private void updateAllNotes() { final Collection<Note> allNotesInDb = getAllNotesInDb(); LOG.info("clear and repopulate allNotes list"); final Collection<Note> toRemove = CollectionUtils.subtract(allNotes, allNotesInDb); final Collection<Note> toAdd = CollectionUtils.subtract(allNotesInDb, allNotes); long startLockList = System.currentTimeMillis(); //allNotes.getReadWriteLock().writeLock().lock(); try { // avoid removeAll as it would block allNotes for too long CollectionUtils.forAllDo(toRemove, new Closure() { @Override @SuppressWarnings("element-type-mismatch") public void execute(Object input) { allNotes.remove(input); } }); //avoid allNotes.addAll it could block allNotes for too long CollectionUtils.addAll(allNotes, toAdd.iterator()); } finally { //allNotes.getReadWriteLock().writeLock().unlock(); } long deltaListLock = System.currentTimeMillis() - startLockList; LOG.log(Level.INFO, "We locked the eventlist for {0} ms", deltaListLock); LOG.log(Level.INFO, "allNotes size: {0} allNotesInDb size: {1}", new Object[] { allNotes.size(), allNotesInDb.size() }); } }; return new RepeatableTask(runnable, 4000); }
From source file:net.sourceforge.fenixedu.domain.student.importation.ExportDegreeCandidaciesByDegreeForPasswordGeneration.java
public static List<ExportDegreeCandidaciesByDegreeForPasswordGeneration> readUndoneJobs( final ExecutionYear executionYear) { return new ArrayList(CollectionUtils.subtract(readAllJobs(executionYear), readDoneJobs(executionYear))); }
From source file:com.dianping.lion.service.impl.EnvironmentServiceImpl.java
/** * @param environments// www.ja v a 2 s.c om */ @SuppressWarnings("unchecked") private void refreshRegisterServiceRepository(List<Environment> environments) { Set<Integer> allEnvIds = new HashSet<Integer>(environments.size()); for (Environment env : environments) { allEnvIds.add(env.getId()); ConfigRegisterService registerService = registerServiceRepository.getRegisterService(env.getId()); if (registerService != null && !StringUtils.equals(registerService.getAddresses(), env.getIps())) { registerServiceRepository.removeRegisterService(env.getId()); } } Set<Integer> registeredEnvironments = registerServiceRepository.getRegisteredEnvironments(); Collection<Integer> needRemovedEnvIds = CollectionUtils.subtract(registeredEnvironments, allEnvIds); for (Integer needRemovedEnvId : needRemovedEnvIds) { registerServiceRepository.removeRegisterService(needRemovedEnvId); } }
From source file:net.sourceforge.atunes.kernel.modules.playlist.DynamicPlayList.java
/** * Replaces content//from w ww . j a v a2 s.c o m * * @param content */ @SuppressWarnings("unchecked") protected void replaceContent(final Collection<IAudioObject> content, final IAudioObjectComparator comparator, final IBeanFactory beanFactory) { if (this.audioObjects == null) { this.audioObjects = new PointedList<IAudioObject>(); this.audioObjects.addAll(0, content); notifyAudioObjectsAdded(0, content); } else { Collection<IAudioObject> toRemove = CollectionUtils.subtract(this.audioObjects.getList(), content); Collection<IAudioObject> toAdd = CollectionUtils.subtract(content, this.audioObjects.getList()); remove(toRemove); this.audioObjects.addAll(this.audioObjects.size(), toAdd); notifyAudioObjectsAdded(this.audioObjects.size(), toAdd); } if (this.columnSorted != null) { IColumn<?> column = beanFactory.getBeanByClassName(this.columnSorted, IColumn.class); if (column != null) { sortByColumn(column); } else { this.audioObjects.sort(comparator); } } else { this.audioObjects.sort(comparator); } }
From source file:edu.internet2.middleware.changelogconsumer.googleapps.GoogleAppsFullSync.java
/** * Runs a fullSync./* w ww .j av a 2s .co m*/ * @param dryRun indicates that this is dryRun */ public void process(boolean dryRun) { synchronized (fullSyncIsRunningLock) { fullSyncIsRunning.put(consumerName, Boolean.toString(true)); } connector = new GoogleGrouperConnector(); //Start with a clean cache GoogleCacheManager.googleGroups().clear(); GoogleCacheManager.googleGroups().clear(); properties = new GoogleAppsSyncProperties(consumerName); Pattern googleGroupFilter = Pattern.compile(properties.getGoogleGroupFilter()); try { connector.initialize(consumerName, properties); if (properties.getprefillGoogleCachesForFullSync()) { connector.populateGoogleCache(); } } catch (GeneralSecurityException e) { LOG.error("Google Apps Consume '{}' Full Sync - This consumer failed to initialize: {}", consumerName, e.getMessage()); } catch (IOException e) { LOG.error("Google Apps Consume '{}' Full Sync - This consumer failed to initialize: {}", consumerName, e.getMessage()); } GrouperSession grouperSession = null; try { grouperSession = GrouperSession.startRootSession(); connector.getGoogleSyncAttribute(); connector.cacheSyncedGroupsAndStems(true); // time context processing final StopWatch stopWatch = new StopWatch(); stopWatch.start(); //Populate a normalized list (google naming) of Grouper groups ArrayList<ComparableGroupItem> grouperGroups = new ArrayList<ComparableGroupItem>(); for (String groupKey : connector.getSyncedGroupsAndStems().keySet()) { if (connector.getSyncedGroupsAndStems().get(groupKey).equalsIgnoreCase("yes")) { edu.internet2.middleware.grouper.Group group = connector.fetchGrouperGroup(groupKey); if (group != null) { grouperGroups.add(new ComparableGroupItem( connector.getAddressFormatter().qualifyGroupAddress(group.getName()), group)); } } } //Populate a comparable list of Google groups ArrayList<ComparableGroupItem> googleGroups = new ArrayList<ComparableGroupItem>(); for (String groupName : GoogleCacheManager.googleGroups().getKeySet()) { if (googleGroupFilter.matcher(groupName.replace("@" + properties.getGoogleDomain(), "")).find()) { googleGroups.add(new ComparableGroupItem(groupName)); LOG.debug("Google Apps Consumer '{}' Full Sync - {} group matches group filter: included", consumerName, groupName); } else { LOG.debug("Google Apps Consumer '{}' Full Sync - {} group does not match group filter: ignored", consumerName, groupName); } } //Get our sets Collection<ComparableGroupItem> extraGroups = CollectionUtils.subtract(googleGroups, grouperGroups); processExtraGroups(dryRun, extraGroups); Collection<ComparableGroupItem> missingGroups = CollectionUtils.subtract(grouperGroups, googleGroups); processMissingGroups(dryRun, missingGroups); Collection<ComparableGroupItem> matchedGroups = CollectionUtils.intersection(grouperGroups, googleGroups); processMatchedGroups(dryRun, matchedGroups); // stop the timer and log stopWatch.stop(); LOG.debug("Google Apps Consumer '{}' Full Sync - Processed, Elapsed time {}", new Object[] { consumerName, stopWatch }); } finally { GrouperSession.stopQuietly(grouperSession); synchronized (fullSyncIsRunningLock) { fullSyncIsRunning.put(consumerName, Boolean.toString(true)); } } }
From source file:com.silverwrist.dynamo.security.AclObject.java
public Enumeration getPermissions(Principal user) { PrincipalID prid = new PrincipalID(user); Collection rc = null;//from ww w . ja v a2 s . c o m try { // is this for a user or a group? if (prid.isGroup()) { // compute permissions only for the group itself // (everything that appears in positive set but not in negative set) Set positive = m_ops.getGroupPermissionSetForGroup(m_aclid, prid.getID(), false); Set negative = m_ops.getGroupPermissionSetForGroup(m_aclid, prid.getID(), true); rc = CollectionUtils.subtract(positive, negative); } // end if else { // compute permissions for the user and for all groups of which the user is a member Set pos_group = m_ops.getGroupPermissionSetForUser(m_aclid, prid.getID(), false); Set neg_group = m_ops.getGroupPermissionSetForUser(m_aclid, prid.getID(), true); Set pos_user = m_ops.getUserPermissionSet(m_aclid, prid.getID(), false); Set neg_user = m_ops.getUserPermissionSet(m_aclid, prid.getID(), true); // "Real" groups have been normalized by removing all elements present in the corresponding // "other" group as well Collection real_pos_group = CollectionUtils.subtract(pos_group, neg_group); Collection real_neg_group = CollectionUtils.subtract(neg_group, pos_group); Collection real_pos_user = CollectionUtils.subtract(pos_user, neg_user); Collection real_neg_user = CollectionUtils.subtract(neg_user, pos_user); // "grant_group" = all permissions granted by the groups and not explicitly denied by user Collection grant_group = CollectionUtils.subtract(real_pos_group, real_neg_user); // "deny_group" = all permissions denied by the groups and not explicitly granted by user Collection deny_group = CollectionUtils.subtract(real_neg_group, real_pos_user); // "grant" - all grants from user plus all surviving grants from groups Collection grant = CollectionUtils.union(real_pos_user, grant_group); // "deny" - all denies from user plus all surviving denies from groups Collection deny = CollectionUtils.union(real_neg_user, deny_group); rc = CollectionUtils.subtract(grant, deny); } // end else } // end try catch (DatabaseException e) { // translate this into a SecurityRuntimeException throw new SecurityRuntimeException(e); } // end catch // Compute the proper return value. if (rc.isEmpty()) return Collections.enumeration(Collections.EMPTY_LIST); ArrayList real_rc = new ArrayList(rc.size()); Iterator it = rc.iterator(); while (it.hasNext()) { // transform PropertyKey values into PermObjects PropertyKey pk = (PropertyKey) (it.next()); real_rc.add(new PermObject(pk, m_ns_cache)); } // end while return Collections.enumeration(real_rc); }
From source file:net.sourceforge.fenixedu.domain.accounting.events.export.SIBSOutgoingPaymentFile.java
private void invalidateOldPaymentCodes(SibsOutgoingPaymentFile sibsOutgoingPaymentFile, StringBuilder errorsBuilder) { SIBSOutgoingPaymentFile previous = readPreviousOfLastGeneratedPaymentFile(); PrintedPaymentCodes currentSet = this.getPrintedPaymentCodes(); PrintedPaymentCodes previousSet = previous == null ? null : previous.getPrintedPaymentCodes(); if (previousSet != null && previousSet.getPaymentCodes() != null) { Collection<String> oldPaymentCodes = CollectionUtils.subtract(previousSet.getPaymentCodes(), currentSet.getPaymentCodes()); for (String oldCode : oldPaymentCodes) { sibsOutgoingPaymentFile.addLine(oldCode, new Money("0.01"), new Money("0.01"), new DateTime().minusDays(5).toYearMonthDay(), new DateTime().minusDays(5).toYearMonthDay()); }/*from ww w . j a v a 2s .c o m*/ } }