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:mitm.djigzo.web.components.CertificateGrid.java

public String getReorder() {
    if (exclude == null) {
        return reorder;
    }//from   w  w w  . java 2  s.  co m
    /*
     * We need to remove all columns that are excluded because the Grid does not allow
     * a column to be on the reorder list and on the exclude list.
     * 
     * I have reported an issue about this:
     *       https://issues.apache.org/jira/browse/TAPESTRY-2564
     */
    Set<String> allItems = CollectionUtils.asLinkedHashSet(reorder.split("\\s*,\\s*"));

    Set<String> toRemove = CollectionUtils.asLinkedHashSet(exclude.split("\\s*,\\s*"));

    allItems.removeAll(toRemove);

    return StringUtils.join(allItems, ",");
}

From source file:com.swiftcorp.portal.role.web.RoleFunctionDispatchAction.java

public ActionForward addRoleFunctions(ActionMapping mapping, ActionForm form, HttpServletRequest request,
        HttpServletResponse response) throws SystemException, BusinessRuleViolationException, Exception {
    log.info("addRoleFunctions() : enter");

    @SuppressWarnings("unused")

    HttpSession session = request.getSession();
    System.out.println("in role function");
    DynaValidatorActionForm roleFunctionForm = (DynaValidatorActionForm) form;
    long componentId = Long.parseLong((String) roleFunctionForm.get("role"));
    log.info("Role from Ui" + roleFunctionForm.get("role"));

    // now get the role dto from the database
    RoleDTO roleDTO = (RoleDTO) roleService.get(componentId);// (RoleDTO)roleFunctionForm.get
    // ( "role"/*from   w  w  w  .j a  v a  2  s . com*/
    // );

    String checkedIndex = (String) roleFunctionForm.get("checkedIndex");
    String[] functionIndexArray = checkedIndex.split(",");
    List<FunctionDTO> functionDTOList = (List<FunctionDTO>) session.getAttribute(SESSION_KEYS.FUNCTIONDTO_LIST);
    // get the function from the role dto
    Set<FunctionDTO> functionSet = null;
    if (roleDTO != null) {
        functionSet = roleDTO.getFunctions();
        // remove existing functions from the list
        functionSet.removeAll(functionSet);
    }

    for (int i = 0; i < functionIndexArray.length; i++) {
        int index = -1;
        if (functionIndexArray[i] != null && !(functionIndexArray[i]).equals("null")
                && (functionIndexArray[i]).length() > 0) {
            index = Integer.parseInt(functionIndexArray[i]);
            log.debug("functionIndex are " + functionIndexArray[i]);
            FunctionDTO functionDTOFromList = functionDTOList.get(index);
            functionDTOFromList.getRoles().add(functionDTOFromList);
            functionSet.add(functionDTOFromList);
        }
    }

    FunctionDTO functionDTO = new FunctionDTO();
    String[][] messageArgValues = { { roleDTO.getDescription() } };
    roleDTO.setFunctions(functionSet);
    // now save the role dto
    roleService.modify(roleDTO);
    // get modified role list
    List<RoleDTO> roleList = roleService.getList();
    // put role list to session
    session.setAttribute(SESSION_KEYS.ROLE_LIST, roleList);
    log.info("Save the role and Functions");
    WebUtils.setSuccessMessages(request, MessageKeys.ASSIGN_SUCCESS_MESSAGE_KEYS, messageArgValues);
    return mapping.findForward(ForwardNames.SHOW_FUNCTIONS);

}

From source file:gov.nih.nci.caintegrator.application.lists.UserListBeanHelper.java

public void differenceLists(List<String> listNames, String newListName, ListType listType) {

    //we're only expecting 2 lists here
    if (listNames.size() != 2) {
        return;/*ww  w.  j  av a  2s .  c  o  m*/
    }
    UserList ulist = userListBean.getList(listNames.get(0));
    List<String> s1 = ulist.getList();
    ulist = userListBean.getList(listNames.get(1));
    List<String> s2 = ulist.getList();

    //transforms s1 into the (asymmetric) set difference of s1 and s2. 
    //(For example, the set difference of s1 minus s2 is the set containing all 
    //the elements found in s1 but not in s2.)

    Set<String> difference = new HashSet<String>(s1);
    difference.removeAll(s2);
    UserList newList = null;
    if (difference.size() > 0) {
        List dList = new ArrayList();
        dList.addAll(difference);
        Collections.sort(dList, String.CASE_INSENSITIVE_ORDER);

        newList = new UserList(newListName + "_" + listNames.get(0) + "-" + listNames.get(1), listType, dList,
                new ArrayList<String>(), new Date());
        newList.setListOrigin(ListOrigin.Custom);
        newList.setItemCount(dList.size());
        userListBean.addList(newList);
    }
    Set<String> difference2 = new HashSet<String>(s2);
    difference2.removeAll(s1);
    if (difference2.size() > 0) {
        List dList2 = new ArrayList();
        dList2.addAll(difference2);
        Collections.sort(dList2, String.CASE_INSENSITIVE_ORDER);
        newList = null;
        newList = new UserList(newListName + "_" + listNames.get(1) + "-" + listNames.get(0), listType, dList2,
                new ArrayList<String>(), new Date());
        newList.setListOrigin(ListOrigin.Custom);
        newList.setItemCount(dList2.size());
        userListBean.addList(newList);
    }

}

From source file:com.swiftcorp.portal.role.web.RoleFunctionDispatchAction.java

public ActionForward modifyRoleFunctions(ActionMapping mapping, ActionForm form, HttpServletRequest request,
        HttpServletResponse response) throws SystemException, BusinessRuleViolationException, Exception {
    log.info("addRoleFunctions() : enter");

    @SuppressWarnings("unused")

    HttpSession session = request.getSession();
    System.out.println("in role function");

    long componentId = Long.parseLong((String) request.getParameter("role"));

    // now get the role dto from the database
    RoleDTO roleDTO = (RoleDTO) roleService.get(componentId);// (RoleDTO)roleFunctionForm.get
    // ( "role"/*from  w w w.  ja va2s.c om*/
    // );
    Enumeration<String> en = request.getParameterNames();

    List<FunctionDTO> functionDTOList = (List<FunctionDTO>) session.getAttribute(SESSION_KEYS.FUNCTIONDTO_LIST);
    // get the function from the role dto
    Set<FunctionDTO> functionSet = null;
    if (roleDTO != null) {
        functionSet = roleDTO.getFunctions();
        // remove existing functions from the list
        functionSet.removeAll(functionSet);
    }
    String key = "";
    String value = "";
    while (en.hasMoreElements()) {
        key = en.nextElement();
        if (key.startsWith("cb-")) {
            int index = -1;
            value = key.substring(3, key.length());
            index = Integer.parseInt(value);
            log.debug("functionIndex are " + value);
            FunctionDTO functionDTOFromList = null;
            for (FunctionDTO dto : functionDTOList) {
                if (("" + dto.getComponentId()).equals("" + (value))) {
                    functionDTOFromList = dto;
                    break;
                }
            }
            if (functionDTOFromList != null) {
                functionDTOFromList.getRoles().add(functionDTOFromList);
                functionSet.add(functionDTOFromList);
            }

        }
    }

    FunctionDTO functionDTO = new FunctionDTO();
    String[][] messageArgValues = { { roleDTO.getDescription() } };
    roleDTO.setFunctions(functionSet);
    // now save the role dto
    roleService.modify(roleDTO);
    // get modified role list
    List<RoleDTO> roleList = roleService.getList();
    // put role list to session
    session.setAttribute(SESSION_KEYS.ROLE_LIST, roleList);
    log.info("Save the role and Functions");
    WebUtils.setSuccessMessages(request, MessageKeys.ASSIGN_SUCCESS_MESSAGE_KEYS, messageArgValues);
    return mapping.findForward(ForwardNames.EXT_FORM_ADD_SUCCESS);

}

From source file:edu.cornell.mannlib.vitro.utilities.containerneutral.CheckContainerNeutrality.java

private void checkServletNames() {
    Set<String> servletNames = new HashSet<String>();
    for (Node n : findNodes("//j2ee:servlet/j2ee:servlet-name")) {
        servletNames.add(n.getTextContent());
    }/*  ww w. j a  va 2 s  .c o  m*/

    Set<String> servletMappingNames = new HashSet<String>();
    for (Node n : findNodes("//j2ee:servlet-mapping/j2ee:servlet-name")) {
        servletMappingNames.add(n.getTextContent());
    }

    servletMappingNames.removeAll(servletNames);
    for (String name : servletMappingNames) {
        messages.add("There is a <servlet-mapping> tag for <servlet-name>" + name
                + "</servlet-name>, but there is " + "no matching <servlet> tag.");
    }
}

From source file:com.univocity.app.DataUpdateTest.java

private void validateAbsentRecordsGotRemoved(String entityName, RowDataCollector dataCollector,
        String deleteFile) {//from   www  .j  a va 2s .c o m

    String[] fieldNames = dataCollector.getFieldNames();

    DataSource dataSource = DataStores.getInstance().getSourceDatabase().getDataSource();
    List<Map<String, Object>> results = new JdbcTemplate(dataSource)
            .queryForList("SELECT " + toString(fieldNames).replace('^', ',') + " FROM " + entityName);

    Set<String> idsOnDatabase = new HashSet<String>(results.size());

    for (Map<String, Object> e : results) {
        String id = toString(fieldNames, e);
        idsOnDatabase.add(id);
    }

    System.gc();

    if (deleteFile == null) {
        Set<String> sr25Rows = getMapOfRows(entityName, fieldNames, true).keySet();
        Set<String> sr26Rows = getMapOfRows(entityName, fieldNames, false).keySet();

        @SuppressWarnings("unchecked")
        Collection<String> commonIds = CollectionUtils.intersection(sr25Rows, sr26Rows);
        sr25Rows.removeAll(commonIds);
        sr26Rows.removeAll(commonIds);

        sr25Rows = new TreeSet<String>(sr25Rows);
        sr26Rows = new TreeSet<String>(sr26Rows);

        for (String id : idsOnDatabase) {
            //table does not retain ids that are not in SR26
            assertFalse(sr25Rows.contains(id));

            sr26Rows.remove(id);
        }

        // ensures no unexpected ID is found on SR26.
        assertTrue(sr26Rows.isEmpty());
    } else {
        parserSettings.setRowProcessor(dataCollector);
        new CsvParser(parserSettings)
                .parse(DataStores.getInstance().getSourceData().openUpdateFile(deleteFile));
        Set<String> expectedToBeRemoved = dataCollector.getExpected();

        for (String toBeRemoved : expectedToBeRemoved) {
            assertFalse(idsOnDatabase.contains(toBeRemoved));
        }
    }
}

From source file:com.univocity.app.DataUpdateTest.java

private void executeAndValidate(String entityName, boolean inserting, RowDataCollector dataCollector) {
    System.gc();//  ww  w.  ja  v  a  2 s.  c o  m
    loadProcess.execute(entityName);

    Set<String> persistedRows = dataCollector.getPersistedData();
    Set<String> expectedRows = dataCollector.getExpected();

    if (!expectedRows.containsAll(persistedRows)) {
        @SuppressWarnings("unchecked")
        Collection<String> intersection = CollectionUtils.intersection(persistedRows, expectedRows);

        persistedRows.removeAll(intersection);
        expectedRows.removeAll(intersection);

        if (!isExpectedDiscrepancy(entityName, dataCollector.getFieldNames(), inserting, persistedRows)) {
            fail("Unexpected rows persisted:\n" + persistedRows.size()
                    + "\n\nRows expected but not persisted:\n" + expectedRows.size());
        }
    }
    System.gc();
}

From source file:eu.trentorise.smartcampus.permissionprovider.manager.ResourceAdapter.java

/**
 * Try to remove the resource parameter and its children. Operation is recursive.
 * If one of the derived resources is already in use, an exception is thrown.
 * @param resourceId// ww w.  j  av  a  2  s.  c o  m
 * @param value
 * @param clientId
 */
public void removeResourceParameter(String resourceId, String value, String clientId) {
    ResourceParameterKey pk = new ResourceParameterKey();
    pk.resourceId = resourceId;
    pk.value = value;
    // main parameter
    ResourceParameter rpdb = resourceParameterRepository.findOne(pk);
    if (rpdb != null && !rpdb.getClientId().equals(clientId)) {
        throw new IllegalArgumentException("Can delete only own resource parameters");
    }
    if (rpdb != null) {
        Set<String> ids = new HashSet<String>();
        Set<String> scopes = new HashSet<String>();
        // aggregate all derived resource uris
        Collection<String> uris = findResourceURIs(rpdb).keySet();
        for (String uri : uris) {
            Resource r = resourceRepository.findByResourceUri(uri);
            if (r != null) {
                ids.add(r.getResourceId().toString());
                scopes.add(r.getResourceUri());
            }
        }
        ClientDetailsEntity owner = null;
        // check the resource uri usages
        for (ClientDetailsEntity cd : clientDetailsRepository.findAll()) {
            if (cd.getClientId().equals(clientId)) {
                owner = cd;
                continue;
            }
            if (!Collections.disjoint(cd.getResourceIds(), ids)) {
                throw new IllegalArgumentException("Resource is in use by other client app.");
            }
        }
        // delete main and its children
        for (String id : ids) {
            resourceRepository.delete(Long.parseLong(id));
        }
        if (owner != null) {
            Set<String> oldScopes = new HashSet<String>(owner.getScope());
            oldScopes.removeAll(scopes);
            owner.setScope(StringUtils.collectionToCommaDelimitedString(oldScopes));
            Set<String> oldIds = new HashSet<String>(owner.getResourceIds());
            oldIds.removeAll(ids);
            owner.setResourceIds(StringUtils.collectionToCommaDelimitedString(oldIds));
            clientDetailsRepository.save(owner);

        }
        resourceParameterRepository.delete(rpdb);
    }
}

From source file:annis.visualizers.component.grid.EventExtractor.java

/**
* Returns the annotations to display according to the mappings configuration.
*
* This will check the "annos" and "annos_regex" paramters for determining.
* the annotations to display. It also iterates over all nodes of the graph
* matching the type.//from   w  w  w  .  j  a  v a  2s  .  c  om
*
* @param input The input for the visualizer.
* @param type Which type of nodes to include
* @return
*/
public static List<String> computeDisplayAnnotations(VisualizerInput input, Class<? extends SNode> type) {
    if (input == null) {
        return new LinkedList<String>();
    }

    SDocumentGraph graph = input.getDocument().getSDocumentGraph();

    Set<String> annoPool = getAnnotationLevelSet(graph, input.getNamespace(), type);
    List<String> annos = new LinkedList<String>(annoPool);

    String annosConfiguration = input.getMappings().getProperty(MAPPING_ANNOS_KEY);
    if (annosConfiguration != null && annosConfiguration.trim().length() > 0) {
        String[] split = annosConfiguration.split(",");
        annos.clear();
        for (String s : split) {
            s = s.trim();
            // is regular expression?
            if (s.startsWith("/") && s.endsWith("/")) {
                // go over all remaining items in our pool of all annotations and
                // check if they match
                Pattern regex = Pattern.compile(StringUtils.strip(s, "/"));

                LinkedList<String> matchingAnnos = new LinkedList<String>();
                for (String a : annoPool) {
                    if (regex.matcher(a).matches()) {
                        matchingAnnos.add(a);
                    }
                }

                annos.addAll(matchingAnnos);
                annoPool.removeAll(matchingAnnos);

            } else {
                annos.add(s);
                annoPool.remove(s);
            }
        }
    }

    // filter already found annotation names by regular expression
    // if this was given as mapping
    String regexFilterRaw = input.getMappings().getProperty(MAPPING_ANNO_REGEX_KEY);
    if (regexFilterRaw != null) {
        try {
            Pattern regexFilter = Pattern.compile(regexFilterRaw);
            ListIterator<String> itAnnos = annos.listIterator();
            while (itAnnos.hasNext()) {
                String a = itAnnos.next();
                // remove entry if not matching
                if (!regexFilter.matcher(a).matches()) {
                    itAnnos.remove();
                }
            }
        } catch (PatternSyntaxException ex) {
            log.warn("invalid regular expression in mapping for grid visualizer", ex);
        }
    }
    return annos;
}

From source file:com.github.jengelman.gradle.plugins.integration.TestFile.java

/**
 * Asserts that this file contains exactly the given set of descendants.
 *///from  www .  ja  va2 s  .com
public TestFile assertHasDescendants(String... descendants) {
    Set<String> actual = new TreeSet<String>();
    assertIsDir();
    visit(actual, "", this);
    Set<String> expected = new TreeSet<String>(Arrays.asList(descendants));

    Set<String> extras = new TreeSet<String>(actual);
    extras.removeAll(expected);
    Set<String> missing = new TreeSet<String>(expected);
    missing.removeAll(actual);

    assertEquals(String.format("For dir: %s, extra files: %s, missing files: %s, expected: %s", this, extras,
            missing, expected), expected, actual);

    return this;
}