Example usage for java.util List removeAll

List of usage examples for java.util List removeAll

Introduction

In this page you can find the example usage for java.util List removeAll.

Prototype

boolean removeAll(Collection<?> c);

Source Link

Document

Removes from this list all of its elements that are contained in the specified collection (optional operation).

Usage

From source file:org.jblogcms.core.post.service.PostServiceImpl.java

@Override
@Transactional/*from www .  j  av a  2 s. c om*/
@PreAuthorize("#post.account.id == principal.id")
public Post editPost(Post post) {
    Post oldPost = postRepository.findPostById(post.getId());

    List<Long> oldPostBlogIds = getBlogsIds(oldPost.getBlogs());
    List<Long> oldPostBlogIdsCheckSimilar = getBlogsIds(oldPost.getBlogs());
    List<Long> blogIds = getBlogsIds(post.getBlogs());

    oldPostBlogIdsCheckSimilar.retainAll(blogIds);
    oldPostBlogIds.removeAll(oldPostBlogIdsCheckSimilar);
    blogIds.removeAll(oldPostBlogIdsCheckSimilar);

    Account account = accountRepository.getOne(post.getAccount().getId());
    post.setAccount(account);
    Post editedPost = postRepository.save(post);

    if (editedPost != null) {
        if (!oldPostBlogIds.isEmpty()) {
            blogRepository.updateNoOfPosts(oldPostBlogIds, NUMBER_OF_POSTS_DECREMENT);
        }
        blogRepository.flush();
        if (!blogIds.isEmpty()) {
            blogRepository.updateNoOfPosts(blogIds, NUMBER_OF_POSTS_INCREMENT);
        }
    }
    return editedPost;
}

From source file:net.certiv.antlr.project.regen.ReGenConfig.java

private boolean delta(Collection<String> names1, Collection<String> names2, LogLevel lvl, String xname,
        String msg) {/*from   www .j a va2  s  .  com*/
    boolean ok = true;
    List<String> d = new ArrayList<String>(names1);
    d.removeAll(names2);
    if (d.size() > 0)
        ok = log(lvl, xname, msg, Strings.toCsv(d));
    return ok;
}

From source file:com.bgh.myopeninvoice.jsf.jsfbeans.UsersBean.java

private void fillDualList() {
    final Iterable<RolesEntity> allRolesEntity = invoiceDAO.getRolesRepository().findAll();
    final Collection<UserRoleEntity> assignedRolesEntity = selectedUsersEntity.getUserRolesByUserId();

    List<RolesEntity> sourceList = new ArrayList<>();
    List<RolesEntity> targetList = new ArrayList<>();

    rolesDualListModel = new DualListModel<>();

    allRolesEntity.forEach(sourceList::add);
    assignedRolesEntity.forEach(r -> targetList.add(r.getRolesByRoleId()));

    sourceList.removeAll(targetList);

    rolesDualListModel.setSource(sourceList);
    rolesDualListModel.setTarget(targetList);
}

From source file:com.squid.kraken.v4.persistence.dao.UserDAO.java

@Override
public void update(AppContext ctx, User userData) {
    User existingUser = DAOFactory.getDAOFactory().getDAO(User.class).readNotNull(ctx, userData.getId());
    if (userData.getPassword() != null) {

        AppContext rootUserContext = ServiceUtils.getInstance().getRootUserContext(ctx.getCustomerId());
        Customer customer = DAOFactory.getDAOFactory().getDAO(Customer.class).readNotNull(rootUserContext,
                ctx.getCustomerPk());/*from  w  ww  .  jav  a 2s .  c o  m*/
        boolean doUpdate = false;
        // check for conditions to update the password
        if ((ctx.getToken() != null) && (ctx.getToken().getType().equals(AccessToken.Type.RESET_PWD))) {
            // the token is a reset pwd token
            doUpdate = true;
        } else if (AccessRightsUtils.getInstance().hasRole(ctx, customer, Role.WRITE)) {
            // the user is an admin
            doUpdate = true;
        } else {
            int index = userData.getPassword().indexOf(" ");
            if (index >= 0) {
                String oldPassword = userData.getPassword().substring(0, index);
                if (ServiceUtils.getInstance().matchPassword(ctx, existingUser, oldPassword)) {
                    // old and new passwords match
                    doUpdate = true;
                }
            } else {
                throw new InvalidCredentialsAPIException(
                        "Sent password string should be '[new-password] [old-password]'", ctx.isNoError());
            }
        }
        if (doUpdate) {
            // update the password
            String newPassword = userData.getPassword().substring(userData.getPassword().indexOf(" ") + 1);
            userData.setPassword(hashPassword(ctx, newPassword));
        } else {
            throw new InvalidCredentialsAPIException("Invalid old password", ctx.isNoError());
        }
    } else {
        // do not update the password
        userData.setPassword(existingUser.getPassword());
    }

    // check for duplicates
    Optional<User> findByEmail = findByEmail(ctx, userData.getEmail());
    if (findByEmail.isPresent()) {
        if (!findByEmail.get().getId().equals(userData.getId())) {
            throw new APIException("Duplicate email", ctx.isNoError(), ApiError.DUPLICATE_EMAIL);
        }
    }
    Optional<User> findByLogin = findByLogin(ctx, userData.getLogin());
    if (findByLogin.isPresent()) {
        if (!findByLogin.get().getId().equals(userData.getId())) {
            throw new APIException("Duplicate login", ctx.isNoError(), ApiError.DUPLICATE_LOGIN);
        }
    }

    // check the access rights
    // prepare neccessary information

    String ctxUserId = ctx.getUser().getId().getUserId();
    String newUserId = userData.getId().getUserId();

    // caller != callee
    if (!ctxUserId.equalsIgnoreCase(newUserId)) {
        // get the customer and its access rights
        Customer customer = DAOFactory.getDAOFactory().getDAO(Customer.class).readNotNull(ctx,
                ctx.getCustomerPk());
        Set<AccessRight> accessRights = customer.getAccessRights();

        // retrieve access rights of the context user and the new user from
        // access rights of customer
        List<RolePriorityMapper> ctxAccessRights = new ArrayList<RolePriorityMapper>();
        List<RolePriorityMapper> newUserAccessRights = new ArrayList<RolePriorityMapper>();
        for (AccessRight ar : accessRights) {
            if ((ar.getUserId() != null) && (ar.getUserId().equals(ctxUserId))) {
                ctxAccessRights.add(new RolePriorityMapper(ar.getRole()));
            }
            if ((ar.getUserId() != null) && (ar.getUserId().equals(newUserId))) {
                newUserAccessRights.add(new RolePriorityMapper(ar.getRole()));
            }
        }

        // compare access right with new user
        RolePriorityMapper ctxHighestRole = getHighestRole(ctxAccessRights);
        RolePriorityMapper newUserHighestRole = getHighestRole(newUserAccessRights);
        if ((newUserHighestRole != null) && (ctxHighestRole != null)) {
            if ((newUserHighestRole.getRole() != Role.OWNER) || (ctxHighestRole.getRole() != Role.OWNER)) {
                if (newUserHighestRole.getPriority() >= ctxHighestRole.getPriority()) {
                    throw new InvalidCredentialsAPIException("Insufficient privileges : caller hasn't "
                            + newUserHighestRole.getRole().name() + " role on " + ctxUserId, ctx.isNoError());
                }
            }
        } else {
            if ((ctxHighestRole != null) && (ctxHighestRole.getRole() != Role.WRITE)
                    && (ctxHighestRole.getRole() != Role.OWNER)) {
                throw new InvalidCredentialsAPIException(
                        "Insufficient privileges : caller hasn't WRITE/OWNER role on" + ctxUserId,
                        ctx.isNoError());
            }
        }
    }

    // check for groups membership update
    if (!userData.getGroups().equals(existingUser.getGroups())) {
        List<String> added = new ArrayList<String>(userData.getGroups());
        added.removeAll(existingUser.getGroups());
        checkUserGroupAccess(ctx, added);
    }
    ds.update(ctx, userData);
}

From source file:de.dhke.projects.cutil.collections.aspect.AspectMapKeySetTest.java

@Test
public void testIteratorRemove() {
    final List<String> testList = new ArrayList<>(Arrays.asList("A", "B", "C", "D"));
    Iterator<String> iter = _keySet.iterator();
    String key = iter.next();/*from w  w w.j  a  v  a2  s  .  com*/
    iter.remove();
    testList.removeAll(_keySet);

    assertEquals(1, testList.size());
    assertTrue(testList.contains(key));

    assertEquals(1, _listener.beforeRemoveEvents.size());
    assertEquals(new DefaultMapEntry<>("A", "1"), _listener.beforeRemoveEvents.get(0).getItem());
    assertEquals(1, _listener.afterRemoveEvents.size());
    assertEquals(new DefaultMapEntry<>("A", "1"), _listener.afterRemoveEvents.get(0).getItem());
}

From source file:com.envision.envservice.service.OrgStructureService.java

/**
 * ?// w  w w  .  j av a2s .  c  om
 */
public List<JSONObject> querySameDepUsers(String userId) throws Exception {
    checkExist(userId);

    List<UserBo> sameDepUsers = userService.queryUsersByDep(sapUserService.queryDepCode(userId));
    sameDepUsers.removeAll(buildUsers(queryEqualLevel(userId)));
    sameDepUsers.removeAll(buildUsers(queryHigherLevel(userId)));
    sameDepUsers.removeAll(buildUsers(queryLowerLevel(userId)));
    sameDepUsers.remove(userService.queryUser(userId));

    UserUtil.sortByName(sameDepUsers);

    return toBos(sameDepUsers, false);
}

From source file:com.gargoylesoftware.htmlunit.javascript.host.PropertiesTest.java

/**
 * Test./*w ww  . j av  a 2  s.  co m*/
 * @throws IOException If an error occurs
 */
@Test
public void test() throws IOException {
    final List<String> realList;
    final List<String> simulatedList;
    final DefaultCategoryDataset dataset;
    final StringBuilder html;
    final MutableInt actualPropertyCount;
    final MutableInt remainingPropertyCount;
    if (browserVersion_ == BrowserVersion.INTERNET_EXPLORER_6) {
        realList = IE6_;
        simulatedList = IE6_SIMULATED_;
        dataset = CATEGORY_DATASET_IE6_;
        html = IE6_HTML_;
        actualPropertyCount = IE6_ACTUAL_PROPERTY_COUNT_;
        remainingPropertyCount = IE6_REMAINING_PROPERTY_COUNT_;
    } else if (browserVersion_ == BrowserVersion.INTERNET_EXPLORER_7) {
        realList = IE7_;
        simulatedList = IE7_SIMULATED_;
        dataset = CATEGORY_DATASET_IE7_;
        html = IE7_HTML_;
        actualPropertyCount = IE7_ACTUAL_PROPERTY_COUNT_;
        remainingPropertyCount = IE7_REMAINING_PROPERTY_COUNT_;
    } else if (browserVersion_ == BrowserVersion.INTERNET_EXPLORER_8) {
        realList = IE8_;
        simulatedList = IE8_SIMULATED_;
        dataset = CATEGORY_DATASET_IE8_;
        html = IE8_HTML_;
        actualPropertyCount = IE8_ACTUAL_PROPERTY_COUNT_;
        remainingPropertyCount = IE8_REMAINING_PROPERTY_COUNT_;
    } else if (browserVersion_ == BrowserVersion.FIREFOX_3) {
        realList = FF3_;
        simulatedList = FF3_SIMULATED_;
        dataset = CATEGORY_DATASET_FF3_;
        html = FF3_HTML_;
        actualPropertyCount = FF3_ACTUAL_PROPERTY_COUNT_;
        remainingPropertyCount = FF3_REMAINING_PROPERTY_COUNT_;
    } else if (browserVersion_ == BrowserVersion.FIREFOX_3_6) {
        realList = FF3_6_;
        simulatedList = FF3_6_SIMULATED_;
        dataset = CATEGORY_DATASET_FF3_6_;
        html = FF3_6_HTML_;
        actualPropertyCount = FF3_6_ACTUAL_PROPERTY_COUNT_;
        remainingPropertyCount = FF3_6_REMAINING_PROPERTY_COUNT_;
    } else {
        fail("Unknown BrowserVersion " + browserVersion_);
        return;
    }

    List<String> realProperties = Arrays.asList(getValueOf(realList, name_).split(","));
    List<String> simulatedProperties = Arrays.asList(getValueOf(simulatedList, name_).split(","));
    if (realProperties.size() == 1 && realProperties.get(0).length() == 0) {
        realProperties = new ArrayList<String>();
    }
    if (simulatedProperties.size() == 1 && simulatedProperties.get(0).length() == 0) {
        simulatedProperties = new ArrayList<String>();
    }
    final List<String> originalRealProperties = new ArrayList<String>(realProperties);
    removeParentheses(realProperties);
    removeParentheses(simulatedProperties);

    final List<String> erroredProperties = new ArrayList<String>(simulatedProperties);
    erroredProperties.removeAll(realProperties);

    final List<String> implementedProperties = new ArrayList<String>(simulatedProperties);
    implementedProperties.retainAll(realProperties);

    dataset.addValue(implementedProperties.size(), "Implemented", name_);
    dataset.addValue(realProperties.size(),
            browserVersion_.getNickname().replace("FF", "Firefox ").replace("IE", "Internet Explorer "), name_);
    dataset.addValue(erroredProperties.size(), "Should not be implemented", name_);

    final List<String> remainingProperties = new ArrayList<String>(realProperties);
    remainingProperties.removeAll(implementedProperties);

    actualPropertyCount.add(realProperties.size());
    remainingPropertyCount.add(remainingProperties.size());

    if (LOG.isDebugEnabled()) {
        LOG.debug(name_ + ':' + browserVersion_.getNickname() + ':' + realProperties);
        LOG.debug("Remaining" + ':' + remainingProperties);
        LOG.debug("Error" + ':' + erroredProperties);
    }

    appendHtml(html, originalRealProperties, simulatedProperties, erroredProperties);
    if (dataset.getColumnCount() == IE7_.size()) {
        saveChart(dataset);
        html.append("<tr><td colspan='3' align='right'><b>Total Implemented: ")
                .append(actualPropertyCount.intValue() - remainingPropertyCount.intValue()).append(" / ")
                .append(actualPropertyCount.intValue()).append("</b></td></tr>");
        html.append("</table>").append('\n').append("<br>").append("Legend:").append("<br>")
                .append("<span style='color: blue'>").append("To be implemented").append("</span>")
                .append("<br>").append("<span style='color: green'>").append("Implemented").append("</span>")
                .append("<br>").append("<span style='color: red'>").append("Should not be implemented")
                .append("</span>").append("</html>");

        FileUtils.writeStringToFile(
                new File(getArtifactsDirectory() + "/properties-" + browserVersion_.getNickname() + ".html"),
                html.toString());
    }
}

From source file:net.seedboxer.sources.filter.FilterManager.java

/**
 * After having the content mapped to each user, this method filters the users for each content
 * using the user's cache (10 minutes by default to avoid dual downloads), if cache content is
 * equal to a matchedContent, then the user is removed.
 *///  ww  w .  j av a 2  s  . com
private Map<Content, List<User>> filterContentWithCache(Map<Content, List<User>> mappedContents) {
    LOGGER.debug("Before filter with cache {}", mappedContents);

    List<Content> toRemove = new ArrayList<Content>();
    for (Map.Entry<Content, List<User>> entries : mappedContents.entrySet()) {

        Content content = entries.getKey();
        List<User> users = entries.getValue();
        List<User> usersThatAlreadyHaveThisContent = cache.getIfPresent(content);

        if (usersThatAlreadyHaveThisContent != null) {
            if (users.size() == usersThatAlreadyHaveThisContent.size()) {
                toRemove.add(content);
            } else {
                users.removeAll(usersThatAlreadyHaveThisContent);
            }
        } else {
            cache.put(content, users);
        }
    }

    for (Content content : toRemove) {
        mappedContents.remove(content);
    }
    LOGGER.debug("After filter with cache {}", mappedContents);
    return mappedContents;
}

From source file:com.wipro.ats.bdre.clustermigration.MigrationPreprocessor.java

private Set<String> getChangedBusinessPartitionSet(List<String> sourcePartitionList,
        List<String> previousPartitionList) {
    List<String> deletedPartitionList = new ArrayList<>(previousPartitionList);
    deletedPartitionList.removeAll(sourcePartitionList);
    List<String> addedPartitionList = new ArrayList<>(sourcePartitionList);
    addedPartitionList.removeAll(previousPartitionList);
    List<String> removedBusinessPartitionList = new ArrayList<>();
    List<String> addedBusinessPartitionList = new ArrayList<>();

    for (String addedPartition : addedPartitionList) {
        addedBusinessPartitionList.add(addedPartition.substring(0, addedPartition.lastIndexOf("/")));
    }/*from www  . ja  v a2s.  c  o  m*/

    for (String deletedPartition : deletedPartitionList) {
        removedBusinessPartitionList.add(deletedPartition.substring(0, deletedPartition.lastIndexOf("/")));
    }
    Set<String> businessPartitionSet = new HashSet<>();
    businessPartitionSet.addAll(removedBusinessPartitionList);
    businessPartitionSet.addAll(addedBusinessPartitionList);

    for (String editedBusinessPartition : businessPartitionSet) {
        LOGGER.debug("editedBusinessPartition = " + editedBusinessPartition);
    }
    return businessPartitionSet;
}

From source file:com.esri.geoevent.test.performance.ui.ReportOptionsController.java

@FXML
private void moveLeft(final ActionEvent event) {
    if (selectedColumns.getSelectionModel().getSelectedItems() != null
            && selectedColumns.getItems().size() > 1) {
        List<String> selectedColumnsList = new ArrayList<String>(selectedColumns.getItems());
        List<String> columnsToRemoveList = new ArrayList<String>(
                selectedColumns.getSelectionModel().getSelectedItems());
        selectedColumnsList.removeAll(columnsToRemoveList);
        updateSelectedReportColumns(selectedColumnsList);
    }/*from   w ww  .ja va 2 s  . c o  m*/
}