Java Code Examples for org.apache.commons.collections4.CollectionUtils#removeAll()

The following examples show how to use org.apache.commons.collections4.CollectionUtils#removeAll() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MailinglistApprovalServiceImpl.java    From openemm with GNU Affero General Public License v3.0 6 votes vote down vote up
@Override
public boolean setDisabledMailinglistForAdmin(@VelocityCheck int companyId, int adminId, Collection<Integer> mailinglistIds){
    if(CollectionUtils.isEmpty(mailinglistIds)){
    	mailinglistApprovalDao.allowAdminToUseAllMailinglists(companyId, adminId);
        return true;
    }

    List<Integer> alreadyDisabledList = mailinglistApprovalDao.getDisabledMailinglistsForAdmin(companyId, adminId);

    if(CollectionUtils.isEmpty(alreadyDisabledList)){
        return mailinglistApprovalDao.disallowAdminToUseMailinglists(companyId, adminId, mailinglistIds);
    }

    Set<Integer> alreadyDisabled = new HashSet<>(alreadyDisabledList);
    Collection<Integer> enableMailinglists = CollectionUtils.removeAll(alreadyDisabled, mailinglistIds);
    Collection<Integer> disableMailingLists = CollectionUtils.removeAll(mailinglistIds, alreadyDisabled);

    mailinglistApprovalDao.allowAdminToUseMailinglists(companyId, adminId, enableMailinglists);
    return mailinglistApprovalDao.disallowAdminToUseMailinglists(companyId, adminId, disableMailingLists);
}
 
Example 2
Source File: MailinglistApprovalServiceImpl.java    From openemm with GNU Affero General Public License v3.0 6 votes vote down vote up
@Override
public boolean setAdminsDisallowedToUseMailinglist(@VelocityCheck int companyId, int mailinglistId, Collection<Integer> adminIds){
    if(CollectionUtils.isEmpty(adminIds)){
    	mailinglistApprovalDao.allowAllAdminsToUseMailinglist(companyId, mailinglistId);
        return true;
    }

    List<Integer> alreadyDisabledList = mailinglistApprovalDao.getAdminsDisallowedToUseMailinglist(companyId, mailinglistId);

    if(CollectionUtils.isEmpty(alreadyDisabledList)){
        return mailinglistApprovalDao.disallowAdminsToUseMailinglist(companyId, mailinglistId, adminIds);
    }

    Set<Integer> alreadyDisabled = new HashSet<>(alreadyDisabledList);
    Collection<Integer> enableUsers = CollectionUtils.removeAll(alreadyDisabled, adminIds);
    Collection<Integer> disableUsers = CollectionUtils.removeAll(adminIds, alreadyDisabled);

    mailinglistApprovalDao.allowAdminsToUseMailinglist(companyId, mailinglistId, enableUsers);
    return mailinglistApprovalDao.disallowAdminsToUseMailinglist(companyId, mailinglistId, disableUsers);
}
 
Example 3
Source File: CollectionCompareTests.java    From java_in_examples with Apache License 2.0 6 votes vote down vote up
private static void testDifference() {
    Collection<String> collection1 = Lists.newArrayList("a2", "a3");
    Collection<String> collection2 = Lists.newArrayList("a8", "a3", "a5");
    Set<String> set1 = Sets.newHashSet("a2", "a3");
    Set<String> set2 = Sets.newHashSet("a8", "a3", "a5");
    MutableSet<String> mutableSet1 = UnifiedSet.newSetWith("a2", "a3");
    MutableSet<String> mutableSet2 = UnifiedSet.newSetWith("a8", "a3", "a5");

    // Find all elements that are contained by one collecion and not contained by another (difference)
    Set<String> jdk = new HashSet<>(set1); // using JDK
    jdk.removeAll(set2);
    Set<String> guava = Sets.difference(set1, set2); // using guava
    Collection<String> apache = CollectionUtils.removeAll(collection1, collection2);  // using Apache
    Set<String> gs = mutableSet1.difference(mutableSet2); // using GS
    System.out.println("difference = " + jdk + ":" + guava + ":" + apache + ":" + gs); // print difference = [a2]:[a2]:[a2]:[a2]
}
 
Example 4
Source File: CollectionCompareTests.java    From java_in_examples with Apache License 2.0 6 votes vote down vote up
private static void testDifference() {
    Collection<String> collection1 = Lists.newArrayList("a2", "a3");
    Collection<String> collection2 = Lists.newArrayList("a8", "a3", "a5");
    Set<String> set1 = Sets.newHashSet("a2", "a3");
    Set<String> set2 = Sets.newHashSet("a8", "a3", "a5");
    MutableSet<String> mutableSet1 = UnifiedSet.newSetWith("a2", "a3");
    MutableSet<String> mutableSet2 = UnifiedSet.newSetWith("a8", "a3", "a5");

    // Найти все элементы, которые есть в одной коллекции и нет в другой (difference)
    Set<String> jdk = new HashSet<>(set1); // c помощью JDK
    jdk.removeAll(set2);
    Set<String> guava = Sets.difference(set1, set2); // с помощью guava
    Collection<String> apache = CollectionUtils.removeAll(collection1, collection2);  // c помощью Apache
    Set<String> gs = mutableSet1.difference(mutableSet2); // c помощью GS
    System.out.println("difference = " + jdk + ":" + guava + ":" + apache + ":" + gs); // напечатает difference = [a2]:[a2]:[a2]:[a2]
}
 
Example 5
Source File: MailinglistApprovalServiceImpl.java    From openemm with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
public Set<Integer> getAdminsAllowedToUseMailinglist(@VelocityCheck int companyId, int mailinglistId){
    List<Integer> adminsDisallowedToUseMailinglist = mailinglistApprovalDao.getAdminsDisallowedToUseMailinglist(companyId, mailinglistId);
    Set<Integer> adminIds= adminService.getAdminsNamesMap(companyId).keySet();
    Collection<Integer> allowed = adminIds;
    if(!adminsDisallowedToUseMailinglist.isEmpty()) {
        allowed = CollectionUtils.removeAll(adminIds, adminsDisallowedToUseMailinglist);
    }
    return new HashSet<>(allowed);
}
 
Example 6
Source File: MailinglistApprovalServiceImpl.java    From openemm with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
public boolean editUsersApprovalPermissions(int companyId, int mailinglistId, Set<Integer> allowedRecipientIds, List<UserAction> userActions) {
    if(mailinglistId == 0) {
        return false;
    }
    
    Collection<Integer> adminForDisallowing = CollectionUtils.removeAll(adminService.getAdminsNamesMap(companyId).keySet(), allowedRecipientIds);
    boolean result = setAdminsDisallowedToUseMailinglist(companyId, mailinglistId, adminForDisallowing);
    if(result) {
        userActions.add(new UserAction("mailing list edit", "Allowed mailing list for admins: " + StringUtils.join(allowedRecipientIds, ", ")));
        userActions.add(new UserAction("mailing list edit", "Disallowed mailing list for admins: " + StringUtils.join(adminForDisallowing, ", ")));
    }
    return result;
}
 
Example 7
Source File: ProgramChecker.java    From nuls-v2 with MIT License 5 votes vote down vote up
public static void checkClass(Map<String, ClassCode> classCodes) {
    Set<String> allClass = allClass(classCodes);
    Set<String> classCodeNames = classCodes.values().stream().map(classCode -> classCode.name).collect(Collectors.toSet());
    Collection<String> classes = CollectionUtils.removeAll(allClass, classCodeNames);
    Collection<String> classes1 = CollectionUtils.removeAll(classes, Arrays.asList(ProgramConstants.SDK_CLASS_NAMES));
    Collection<String> classes2 = CollectionUtils.removeAll(classes1, Arrays.asList(ProgramConstants.CONTRACT_USED_CLASS_NAMES));
    Collection<String> classes3 = CollectionUtils.removeAll(classes2, Arrays.asList(ProgramConstants.CONTRACT_LAZY_USED_CLASS_NAMES));
    if (classes3.size() > 0) {
        throw new RuntimeException(String.format("can't use classes: %s", Joiner.on(", ").join(classes3)));
    }
}
 
Example 8
Source File: ProgramChecker.java    From nuls with MIT License 5 votes vote down vote up
public static void checkClass(Map<String, ClassCode> classCodes) {
    Set<String> allClass = allClass(classCodes);
    Set<String> classCodeNames = classCodes.values().stream().map(classCode -> classCode.name).collect(Collectors.toSet());
    Collection<String> classes = CollectionUtils.removeAll(allClass, classCodeNames);
    Collection<String> classes1 = CollectionUtils.removeAll(classes, Arrays.asList(ProgramConstants.SDK_CLASS_NAMES));
    Collection<String> classes2 = CollectionUtils.removeAll(classes1, Arrays.asList(ProgramConstants.CONTRACT_USED_CLASS_NAMES));
    Collection<String> classes3 = CollectionUtils.removeAll(classes2, Arrays.asList(ProgramConstants.CONTRACT_LAZY_USED_CLASS_NAMES));
    if (classes3.size() > 0) {
        throw new RuntimeException(String.format("can't use classes: %s", Joiner.on(", ").join(classes3)));
    }
}
 
Example 9
Source File: NodeJdbcDAO.java    From phoebus with Eclipse Public License 1.0 5 votes vote down vote up
@Override
@Transactional
public Node updateConfiguration(Node configToUpdate, List<ConfigPv> updatedConfigPvList) {

	Node configNode = getNode(configToUpdate.getUniqueId());

	if(configNode == null || !configNode.getNodeType().equals(NodeType.CONFIGURATION)) {
		throw new IllegalArgumentException(String.format("Config node with unique id=%s not found or is wrong type", configToUpdate.getUniqueId()));
	}

	List<ConfigPv> existingConfigPvList = getConfigPvs(configToUpdate.getUniqueId());

	Collection<ConfigPv> pvsToRemove = CollectionUtils.removeAll(existingConfigPvList,
			updatedConfigPvList);
	Collection<Integer> pvIdsToRemove = CollectionUtils.collect(pvsToRemove, ConfigPv::getId);

	// Remove PVs from relation table
	pvIdsToRemove.stream().forEach(id -> jdbcTemplate.update(
			"delete from config_pv_relation where config_id=? and config_pv_id=?",
			configNode.getId(), id));

	// Check if any of the PVs is orphaned
	deleteOrphanedPVs(pvIdsToRemove);

	Collection<ConfigPv> pvsToAdd = CollectionUtils.removeAll(updatedConfigPvList,
			existingConfigPvList);

	// Add new PVs
	pvsToAdd.stream().forEach(configPv -> saveConfigPv(configNode.getId(), configPv));

	updateProperties(configNode.getId(), configToUpdate.getProperties());

	jdbcTemplate.update("update node set username=?, last_modified=? where id=?",
			configToUpdate.getUserName(), Timestamp.from(Instant.now()), configNode.getId());

	return getNode(configNode.getId());
}
 
Example 10
Source File: DependencyServiceImpl.java    From studio with GNU General Public License v3.0 5 votes vote down vote up
private Set<String> getMandatoryParentsForPublishing(String site, List<String> paths) {
    Set<String> toRet = new HashSet<String>();
    Set<String> possibleParents = calculatePossibleParents(paths);
    if (!possibleParents.isEmpty()) {
        Map<String, Object> params = new HashMap<String, Object>();
        params.put(ItemStateMapper.SITE_PARAM, site);
        params.put(ItemStateMapper.POSSIBLE_PARENTS_PARAM, possibleParents);
        Collection<State> onlyEditStates = CollectionUtils.removeAll(State.CHANGE_SET_STATES, State.NEW_STATES);
        params.put(ItemStateMapper.EDITED_STATES_PARAM, onlyEditStates);
        params.put(ItemStateMapper.NEW_STATES_PARAM, State.NEW_STATES);
        List<String> result = itemStateMapper.getMandatoryParentsForPublishing(params);
        toRet.addAll(result);
    }
    return toRet;
}
 
Example 11
Source File: DependencyServiceImpl.java    From studio with GNU General Public License v3.0 5 votes vote down vote up
private List<Map<String, String>> calculatePublishingDependenciesForListFromDB(String site, Set<String> paths) {
    Map<String, Object> params = new HashMap<String, Object>();
    params.put(SITE_PARAM, site);
    params.put(PATHS_PARAM, paths);
    params.put(REGEX_PARAM, getItemSpecificDependenciesPatterns());
    Collection<State> onlyEditStates = CollectionUtils.removeAll(State.CHANGE_SET_STATES, State.NEW_STATES);
    params.put(EDITED_STATES_PARAM, onlyEditStates);
    params.put(NEW_STATES_PARAM, State.NEW_STATES);
    return dependencyMapper.calculatePublishingDependenciesForList(params);
}
 
Example 12
Source File: DependencyServiceInternalImpl.java    From studio with GNU General Public License v3.0 5 votes vote down vote up
private Set<String> getMandatoryParents(String site, List<String> paths) {
    Set<String> toRet = new HashSet<String>();
    Set<String> possibleParents = calculatePossibleParents(paths);
    if (!possibleParents.isEmpty()) {
        Map<String, Object> params = new HashMap<String, Object>();
        params.put(ItemStateMapper.SITE_PARAM, site);
        params.put(ItemStateMapper.POSSIBLE_PARENTS_PARAM, possibleParents);
        Collection<State> onlyEditStates = CollectionUtils.removeAll(State.CHANGE_SET_STATES, State.NEW_STATES);
        params.put(ItemStateMapper.EDITED_STATES_PARAM, onlyEditStates);
        params.put(ItemStateMapper.NEW_STATES_PARAM, State.NEW_STATES);
        List<String> result = itemStateMapper.getMandatoryParentsForPublishing(params);
        toRet.addAll(result);
    }
    return toRet;
}
 
Example 13
Source File: DependencyServiceInternalImpl.java    From studio with GNU General Public License v3.0 4 votes vote down vote up
private List<Map<String, String>> getSoftDependenciesForListFromDB(String site, Set<String> paths) {
    Collection<State> onlyEditStates = CollectionUtils.removeAll(State.CHANGE_SET_STATES, State.NEW_STATES);
    return dependencyDao.getSoftDependenciesForList(site, paths, getItemSpecificDependenciesPatterns(),
            onlyEditStates);
}
 
Example 14
Source File: DependencyServiceInternalImpl.java    From studio with GNU General Public License v3.0 4 votes vote down vote up
private List<Map<String, String>> calculateHardDependenciesForListFromDB(String site, Set<String> paths) {
    Collection<State> onlyEditStates = CollectionUtils.removeAll(State.CHANGE_SET_STATES, State.NEW_STATES);
    return dependencyDao.getHardDependenciesForList(site, paths, getItemSpecificDependenciesPatterns(),
            onlyEditStates, State.NEW_STATES);
}