Example usage for java.util Set removeAll

List of usage examples for java.util Set removeAll

Introduction

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

Prototype

boolean removeAll(Collection<?> c);

Source Link

Document

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

Usage

From source file:com.glaf.base.modules.sys.springmvc.SysUserController.java

/**
 * //from   w  w w.  j  a  v a  2s  .c om
 * 
 * @param request
 * @param modelMap
 * @return
 */
@RequestMapping(params = "method=setRole")
public ModelAndView setRole(HttpServletRequest request, ModelMap modelMap) {
    logger.debug(RequestUtils.getParameterMap(request));
    ViewMessages messages = new ViewMessages();
    long userId = ParamUtil.getIntParameter(request, "user_id", 0);
    SysUser user = sysUserService.findById(userId);// 

    if (user != null) {// 
        long[] id = ParamUtil.getLongParameterValues(request, "id");// ???
        if (id != null) {
            Set<SysDeptRole> delRoles = new HashSet<SysDeptRole>();
            Set<SysDeptRole> oldRoles = user.getRoles();
            Set<SysDeptRole> newRoles = new HashSet<SysDeptRole>();
            for (int i = 0; i < id.length; i++) {
                logger.debug("id[" + i + "]=" + id[i]);
                SysDeptRole role = sysDeptRoleService.findById(id[i]);// 
                if (role != null) {
                    newRoles.add(role);// 
                }
            }

            oldRoles.retainAll(newRoles);// ??
            delRoles.removeAll(newRoles);// ??
            newRoles.removeAll(oldRoles);// ??
            user.setUpdateBy(RequestUtils.getActorId(request));

            if (sysUserService.updateRole(user, delRoles, newRoles)) {// ??
                messages.add(ViewMessages.GLOBAL_MESSAGE, new ViewMessage("user.role_success"));
            } else {// ?
                messages.add(ViewMessages.GLOBAL_MESSAGE, new ViewMessage("user.role_failure"));
            }
        }
    }
    MessageUtils.addMessages(request, messages);
    return new ModelAndView("show_msg", modelMap);
}

From source file:com.ephesoft.dcma.da.dao.hibernate.BatchInstanceDaoImpl.java

/**
 * An api to fetch all the batch instances excluding remotely executing batches by status list. Parameter firstResult set a limit
 * upon the number of objects to be retrieved. Parameter maxResults set the first result to be retrieved. Parameter orderList set
 * the sort property and order of that property. If orderList parameter is null or empty then this parameter is avoided. This will
 * return only those batch instance which having access by the user roles on the basis of the ephesoft user.
 * // w w  w . j  av  a 2s  . c  o m
 * @param searchString {@link String}
 * @param statusList List<{@link BatchInstanceStatus}> status list of batch instance status.
 * @param firstResult the first result to retrieve, numbered from <tt>0</tt>
 * @param maxResults maxResults the maximum number of results
 * @param orderList List<{@link Order}> orderList set the sort property and order of that property. If orderList parameter is null
 *            or empty then this parameter is avoided.
 * @param filterClauseList List<{@link BatchInstanceFilter}> this will add the where clause to the criteria query based on the
 *            property name and value. If filterClauseList parameter is null or empty then this parameter is avoided.
 * @param batchPriorities List<{@link BatchPriority}> this will add the where clause to the criteria query based on the priority
 *            list selected. If batchPriorities parameter is null or empty then this parameter is avoided.
 * @param currentUser {@link String}
 * @param userRoles Set<{@link String}>
 * @param ephesoftUser {@link EphesoftUser}
 * @return List<{@link BatchInstance}> return the batch instance list.
 */
@Override
public List<BatchInstance> getBatchInstancesExcludedRemoteBatch(final String searchString,
        List<BatchInstanceStatus> statusList, final int firstResult, final int maxResults,
        final List<Order> orderList, final List<BatchInstanceFilter> filterClauseList,
        final List<BatchPriority> batchPriorities, String userName, final Set<String> userRoles,
        EphesoftUser ephesoftUser) {
    EphesoftCriteria criteria = criteria();

    if (searchString != null && !searchString.isEmpty()) {
        String batchNameLocal = searchString.replaceAll("%", "\\\\%");
        Criterion nameLikeCriteria = Restrictions.like(BATCH_NAME, "%" + batchNameLocal + "%");
        Criterion idLikeCriteria = Restrictions.like(BATCH_INSTANCE_IDENTIFIER, "%" + batchNameLocal + "%");

        LogicalExpression searchCriteria = Restrictions.or(nameLikeCriteria, idLikeCriteria);
        criteria.add(searchCriteria);
    }
    if (null != statusList) {
        criteria.add(Restrictions.in(STATUS, statusList));
        criteria.add(
                Restrictions.or(Restrictions.isNull(CURRENT_USER), Restrictions.eq(CURRENT_USER, userName)));
        criteria.add(Restrictions.eq(IS_REMOTE, false));
    }
    if (null != batchPriorities && !(batchPriorities.isEmpty())) {
        Disjunction disjunction = Restrictions.disjunction();
        for (BatchPriority batchPriority : batchPriorities) {
            if (null != batchPriority) {
                Integer lowValue = batchPriority.getLowerLimit();
                Integer upperValue = batchPriority.getUpperLimit();
                disjunction.add(Restrictions.between(PRIORITY, lowValue, upperValue));
            } else {
                disjunction = Restrictions.disjunction();
                break;
            }
        }
        criteria.add(disjunction);

    }
    List<BatchInstance> batchInstanceList = new ArrayList<BatchInstance>();

    Set<String> batchClassIdentifiers = batchClassGroupsDao.getBatchClassIdentifierForUserRoles(userRoles);

    switch (ephesoftUser) {
    case NORMAL_USER:
        batchClassIdentifiers = batchClassGroupsDao.getBatchClassIdentifierForUserRoles(userRoles);
        Set<String> batchInstanceIdentifierSet = batchInstanceGroupsDao
                .getBatchInstanceIdentifiersExceptUserRoles(userRoles);
        Set<String> batchInstanceIdentifiers = batchInstanceGroupsDao
                .getBatchInstanceIdentifierForUserRoles(userRoles);
        batchInstanceIdentifierSet.removeAll(batchInstanceIdentifiers);

        if ((null != batchClassIdentifiers && batchClassIdentifiers.size() > 0)
                || (null != batchInstanceIdentifiers && batchInstanceIdentifiers.size() > 0)) {
            BatchInstanceFilter[] filters = null;
            if (filterClauseList != null) {
                filters = filterClauseList.toArray(new BatchInstanceFilter[filterClauseList.size()]);
            }
            Order[] orders = null;
            if (orderList != null) {
                orders = orderList.toArray(new Order[orderList.size()]);
            }

            batchInstanceList = find(criteria, 0, -1, filters, orders);
            // Fixed against JIRA-1018 User not able to navigate through batch list.
            batchInstanceList = updateBatchInstanceList(batchInstanceList, batchClassIdentifiers,
                    batchInstanceIdentifiers, batchInstanceIdentifierSet, firstResult, maxResults);
        }
        break;
    default:
        if (null != batchClassIdentifiers && batchClassIdentifiers.size() > 0) {
            BatchInstanceFilter[] filters = null;
            if (filterClauseList != null) {
                filters = filterClauseList.toArray(new BatchInstanceFilter[filterClauseList.size()]);
            }
            Order[] orders = null;
            if (orderList != null) {
                orders = orderList.toArray(new Order[orderList.size()]);
            }

            criteria.createAlias(BATCH_CLASS, BATCH_CLASS);
            criteria.add(Restrictions.in(BATCH_CLASS_IDENTIFIER, batchClassIdentifiers));
            batchInstanceList = find(criteria, firstResult, maxResults, filters, orders);
        }
        break;
    }
    return batchInstanceList;
}

From source file:com.glaf.base.modules.branch.springmvc.BranchUserController.java

/**
 * //from   w w w .  j  a va 2s  .com
 * 
 * @param request
 * @param modelMap
 * @return
 */
@RequestMapping(params = "method=saveRole")
public ModelAndView saveRole(HttpServletRequest request, ModelMap modelMap) {
    logger.debug(RequestUtils.getParameterMap(request));
    ViewMessages messages = new ViewMessages();
    long userId = ParamUtil.getIntParameter(request, "user_id", 0);
    SysUser user = sysUserService.findById(userId);// 
    if (user != null && user.getDeptId() > 0) {// 
        String actorId = RequestUtils.getActorId(request);
        List<Long> nodeIds = complexUserService.getUserManageBranchNodeIds(actorId);

        SysDepartment department = sysDepartmentService.findById(user.getDeptId());
        /**
         * ???
         */
        if (department != null && department.getNodeId() > 0) {
            SysTree tree = sysTreeService.findById(department.getNodeId());
            if (tree != null && nodeIds.contains(tree.getId())) {
                long[] id = ParamUtil.getLongParameterValues(request, "id");// ???
                if (id != null) {
                    Set<SysDeptRole> delRoles = new HashSet<SysDeptRole>();
                    Set<SysDeptRole> oldRoles = user.getRoles();
                    Set<SysDeptRole> newRoles = new HashSet<SysDeptRole>();
                    for (int i = 0; i < id.length; i++) {
                        logger.debug("id[" + i + "]=" + id[i]);
                        SysDeptRole role = sysDeptRoleService.findById(id[i]);// 
                        if (role != null) {
                            newRoles.add(role);// 
                        }
                    }

                    oldRoles.retainAll(newRoles);// ??
                    delRoles.removeAll(newRoles);// ??
                    newRoles.removeAll(oldRoles);// ??
                    user.setUpdateBy(RequestUtils.getActorId(request));

                    if (sysUserService.updateRole(user, delRoles, newRoles)) {// ??
                        messages.add(ViewMessages.GLOBAL_MESSAGE, new ViewMessage("user.role_success"));
                    } else {// ?
                        messages.add(ViewMessages.GLOBAL_MESSAGE, new ViewMessage("user.role_failure"));
                    }
                }
            }
        }
    }
    MessageUtils.addMessages(request, messages);
    return new ModelAndView("show_msg", modelMap);
}

From source file:edu.stanford.muse.util.Util.java

/**
 * Return list1 - list2. require that the elements must be sortable.
 * /*ww w  .j a v  a  2 s  .co  m*/
 * @param list1
 * @param list2
 * @return
 */
public static <E extends Comparable<? super E>> List<E> getRemoveAll(List<E> list1, Collection<E> list2) {
    Set<E> set1 = new LinkedHashSet<E>(list1);
    set1.removeAll(list2);
    return new ArrayList<E>(set1);
}

From source file:net.sourceforge.floggy.persistence.Weaver.java

/**
 * DOCUMENT ME!//from   w  w  w.j  a v  a2 s  .  c  o  m
*
* @throws NotFoundException DOCUMENT ME!
*/
protected void excludeAbstractDescendents() throws NotFoundException {
    List persistables = configuration.getPersistableMetadatas();

    for (int i = 0; i < persistables.size(); i++) {
        PersistableMetadata metadata = (PersistableMetadata) persistables.get(i);

        String[] temp = metadata.getDescendents();

        if (temp != null) {
            Set descendents = new HashSet(Arrays.asList(temp));

            List toRemove = new LinkedList();

            Iterator iterator = descendents.iterator();

            while (iterator.hasNext()) {
                String className = (String) iterator.next();

                CtClass ctClass = classpathPool.get(className);

                if (Modifier.isAbstract(ctClass.getModifiers())) {
                    toRemove.add(className);
                }
            }

            if (descendents.removeAll(toRemove)) {
                metadata.setDescendents((String[]) descendents.toArray(new String[descendents.size()]));
            }
        }
    }
}

From source file:com.evolveum.midpoint.repo.sql.helpers.OrgClosureManager.java

private void handleModify(String oid, Collection<? extends ItemDelta> modifications,
        PrismObject<? extends ObjectType> originalObject, Context context, Session session) {
    if (modifications.isEmpty()) {
        return;/*w  w w .jav  a 2  s. c om*/
    }

    Set<String> parentsToDelete = getParentOidsToDelete(modifications, originalObject);
    Set<String> parentsToAdd = getParentOidsToAdd(modifications, originalObject);

    Collection<String> livingParentsToDelete = retainExistingOids(parentsToDelete, session);
    Collection<String> livingParentsToAdd = retainExistingOids(parentsToAdd, session);

    parentsToDelete.removeAll(parentsToAdd); // if something is deleted and the re-added we can skip this operation

    removeParentEdges(oid, livingParentsToDelete, context, session);
    addParentEdges(oid, livingParentsToAdd, context, session);
}

From source file:brooklyn.entity.basic.AbstractEntity.java

@Override
public void addLocations(Collection<? extends Location> newLocations) {
    synchronized (locations) {
        List<Location> oldLocations = locations.get();
        Set<Location> truelyNewLocations = Sets.newLinkedHashSet(newLocations);
        truelyNewLocations.removeAll(oldLocations);
        if (truelyNewLocations.size() > 0) {
            locations.set(/*from   ww  w  .j ava2  s.  com*/
                    ImmutableList.<Location>builder().addAll(oldLocations).addAll(truelyNewLocations).build());
        }

        for (Location loc : truelyNewLocations) {
            emit(AbstractEntity.LOCATION_ADDED, loc);
        }
    }

    if (getManagementSupport().isDeployed()) {
        for (Location newLocation : newLocations) {
            // Location is now reachable, so manage it
            // TODO will not be required in future releases when creating locations always goes through LocationManager.createLocation(LocationSpec).
            Locations.manage(newLocation, getManagementContext());
        }
    }
    getManagementSupport().getEntityChangeListener().onLocationsChanged();
}

From source file:com.ephesoft.dcma.da.dao.hibernate.BatchInstanceDaoImpl.java

/**
 * An api to fetch all the batch instances by status list. Parameter firstResult set a limit upon the number of objects to be
 * retrieved. Parameter maxResults set the first result to be retrieved. Parameter orderList set the sort property and order of
 * that property. If orderList parameter is null or empty then this parameter is avoided.
 * /*from w ww  . ja v a 2  s . co m*/
 * @param statusList List<BatchInstanceStatus> status list of batch instance status.
 * @param firstResultTemp the first result to retrieve, numbered from <tt>0</tt>
 * @param maxResultsTemp maxResults the maximum number of results
 * @param orderList List<Order> orderList set the sort property and order of that property. If orderList parameter is null or empty
 *            then this parameter is avoided.
 * @param filterClauseList List<BatchInstanceFilter> this will add the where clause to the criteria query based on the property
 *            name and value. If filterClauseList parameter is null or empty then this parameter is avoided.
 * @param batchPriorities List<BatchPriority> this will add the where clause to the criteria query based on the priority list
 *            selected. If batchPriorities parameter is null or empty then this parameter is avoided.
 * @param userName Current user name.
 * @param userRoles currentUserRoles
 * @param EphesoftUser current ephesoft-user
 * @param searchString the searchString on which batch instances have to be fetched
 * @return List<BatchInstance> return the batch instance list.
 */
public List<BatchInstance> getBatchInstances(String batchIdentifierTextSearch, String batchNameTextSearch,
        List<BatchInstanceStatus> statusList, final int firstResult, final int maxResults,
        final List<Order> orderList, final List<BatchInstanceFilter> filterClauseList,
        final List<BatchPriority> batchPriorities, String userName, final Set<String> userRoles,
        EphesoftUser ephesoftUser, final EphesoftCriteria criteria, final String searchString) {
    EphesoftCriteria criteriaLocal = null;
    if (criteria == null) {
        criteriaLocal = criteria();
    } else {
        criteriaLocal = criteria;
    }

    int firstResultTemp = firstResult;
    int maxResultsTemp = maxResults;

    // For adding identifier as an criteria for result
    if (null != searchString && !searchString.isEmpty()) {
        String searchStringLocal = searchString.replaceAll("%", "\\\\%");
        Criterion nameLikeCriteria = Restrictions.like(BATCH_NAME, "%" + searchStringLocal + "%");
        Criterion idLikeCriteria = Restrictions.like(BATCH_INSTANCE_IDENTIFIER, "%" + searchStringLocal + "%");

        LogicalExpression searchCriteria = Restrictions.or(nameLikeCriteria, idLikeCriteria);
        criteriaLocal.add(searchCriteria);
    }

    if (null != batchIdentifierTextSearch && !batchIdentifierTextSearch.isEmpty()
            && !"-1".equalsIgnoreCase(batchIdentifierTextSearch)) {
        System.out.println("Batch identifier text is as follows : " + batchIdentifierTextSearch);
        String searchStringLocal = batchIdentifierTextSearch.replaceAll("%", "\\\\%");
        Criterion idLikeCriteria = Restrictions.like(BATCH_INSTANCE_IDENTIFIER, "%" + searchStringLocal + "%");
        criteriaLocal.add(idLikeCriteria);
    } else if (null != batchNameTextSearch && !batchNameTextSearch.isEmpty()
            && !"-1".equalsIgnoreCase(batchNameTextSearch)) {
        System.out.println("batch name text search is as follows : " + batchNameTextSearch);
        String searchStringLocal = batchNameTextSearch.replaceAll("%", "\\\\%");
        Criterion nameLikeCriteria = Restrictions.like(BATCH_NAME, "%" + searchStringLocal + "%");
        criteriaLocal.add(nameLikeCriteria);
    }

    if (null != statusList) {
        criteriaLocal.add(Restrictions.in(STATUS, statusList));
        // criteria.add(Restrictions.or(Restrictions.isNull(CURRENT_USER), Restrictions.eq(CURRENT_USER, userName)));
    }

    if (null != batchPriorities && !(batchPriorities.isEmpty())) {
        Disjunction disjunction = Restrictions.disjunction();
        for (BatchPriority batchPriority : batchPriorities) {
            if (null != batchPriority) {
                Integer lowValue = batchPriority.getLowerLimit();
                Integer upperValue = batchPriority.getUpperLimit();
                disjunction.add(Restrictions.between(PRIORITY, lowValue, upperValue));
            } else {
                disjunction = Restrictions.disjunction();
                break;
            }
        }
        criteriaLocal.add(disjunction);

    }

    List<BatchInstance> batchInstances = new ArrayList<BatchInstance>();
    BatchInstanceFilter[] filters = null;
    Order[] orders = null;
    switch (ephesoftUser) {
    default:

        // Fixed for JIRA 10220 Batch assigned to some other user from DB is getting visible to the user, to whom corresponding
        // batch class is assigned.
        Set<String> batchClassIdentifiers = batchClassGroupsDao.getBatchClassIdentifierForUserRoles(userRoles);
        batchClassIdentifiers = batchClassGroupsDao.getBatchClassIdentifierForUserRoles(userRoles);
        final Set<String> batchInstanceIdentifierSet = batchInstanceGroupsDao
                .getBatchInstanceIdentifiersExceptUserRoles(userRoles);
        final Set<String> batchInstanceIdentifiers = batchInstanceGroupsDao
                .getBatchInstanceIdentifierForUserRoles(userRoles);
        if (!CollectionUtil.isEmpty(batchInstanceIdentifiers)) {
            batchInstanceIdentifierSet.removeAll(batchInstanceIdentifiers);
        }
        if ((null != batchClassIdentifiers && batchClassIdentifiers.size() > 0)
                || (null != batchInstanceIdentifiers && batchInstanceIdentifiers.size() > 0)) {
            if (filterClauseList != null) {
                filters = filterClauseList.toArray(new BatchInstanceFilter[filterClauseList.size()]);
            }
            if (orderList != null) {
                orders = orderList.toArray(new Order[orderList.size()]);
            }
            batchInstances = find(criteriaLocal, 0, -1, filters, orders);
            if (batchInstances != null && !batchInstances.isEmpty()) {
                batchInstances = updateBatchInstanceList(batchInstances, batchClassIdentifiers,
                        batchInstanceIdentifiers, batchInstanceIdentifierSet, firstResultTemp, maxResultsTemp);
            }
        }
        break;
    }
    return batchInstances;
}

From source file:uk.org.rbc1b.roms.controller.volunteer.interview.InterviewSessionsController.java

/**
 * Submit a list of volunteers to be invited to the session.
 *
 * @param interviewSessionId session id/*from   ww w  .j ava  2  s .  c o m*/
 * @param volunteerIdsParam volunteer ids to be invited
 * @return redirect
 * session
 */
@RequestMapping(value = "{interviewSessionId}/invitations", method = RequestMethod.POST)
@PreAuthorize("hasPermission('VOLUNTEER', 'READ')")
public String submitInvitationList(@PathVariable Integer interviewSessionId,
        @RequestParam(value = "volunteerIds") String volunteerIdsParam) {

    Set<Integer> volunteerIds = new HashSet<Integer>();
    for (String volunteerId : volunteerIdsParam.split(",")) {
        volunteerIds.add(DataConverterUtil.toInteger(volunteerId));
    }

    InterviewSession session = interviewSessionDao.findInterviewSession(interviewSessionId);
    if (session == null) {
        throw new ResourceNotFoundException("No session with id [" + interviewSessionId + "]");
    }

    // we can't invite more people if the session has already happened
    if (session.isInPast()) {
        throw new IllegalStateException("Interview session #" + interviewSessionId + " is in the past.");
    }

    if (session.getKingdomHall() == null || session.getKingdomHall().getKingdomHallId() == null) {
        throw new IllegalStateException(
                "Interview session #" + interviewSessionId + " does not have a kingdom hall defined.");
    }

    List<VolunteerInterviewSession> existingInterviewSessions = interviewSessionDao
            .findVolunteerInterviewSessions(interviewSessionId);

    Set<Integer> existingVolunteerIds = new HashSet<Integer>();
    for (VolunteerInterviewSession existingInterviewSession : existingInterviewSessions) {
        existingVolunteerIds.add(existingInterviewSession.getVolunteer().getPersonId());
    }

    volunteerIds.removeAll(existingVolunteerIds);

    interviewSessionDao.addVolunteerInterviewSessions(volunteerIds, interviewSessionId);

    KingdomHall kingdomHall = kingdomHallDao.findKingdomHall(session.getKingdomHall().getKingdomHallId());

    for (Integer volunteerId : volunteerIds) {
        scheduleInterviewInvitationEmail(session, kingdomHall, volunteerId);
    }

    return "redirect:" + InterviewSessionModelFactory.generateUri(interviewSessionId);

}