Example usage for java.util Collection remove

List of usage examples for java.util Collection remove

Introduction

In this page you can find the example usage for java.util Collection remove.

Prototype

boolean remove(Object o);

Source Link

Document

Removes a single instance of the specified element from this collection, if it is present (optional operation).

Usage

From source file:org.apache.fop.render.ps.ResourceOptimizationTestCase.java

private void verifyPostScriptFile(File psFile) throws IOException, DSCException {
    InputStream in = new java.io.FileInputStream(psFile);
    in = new java.io.BufferedInputStream(in);
    try {/*from  w  ww  .  j  av a2  s  . co  m*/
        DSCParser parser = new DSCParser(in);

        //The first form is for arrow_down_small.png (to be reused)
        PSResource form1 = new PSResource(PSResource.TYPE_FORM, "FOPForm:1");
        PSResource helvetica = new PSResource(PSResource.TYPE_FONT, "Helvetica");
        PSResource helveticaBold = new PSResource(PSResource.TYPE_FONT, "Helvetica-Bold");

        PSResource res;
        DSCCommentPages pages = (DSCCommentPages) gotoDSCComment(parser, DSCConstants.PAGES);
        assertEquals(2, pages.getPageCount());

        DSCCommentDocumentSuppliedResources supplied = (DSCCommentDocumentSuppliedResources) gotoDSCComment(
                parser, DSCConstants.DOCUMENT_SUPPLIED_RESOURCES);
        Set resources = supplied.getResources();
        assertEquals(5, resources.size());
        assertTrue(resources.contains(form1));
        assertTrue("Expected barcode.eps as supplied resource",
                resources.contains(new PSResource(PSResource.TYPE_FILE, "test/resources/images/barcode.eps")));

        DSCCommentDocumentNeededResources needed = (DSCCommentDocumentNeededResources) gotoDSCComment(parser,
                DSCConstants.DOCUMENT_NEEDED_RESOURCES);
        resources = needed.getResources();
        assertEquals(2, resources.size());
        assertTrue("Expected Helvetica as needed resource",
                resources.contains(new PSResource(PSResource.TYPE_FONT, "Helvetica")));
        assertTrue("Expected Helvetica-Bold as needed resource",
                resources.contains(new PSResource(PSResource.TYPE_FONT, "Helvetica-Bold")));

        //Some document structure checking
        assertNotNull(gotoDSCComment(parser, DSCConstants.BEGIN_DEFAULTS));
        assertNotNull(gotoDSCComment(parser, DSCConstants.END_DEFAULTS));
        assertNotNull(gotoDSCComment(parser, DSCConstants.BEGIN_PROLOG));
        assertNotNull(gotoDSCComment(parser, DSCConstants.END_PROLOG));
        assertNotNull(gotoDSCComment(parser, DSCConstants.BEGIN_SETUP));

        //Check includes for the two referenced base 14 fonts
        DSCCommentIncludeResource include;
        Collection strings = new java.util.HashSet(
                Arrays.asList(new String[] { "Helvetica", "Helvetica-Bold" }));
        for (int i = 0; i < 2; i++) {
            include = (DSCCommentIncludeResource) gotoDSCComment(parser, DSCConstants.INCLUDE_RESOURCE);
            res = include.getResource();
            assertEquals(PSResource.TYPE_FONT, res.getType());
            strings.remove(res.getName());
        }
        assertEquals(0, strings.size());

        checkResourceComment(parser, DSCConstants.BEGIN_RESOURCE,
                new PSResource(PSResource.TYPE_ENCODING, "WinAnsiEncoding"));

        //Here, we encounter form 1 again
        checkResourceComment(parser, DSCConstants.BEGIN_RESOURCE, form1);

        assertNotNull(gotoDSCComment(parser, DSCConstants.END_SETUP));
        //Now the actual pages begin

        //---=== Page 1 ===---
        DSCCommentPage page = (DSCCommentPage) gotoDSCComment(parser, DSCConstants.PAGE);
        assertEquals(1, page.getPagePosition());

        assertEquals(DSCAtend.class, gotoDSCComment(parser, DSCConstants.PAGE_RESOURCES).getClass());
        assertNotNull(gotoDSCComment(parser, DSCConstants.BEGIN_PAGE_SETUP));
        assertNotNull(gotoDSCComment(parser, DSCConstants.END_PAGE_SETUP));

        PSResource form2 = new PSResource(PSResource.TYPE_FORM, "FOPForm:2");
        checkResourceComment(parser, DSCConstants.BEGIN_RESOURCE, form2);
        assertNotNull(gotoDSCComment(parser, DSCConstants.PAGE_TRAILER));

        AbstractResourcesDSCComment pageResources;
        pageResources = (AbstractResourcesDSCComment) gotoDSCComment(parser, DSCConstants.PAGE_RESOURCES);
        resources = pageResources.getResources();
        assertEquals(5, resources.size());
        assertTrue(resources.contains(form1));
        assertTrue(resources.contains(form2));
        assertTrue(resources.contains(helvetica));
        assertTrue(resources.contains(helveticaBold));

        //---=== Page 2 ===---
        page = (DSCCommentPage) gotoDSCComment(parser, DSCConstants.PAGE);
        assertEquals(2, page.getPagePosition());

        assertEquals(DSCAtend.class, gotoDSCComment(parser, DSCConstants.PAGE_RESOURCES).getClass());
        assertNotNull(gotoDSCComment(parser, DSCConstants.BEGIN_PAGE_SETUP));
        assertNotNull(gotoDSCComment(parser, DSCConstants.END_PAGE_SETUP));

        DSCCommentBeginDocument beginDocument;
        beginDocument = (DSCCommentBeginDocument) gotoDSCComment(parser, DSCConstants.BEGIN_DOCUMENT);
        assertEquals("test/resources/images/barcode.eps", beginDocument.getResource().getName());
        DSCListener listener = new DefaultNestedDocumentHandler(null);
        listener.processEvent(beginDocument, parser);

        //And again (the barcode is generated twice)
        beginDocument = (DSCCommentBeginDocument) gotoDSCComment(parser, DSCConstants.BEGIN_DOCUMENT);
        assertEquals("test/resources/images/barcode.eps", beginDocument.getResource().getName());
        listener.processEvent(beginDocument, parser);

        assertNotNull(gotoDSCComment(parser, DSCConstants.PAGE_TRAILER));
        pageResources = (AbstractResourcesDSCComment) gotoDSCComment(parser, DSCConstants.PAGE_RESOURCES);
        resources = pageResources.getResources();
        assertEquals(6, resources.size());
        assertTrue(resources.contains(form1));
        assertFalse(resources.contains(form2));
        assertTrue(resources.contains(helvetica));
        assertTrue(resources.contains(helveticaBold));
        assertTrue(resources.contains(beginDocument.getResource()));

        assertNotNull(gotoDSCComment(parser, DSCConstants.TRAILER));
        //No headers in between, as they should have been put at the beginning of the file
        assertEquals(DSCCommentEndOfFile.class, parser.nextEvent().asDSCComment().getClass());

    } finally {
        IOUtils.closeQuietly(in);
    }
}

From source file:org.usergrid.tools.DupAdminRepair.java

/**
 * When our usernames are equal, we need to check if our emails are equal. If
 * they're not, we need to change the one that DOES NOT get returned on a
 * lookup by username//from  w ww  . j  av a2 s  .c om
 * 
 * @param targetDir
 * @param adminId
 * @param userNames
 * @throws Exception
 */
private void resolveUsernameConflicts(String targetDir, String userName, Collection<UUID> ids)
        throws Exception {
    // lookup the admin id
    UserInfo existing = managementService.getAdminUserByUsername(userName);

    if (existing == null) {
        logger.warn("Could not determine an admin for colliding username '{}'.  Skipping", userName);
        return;
    }

    ids.remove(existing.getUuid());

    boolean collision = false;

    EntityManager em = emf.getEntityManager(MANAGEMENT_APPLICATION_ID);

    for (UUID id : ids) {
        UserInfo other = managementService.getAdminUserByUuid(id);

        // same username and email, these will be merged later in the process,
        // skip it
        if (other != null && other.getEmail() != null && other.getEmail().equals(existing.getEmail())) {
            logger.info(
                    "Users with the same username '{}' have the same email '{}'. This will be resolved later in the process, skipping",
                    userName, existing.getEmail());
            continue;
        }

        // if we get here, the emails do not match, but the usernames do. Force
        // both usernames to emails
        collision = true;

        setUserName(em, other, other.getEmail());

    }

    if (collision) {
        setUserName(em, existing, existing.getEmail());
    }

}

From source file:org.mitre.uma.service.impl.MatchAllClaimsProcessor.java

@Override
public Collection<Claim> claimsAreSatisfied(Collection<Claim> claimsRequired,
        Collection<Claim> claimsSupplied) {

    Collection<Claim> claimsUnmatched = new HashSet<>(claimsRequired);

    // see if each of the required claims has a counterpart in the supplied claims set
    for (Claim required : claimsRequired) {
        for (Claim supplied : claimsSupplied) {

            if (required.getIssuer().containsAll(supplied.getIssuer())) {
                // it's from the right issuer

                if (required.getName().equals(supplied.getName())
                        && required.getValue().equals(supplied.getValue())) {

                    // the claim matched, pull it from the set
                    claimsUnmatched.remove(required);

                }//ww  w .  j a  v a2  s. co  m

            }
        }
    }

    // if there's anything left then the claims aren't satisfied, return the leftovers
    return claimsUnmatched;

}

From source file:org.kuali.kfs.module.ld.dataaccess.impl.LaborLedgerBalanceDaoOjb.java

protected ReportQueryByCriteria getBalanceCountQuery(Map fieldValues, List<String> encumbranceBalanceTypes,
        boolean noZeroAmounts) {
    Criteria criteria = buildCriteriaFromMap(fieldValues, new LedgerBalance(), encumbranceBalanceTypes,
            noZeroAmounts);//  w w w . j  a  v a  2  s .  c o m
    ReportQueryByCriteria query = QueryFactory.newReportQuery(LedgerBalance.class, criteria);

    // set the selection attributes
    query.setAttributes(new String[] { "count(*)" });

    Collection<String> groupByList = buildGroupByCollection();
    groupByList.remove(KFSPropertyConstants.SUB_ACCOUNT_NUMBER);
    groupByList.remove(KFSPropertyConstants.FINANCIAL_SUB_OBJECT_CODE);
    groupByList.remove(KFSPropertyConstants.FINANCIAL_OBJECT_TYPE_CODE);

    // add the group criteria into the selection statement
    String[] groupBy = (String[]) groupByList.toArray(new String[groupByList.size()]);
    query.addGroupBy(groupBy);
    return query;
}

From source file:com.stormpath.spring.security.authz.CustomDataPermissionsEditor.java

@Override
public PermissionsEditor remove(String perm) {
    if (StringUtils.hasText(perm)) {
        Collection<String> perms = lookupPermissionStrings();
        if (!CollectionUtils.isEmpty(perms)) {
            if (perms instanceof List) {
                //hasn't yet been converted to a set that we maintain:
                String attrName = getFieldName();
                perms = asSet(attrName, (List) perms);
                CUSTOM_DATA.put(attrName, perms);
            }/*from  ww  w  .  j a  v a  2  s .c  o  m*/
            perms.remove(perm);
        }
    }
    return this;
}

From source file:org.wso2.carbon.identity.application.authentication.framework.handler.provisioning.impl.DefaultProvisioningHandler.java

@Override
public void handle(List<String> roles, String subject, Map<String, String> attributes,
        String provisioningUserStoreId, String tenantDomain) throws FrameworkException {

    RegistryService registryService = FrameworkServiceComponent.getRegistryService();
    RealmService realmService = FrameworkServiceComponent.getRealmService();

    try {//  www.j  a va 2s .  c o  m
        int tenantId = realmService.getTenantManager().getTenantId(tenantDomain);
        UserRealm realm = AnonymousSessionUtil.getRealmByTenantDomain(registryService, realmService,
                tenantDomain);

        String userStoreDomain = getUserStoreDomain(provisioningUserStoreId, realm);

        String username = MultitenantUtils.getTenantAwareUsername(subject);

        UserStoreManager userStoreManager = getUserStoreManager(realm, userStoreDomain);

        // Remove userStoreManager domain from username if the userStoreDomain is not primary
        if (realm.getUserStoreManager().getRealmConfiguration().isPrimary()) {
            username = UserCoreUtil.removeDomainFromName(username);
        }

        String[] newRoles = new String[] {};

        if (roles != null) {
            roles = removeDomainFromNamesExcludeInternal(roles);
            newRoles = roles.toArray(new String[roles.size()]);
        }

        if (log.isDebugEnabled()) {
            log.debug("User " + username + " contains roles : " + Arrays.toString(newRoles)
                    + " going to be provisioned");
        }

        // addingRoles = newRoles AND allExistingRoles
        Collection<String> addingRoles = getRolesToAdd(userStoreManager, newRoles);

        Map<String, String> userClaims = prepareClaimMappings(attributes);

        if (userStoreManager.isExistingUser(username)) {

            if (roles != null && !roles.isEmpty()) {
                // Update user
                Collection<String> currentRolesList = Arrays
                        .asList(userStoreManager.getRoleListOfUser(username));
                // addingRoles = (newRoles AND existingRoles) - currentRolesList)
                addingRoles.removeAll(currentRolesList);

                Collection<String> deletingRoles = new ArrayList<String>();
                deletingRoles.addAll(currentRolesList);
                // deletingRoles = currentRolesList - newRoles
                deletingRoles.removeAll(Arrays.asList(newRoles));

                // Exclude Internal/everyonerole from deleting role since its cannot be deleted
                deletingRoles.remove(realm.getRealmConfiguration().getEveryOneRoleName());

                // TODO : Does it need to check this?
                // Check for case whether superadmin login
                handleFederatedUserNameEqualsToSuperAdminUserName(realm, username, userStoreManager,
                        deletingRoles);

                updateUserWithNewRoleSet(username, userStoreManager, newRoles, addingRoles, deletingRoles);
            }

            if (!userClaims.isEmpty()) {
                userStoreManager.setUserClaimValues(username, userClaims, null);
            }

        } else {

            userStoreManager.addUser(username, generatePassword(),
                    addingRoles.toArray(new String[addingRoles.size()]), userClaims, null);

            if (log.isDebugEnabled()) {
                log.debug("Federated user: " + username
                        + " is provisioned by authentication framework with roles : "
                        + Arrays.toString(addingRoles.toArray(new String[addingRoles.size()])));
            }
        }

        PermissionUpdateUtil.updatePermissionTree(tenantId);

    } catch (org.wso2.carbon.user.api.UserStoreException | CarbonException e) {
        throw new FrameworkException("Error while provisioning user : " + subject, e);
    }
}

From source file:uk.ac.ebi.intact.editor.services.AbstractEditorService.java

protected void initialiseRanges(Collection<Range> ranges) {
    List<Range> originalRanges = new ArrayList<Range>(ranges);
    for (Range r : originalRanges) {
        if (!isRangeInitialised(r)) {
            Range reloaded = initialiseRange(r);
            if (reloaded != r) {
                ranges.remove(r);
                ranges.add(reloaded);//w  ww .  j  a va 2  s  .c o m
            }
        }
    }
}

From source file:org.mitre.uma.service.impl.MatchAllClaimsOnAnyPolicy.java

private Collection<Claim> checkIndividualClaims(Collection<Claim> claimsRequired,
        Collection<Claim> claimsSupplied) {

    Collection<Claim> claimsUnmatched = new HashSet<>(claimsRequired);

    // see if each of the required claims has a counterpart in the supplied claims set
    for (Claim required : claimsRequired) {
        for (Claim supplied : claimsSupplied) {

            if (required.getIssuer().containsAll(supplied.getIssuer())) {
                // it's from the right issuer

                if (required.getName().equals(supplied.getName())
                        && required.getValue().equals(supplied.getValue())) {

                    // the claim matched, pull it from the set
                    claimsUnmatched.remove(required);

                }/*ww w. ja  v a 2 s. c om*/

            }
        }
    }

    // if there's anything left then the claims aren't satisfied, return the leftovers
    return claimsUnmatched;

}

From source file:ubic.gemma.loader.genome.gene.ncbi.homology.HomologeneServiceImpl.java

@Override
public Collection<Long> getHomologues(Long ncbiId) {

    Collection<Long> NcbiGeneIds = new HashSet<Long>();

    if (!this.ready.get()) {
        return NcbiGeneIds;
    }// ww w .ja  va 2  s  . co m

    Long groupId = this.getHomologeneGroup(ncbiId);
    if (groupId == null)
        return NcbiGeneIds;
    NcbiGeneIds = this.getNCBIGeneIdsInGroup(groupId);
    NcbiGeneIds.remove(ncbiId); // remove the given gene from the list

    return NcbiGeneIds;

}

From source file:com.smash.revolance.ui.comparator.page.PageMatchMaker.java

@Override
public Collection<PageMatch> findMatch(final Collection<PageBean> pages, final PageBean page,
        PageSearchMethod... methods) throws NoMatchFound, IllegalArgumentException {
    if (pages == null) {
        throw new IllegalArgumentException("Null collection of pages to be parsed");
    }/*w  w w  . j  av a2s  .  c  o  m*/
    if (page == null) {
        throw new IllegalArgumentException("Null page cannot be matched.");
    }

    Collection<PageBean> localPages = new ArrayList<PageBean>();
    localPages.addAll(pages);
    if (localPages.contains(page)) {
        pages.remove(page);
    }

    List<PageMatch> matches = getPageMatches(page, localPages, methods);

    if (matches.isEmpty()) {
        throw new NoMatchFound("Unable to find a single match.");
    } else {
        return matches;
    }
}