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

The following examples show how to use org.apache.commons.collections4.ListUtils#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: UserGroupController.java    From openemm with GNU Affero General Public License v3.0 5 votes vote down vote up
@PostMapping("/save.action")
public String save(ComAdmin admin, UserGroupForm form, Popups popups) throws Exception {
    int userGroupId = form.getId();
    boolean isNew = userGroupId == NEW_USER_GROUP_ID;

    if(!isValid(admin, form, popups)) {
        return "messages";
    }
    
    boolean isAvailableToCreateOrUpdate = isNew ||
            form.getCompanyId() == admin.getCompanyID() ||
            admin.getAdminID() == ROOT_ADMIN_ID;
    
    if (isAvailableToCreateOrUpdate) {
        UserGroupDto oldUserGroup = userGroupService.getUserGroup(admin, userGroupId);

        int savedUsergroupId = userGroupService.saveUserGroup(admin, conversionService.convert(form, UserGroupDto.class));
        if (savedUsergroupId > 0) {
            form.setId(savedUsergroupId);
            
            popups.success("default.changes_saved");
            userActivityLogService.writeUserActivityLog(admin, (isNew ? "create " : "edit ") + "user group", getDescription(form), logger);

            UserGroupDto userGroup = userGroupService.getUserGroup(admin, savedUsergroupId);
            Set<String> savedPermissions = userGroup.getGrantedPermissions();

            Set<String> oldPermissions = oldUserGroup != null ? oldUserGroup.getGrantedPermissions() : Collections.emptySet();
            List<String> removedPermissions = ListUtils.removeAll(oldPermissions, savedPermissions);
            List<String> addedPermissions = ListUtils.removeAll(savedPermissions, oldPermissions);

            writeUserGroupPermissionChangesLog(admin, form, addedPermissions, removedPermissions);
            return "redirect:/administration/usergroup/list.action";
        } else {
            logger.error("Cannot save userGroup with ID: " + userGroupId);
            popups.alert(isNew ? "error.usergroup.save": "error.group.change.permission");
        }
    }

    return "redirect:/administration/usergroup/list.action";
}
 
Example 2
Source File: BasicCruiseConfig.java    From gocd with Apache License 2.0 5 votes vote down vote up
private List<PartialConfig> removePartialsThatDoNotCorrespondToTheCurrentConfigReposList(List<PartialConfig> partList) {
    List<Object> notToBeMerged = new ArrayList<>();
    for (PartialConfig partialConfig : partList) {
        if (partialConfig.getOrigin() instanceof RepoConfigOrigin) {
            RepoConfigOrigin origin = (RepoConfigOrigin) partialConfig.getOrigin();
            if (!configRepos.hasMaterialWithFingerprint(origin.getMaterial().getFingerprint()))
                notToBeMerged.add(partialConfig);
        }
    }
    partList = ListUtils.removeAll(partList, notToBeMerged);
    return partList;
}
 
Example 3
Source File: CreateOrUpdateAppStep.java    From multiapps-controller with Apache License 2.0 4 votes vote down vote up
private void reportNonUpdatedServices(Set<String> services, String applicationName, List<String> updatedServices) {
    List<String> nonUpdatesServices = ListUtils.removeAll(services, updatedServices);
    for (String service : nonUpdatesServices) {
        getStepLogger().warn(Messages.WILL_NOT_REBIND_APP_TO_SERVICE, service, applicationName);
    }
}
 
Example 4
Source File: AddDomainsStepTest.java    From multiapps-controller with Apache License 2.0 4 votes vote down vote up
private List<String> getNonExistingDomainsList() {
    return ListUtils.removeAll(customDomains, existingDomains);
}
 
Example 5
Source File: UserRepository.java    From j360-dubbo-app-all with Apache License 2.0 4 votes vote down vote up
public List<UserDO> findIn(List<Long> ids) {
    try{
        ids = ids.stream().distinct().collect(Collectors.toList());
        ListUtil.sort(ids);
        RBuckets rBuckets = redissonClient.getBuckets(JsonJacksonCodec.INSTANCE);
        Map<String, UserDO> vpMaps = rBuckets.get(ModelUtil.formatStrings(UserKeys.USER_DO_ID, ids));

        List<UserDO> list = Lists.newArrayListWithCapacity(ids.size());
        List<Long> redisIds = Lists.newArrayListWithCapacity(ids.size());
        ids.stream().forEach( id -> {
            String key = String.format(UserKeys.USER_DO_ID, id);
            if (vpMaps.containsKey(key)) {
                UserDO topicDO = vpMaps.get(key);
                if (Objects.nonNull(topicDO)) {
                    list.add(topicDO);
                    redisIds.add(id);

                    //延迟过期
                    redissonClient.getBucket(key,JsonJacksonCodec.INSTANCE)
                            .expire(AppConfig.COMMON_CACHE_DAYS, TimeUnit.MINUTES);
                }
            }
        });

        List<Long> lastIds = ListUtils.removeAll(ids, redisIds);
        if (CollectionUtils.isNotEmpty(lastIds)) {
            List<UserDO> dbList =  list(lastIds);
            if (CollectionUtils.isNotEmpty(dbList)) {
                list.addAll(dbList);

                dbList.stream().forEach(topicDO -> {
                    redissonClient.getBucket(String.format(UserKeys.USER_DO_ID, topicDO.getUid()),JsonJacksonCodec.INSTANCE)
                            .setAsync(topicDO, AppConfig.COMMON_CACHE_DAYS, TimeUnit.MINUTES);
                });
            }
        }

        return list;
    }catch(Throwable th){
        throw new RepositoryException(ErrorCode.DB_ERROR.getErrorCode(),ErrorCode.DB_ERROR.getErrorMsg(),th);
    }
}
 
Example 6
Source File: CollectionsUtil.java    From feilong-core with Apache License 2.0 2 votes vote down vote up
/**
 * 从 <code>objectCollection</code>中删除所有的 <code>removeCollection</code> <span style="color:red">(原集合对象不变)</span>.
 * 
 * <h3>说明:</h3>
 * <blockquote>
 * <ol>
 * <li>返回剩余的集合 <span style="color:red">(原集合对象<code>objectCollection</code>不变)</span>,如果你不想修改 <code>objectCollection</code>的话,不能直接调用
 * <code>collection.removeAll(remove);</code>,这个方法非常有用.</li>
 * <li>底层实现是调用的 {@link ListUtils#removeAll(Collection, Collection)},将不是<code>removeElement</code>的元素加入到新的list返回.</li>
 * </ol>
 * </blockquote>
 * 
 * <h3>示例:</h3>
 * 
 * <blockquote>
 * 
 * <p>
 * <b>场景:</b> 从list中删除 "feilong2","feilong1"元素
 * </p>
 * 
 * <pre class="code">
 * List{@code <String>} list = toList("xinge", "feilong1", "feilong2", "feilong2");
 * List{@code <String>} removeList = CollectionsUtil.removeAll(list, toList("feilong2", "feilong1"));
 * </pre>
 * 
 * <b>返回:</b>
 * 
 * <pre class="code">
 * ["xinge"]
 * </pre>
 * 
 * </blockquote>
 *
 * @param <O>
 *            the generic type
 * @param objectCollection
 *            the collection from which items are removed (in the returned collection)
 * @param removeCollection
 *            the items to be removed from the returned <code>collection</code>
 * @return 从 <code>objectCollection</code>中排除掉 <code>removeCollection</code> 元素的新的 list
 * @throws NullPointerException
 *             如果 <code>objectCollection</code> 是null,或者 <code>removeCollection</code> 是null
 * @see ListUtils#removeAll(Collection, Collection)
 * @since Commons Collections 4
 * @since 1.0.8
 */
public static <O> List<O> removeAll(Collection<O> objectCollection,Collection<O> removeCollection){
    Validate.notNull(objectCollection, "objectCollection can't be null!");
    Validate.notNull(removeCollection, "removeCollection can't be null!");
    return ListUtils.removeAll(objectCollection, removeCollection);
}