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:uk.co.jassoft.markets.utils.lingual.NamedEntityRecognizer.java

private void removeName(Collection<NamedEntity> collection, String name) {
    for (NamedEntity entity : collection) {
        if (entity.getName().equalsIgnoreCase(name) && entity.getCount() > 1) {
            entity.decrease();/*  w w  w.j  av  a2 s .c o  m*/
            return;
        }
    }

    NamedEntity entity = new NamedEntity(name);
    collection.remove(entity);
}

From source file:fi.vm.sade.organisaatio.service.OrganisaatioServiceImpl.java

@Override
public OrganisaatioOidListType findChildrenOidsByOid(OrganisaatioSearchOidType parameters) {
    LOG.warn("findChildrenOidsByOid({})", parameters.getSearchOid());

    Collection<String> tmp = null;

    // Root oid?/*from   www .  java2s.co  m*/
    if (parameters.getSearchOid().trim().equalsIgnoreCase(ophOid)) {
        tmp = organisaatioDAO.findAllOids(false);
        tmp.remove(ophOid);
    } else {
        tmp = organisaatioDAO.listDescendantOids(parameters.getSearchOid(), false);
    }

    // Create result
    OrganisaatioOidListType oidList = new OrganisaatioOidListType();
    for (String oid : tmp) {
        OrganisaatioOidType oidType = new OrganisaatioOidType();
        oidType.setOrganisaatioOid(oid);
        oidList.getOrganisaatioOidList().add(oidType);
    }

    return oidList;
}

From source file:info.magnolia.cms.util.ExtendingContentWrapper.java

@Override
public Collection<NodeData> getNodeDataCollection() {
    final Content wrapped = getWrappedContent();
    Collection<NodeData> directChildren = wrapped.getNodeDataCollection();
    try {//from  ww  w  .jav  a2 s.  c o  m
        if (wrapped.hasNodeData(EXTENDING_NODE_DATA)) {
            for (NodeData child : directChildren) {
                if (EXTENDING_NODE_DATA.equals(child.getName())) {
                    directChildren.remove(child);
                    break;
                }
            }
        }
    } catch (RepositoryException e) {
        throw new RuntimeException("Can't read nodedata collection from node [" + wrapped.getHandle() + "]", e);
    }
    if (extending) {
        Collection<NodeData> inheritedChildren = extendedContent.getNodeDataCollection();
        // sort by name
        SortedMap<String, NodeData> merged = new TreeMap<String, NodeData>();
        for (NodeData nodeData : inheritedChildren) {
            merged.put(nodeData.getName(), nodeData);
        }
        for (NodeData nodeData : directChildren) {
            merged.put(nodeData.getName(), nodeData);
        }
        return wrapNodeDatas(merged.values());
    }
    return wrapNodeDatas(directChildren);
}

From source file:org.squashtest.tm.domain.library.structures.LibraryTree.java

/**
 * Will remove the node having this key if it is childress.
 * If it has children, throws a RuntimeException
 *
 * @param key//from  ww  w. j a  v  a 2 s.c om
 */
public void remove(IDENT key) {
    T node = getNode(key);
    if (node.getChildren().isEmpty()) {

        Collection<T> layer = layers.get(node.getDepth());
        layer.remove(node);

        T parent = node.getParent();
        if (parent != null) {
            parent.getChildren().remove(node);
        }

    } else {
        throw new IllegalArgumentException("Cannot remove node '" + key + "' : it has no children");
    }
}

From source file:org.cyberoam.iview.utility.MultiHashMap.java

/**
 * Removes a specific value from map.//from  w  w w  .  j a v  a 2 s  .c o m
 * <p>
 * The item is removed from the collection mapped to the specified key.
 * Other values attached to that key are unaffected.
 * <p>
 * If the last value for a key is removed, <code>null</code> will be returned
 * from a subsequant <code>get(key)</code>.
 * 
 * @param key  the key to remove from
 * @param item  the value to remove
 * @return the value removed (which was passed in), null if nothing removed
 */
public Object remove(Object key, Object item) {
    Collection valuesForKey = getCollection(key);
    if (valuesForKey == null) {
        return null;
    }
    boolean removed = valuesForKey.remove(item);
    if (removed == false) {
        return null;
    }
    // remove the list if it is now empty
    // (saves space, and allows equals to work)
    if (valuesForKey.isEmpty()) {
        remove(key);
    }
    return item;
}

From source file:org.eclipse.emf.emfstore.internal.client.ui.dialogs.admin.GroupComposite.java

/**
 * This will be used when adding a new member using add button. It shows a
 * list of ACOrgUnits on the server./*from w w w  . j a v  a  2  s . c om*/
 * 
 * @return selected elements
 */
private EList<ACOrgUnit> getNewMembers() {
    // 1. show a list of all AcOrgUnits that are not member of this group
    // (get list of all AcOrgUnits, remove those who take part in this
    // 2. return the selected ACOrgunits

    final Collection<ACOrgUnit> allOrgUnits = new BasicEList<ACOrgUnit>();
    final EList<ACOrgUnit> members = new BasicEList<ACOrgUnit>();
    try {
        allOrgUnits.addAll(getAdminBroker().getOrgUnits());
        allOrgUnits.removeAll(getAdminBroker().getMembers(group.getId()));
        if (allOrgUnits.contains(group)) {
            allOrgUnits.remove(group);
        }

        final Object[] result = showDialog(allOrgUnits, Messages.GroupComposite_Select_Member);

        for (int i = 0; i < result.length; i++) {
            if (result[i] instanceof ACOrgUnit) {
                members.add((ACOrgUnit) result[i]);
            }
        }
    } catch (final ESException e) {
        // ZH Auto-generated catch block
        e.printStackTrace();
    }
    return members;
}

From source file:com.smartitengineering.cms.api.impl.type.ContentTypeImpl.java

public void removeContentCoProcessorDef(ContentCoProcessorDef def) {
    ContentProcessingPhase phase = def.getPhase();
    if (phase == null) {
        throw new NullPointerException();
    }/*from w w  w .j a va 2s.com*/
    Collection<ContentCoProcessorDef> collection = procDefs.get(phase);
    if (collection == null) {
        return;
    }
    collection.remove(def);
}

From source file:org.sonatype.nexus.plugin.obr.test.metadata.ObrResourceWriterTest.java

@Test
public void testObrSerializing() throws Exception {
    final ObrSite testSite = openObrSite(testRepository, "/obr/samples/osgi_alliance_obr.zip");

    final RepositoryItemUid uid = testRepository.createUid("/obr/repository.xml");

    ObrResourceReader reader = obrMetadataSource.getReader(testSite);
    final ObrResourceWriter writer = obrMetadataSource.getWriter(uid);

    final Collection<Resource> bundles = new ArrayList<Resource>();

    Resource r;// w ww.java 2 s.  c  o m
    while ((r = reader.readResource()) != null) {
        bundles.add(r);
        writer.append(r);
        writer.flush();
    }

    assertEquals(2710, bundles.size());

    writer.complete();
    writer.close();

    reader = obrMetadataSource.getReader(openObrSite(uid));
    while ((r = reader.readResource()) != null) {
        assertTrue(bundles.remove(r));
    }

    assertEquals(Collections.emptyList(), bundles);
}

From source file:chibi.gemmaanalysis.cli.deprecated.BioSequenceCleanupCli.java

@Override
protected Exception doWork(String[] args) {

    Exception err = processCommandLine(args);
    if (err != null)
        return err;

    Collection<ArrayDesign> ads = new HashSet<ArrayDesign>();
    if (!this.arrayDesignsToProcess.isEmpty()) {
        ads.addAll(this.arrayDesignsToProcess);
    } else if (file != null) {
        try (InputStream is = new FileInputStream(file);
                BufferedReader br = new BufferedReader(new InputStreamReader(is));) {

            String id = null;/*  www  .  ja  v  a 2s . c  om*/
            Collection<Long> ids = new HashSet<Long>();
            while ((id = br.readLine()) != null) {
                if (StringUtils.isBlank(id)) {
                    continue;
                }
                ids.add(Long.parseLong(id));
            }

            Collection<BioSequence> bioSequences = bss.loadMultiple(ids);
            bioSequences = bss.thaw(bioSequences);
            processSequences(bioSequences);
            return null;
        } catch (Exception e) {
            return e;
        }
    } else {
        ads = this.arrayDesignService.loadAll();
    }

    for (ArrayDesign design : ads) {
        log.info(design);
        design = unlazifyArrayDesign(design);

        Collection<BioSequence> bioSequences = new HashSet<BioSequence>();

        for (CompositeSequence cs : design.getCompositeSequences()) {
            if (cs == null)
                continue;
            if (cs.getBiologicalCharacteristic() == null)
                continue;
            bioSequences.add(cs.getBiologicalCharacteristic());
        }

        processSequences(bioSequences); // fast.

        log.info("Phase II starting");

        // ///////////////////////////////
        // Second phase: make sure composite sequences don't refer to sequences that have duplicates based on name,
        // using stricter equality criteria.
        int i = 0;
        for (CompositeSequence cs : design.getCompositeSequences()) {

            if (++i % 500 == 0) {
                log.info("Processing: " + i + "/" + bioSequences.size() + " sequences");
            }

            BioSequence anchorSeq = cs.getBiologicalCharacteristic();
            if (anchorSeq == null) {
                continue;
            }
            Collection<BioSequence> seqs = bss.findByName(anchorSeq.getName());

            // no evidence of duplicates?
            if (seqs.size() == 1) {
                continue;
            }

            seqs.remove(anchorSeq);

            seqs = this.bss.thaw(seqs);

            // ensure this group really does contain all duplicates.
            if (log.isDebugEnabled())
                log.debug("Examining set of " + seqs.size() + " possible duplicates of " + anchorSeq);

            Collection<BioSequence> notDuplicate = new HashSet<BioSequence>();
            for (BioSequence candidateForRemoval : seqs) {
                if (log.isDebugEnabled())
                    log.debug("   Examining: " + candidateForRemoval);
                assert !candidateForRemoval.equals(anchorSeq) : candidateForRemoval + " equals " + anchorSeq;
                if (!this.equals(anchorSeq, candidateForRemoval)) {
                    notDuplicate.add(candidateForRemoval);
                } else {
                    if (log.isDebugEnabled())
                        log.debug("    Duplicate: " + anchorSeq + " " + candidateForRemoval);
                }
            }

            seqs.removeAll(notDuplicate);

            for (BioSequence toChange : seqs) {
                if (log.isDebugEnabled())
                    log.debug("Processing " + toChange);
                if (!this.equals(anchorSeq, toChange)) {
                    throw new IllegalStateException(
                            "Sequences weren't equal " + anchorSeq + " and " + toChange);
                }
                switchAndDeleteExtra(anchorSeq, toChange);

            }
        }
    }

    return null;

}

From source file:com.bloomreach.bstore.highavailability.actions.CloneCollectionsAction.java

/**
 * If "all" is being passed as the collections, it assumes all the collections are needed.
 * However we give the ability to filter out collections based on any criteria
 * If streamFilter is passed, it allows collections only based on that.
 * If exclusionFilter is passed, it allows collections excluding that.
 * It filters out collection1 by default
 *
 * @param operationalCollections/*w  ww  .  j a  v a  2s  . c  om*/
 * @return {@link Collection<String>} of collections fitting the criteria
 * @return
 */
private Collection<String> findClonableCollectionSet(List<String> operationalCollections) {
    Collection<String> collectionNames;
    if (operationalCollections.get(0).equalsIgnoreCase("all")) {

        Collection<String> finalCollectionNames = new ArrayList<String>();
        // Build all  collections need to be streamed to destination
        collectionNames = sourceZKClient.getZkClusterData().getCollections();
        collectionNames.remove("collection1");
        boolean dirty = false;
        for (String collName : collectionNames) {
            if (StringUtils.isNotBlank(config.getStreamFilter())
                    || StringUtils.isNotBlank(config.getExclusionPattern())) {
                dirty = true;
            }
            //Add all collections matching a certain pattern
            if (StringUtils.isNotBlank(config.getStreamFilter())
                    && collName.contains(config.getStreamFilter())) {
                logger.info("Adding " + collName + " since it matches  pattern " + config.getStreamFilter());
                finalCollectionNames.add(collName);
            }

            //Remove all collections matching Exclusion Pattern
            if (StringUtils.isNotBlank(config.getExclusionPattern())
                    && collName.contains(config.getExclusionPattern())) {
                logger.info("Skipping " + collName + " since it matches exclusion pattern "
                        + config.getExclusionPattern());
                finalCollectionNames.remove(collName);
            }

        }
        if (dirty) {
            collectionNames = finalCollectionNames;
        }
    } else {
        collectionNames = operationalCollections;
    }
    return collectionNames;
}