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:de.mogwai.common.web.component.renderkit.html.input.CheckboxListRenderer.java

@Override
@SuppressWarnings("all")
public void decode(FacesContext aContext, UIComponent aComponent) {

    CheckboxListComponent theComponent = (CheckboxListComponent) aComponent;

    if (isDisabledOrReadOnly(theComponent)) {
        return;/* ww w. j  a va2s. com*/
    }

    Collection theSelectedItems = (Collection) theComponent.getValue();
    if (theSelectedItems != null) {
        Map theParamMap = aContext.getExternalContext().getRequestParameterMap();

        List theValues = theComponent.getValues();
        if (theValues != null) {
            for (int count = 0; count < theValues.size(); count++) {

                Object theEntry = theValues.get(count);

                Object theCompareValue = theEntry;
                if (theCompareValue instanceof ObjectProvider) {
                    theCompareValue = ((ObjectProvider) theCompareValue).getProvidedObject();
                }

                String theClientID = aComponent.getClientId(aContext) + "::" + count;

                if (theParamMap.containsKey(theClientID)) {
                    if (!theSelectedItems.contains(theCompareValue)) {
                        theSelectedItems.add(theCompareValue);
                    }
                } else {
                    theSelectedItems.remove(theCompareValue);
                }
            }
        }

        theComponent.setSubmittedValue(theSelectedItems);
    }

    super.decode(aContext, aComponent);
}

From source file:org.kuali.rice.krad.maintenance.MaintainableImpl.java

/**
 * Determines if the current group contains restricted lines and clears them if so.
 *
 * @param view view instance that contains the group being checked
 * @param model model instance that contains the group being checked
 * @param group group being checked for restrictions
 */// w ww  . j  a v a  2s . c o  m
private void clearUnauthorizedLine(View view, ViewModel model, CollectionGroup group) {
    String bindingPath = group.getBindingInfo().getBindingPath();

    if (StringUtils.contains(bindingPath, KRADConstants.MAINTENANCE_NEW_MAINTAINABLE)) {
        // A line is restricted if it is hidden or read only
        if (group.getUnauthorizedLineBindingInfos() != null) {
            Collection<Object> collection = ObjectPropertyUtils.getPropertyValue(model, bindingPath);

            // If any lines are restricted, clear them out
            for (BindingInfo bindingInfo : group.getUnauthorizedLineBindingInfos()) {
                String lineBindingPath = bindingInfo.getBindingPath();
                Object line = ObjectPropertyUtils.getPropertyValue(model, lineBindingPath);

                collection.remove(line);
            }
        }
    }
}

From source file:org.springframework.data.redis.listener.RedisMessageListenerContainer.java

private void remove(MessageListener listener, Topic topic, ByteArrayWrapper holder,
        Map<ByteArrayWrapper, Collection<MessageListener>> mapping, List<byte[]> topicToRemove) {

    Collection<MessageListener> listeners = mapping.get(holder);
    Collection<MessageListener> listenersToRemove = null;

    if (listeners != null) {
        // remove only one listener
        if (listener != null) {
            listeners.remove(listener);
            listenersToRemove = Collections.singletonList(listener);
        }//from   w w  w  .  j  a va2s . c om

        // no listener given - remove all of them
        else {
            listenersToRemove = listeners;
        }

        // start removing listeners
        for (MessageListener messageListener : listenersToRemove) {
            Set<Topic> topics = listenerTopics.get(messageListener);
            if (topics != null) {
                topics.remove(topic);
            }
            if (CollectionUtils.isEmpty(topics)) {
                listenerTopics.remove(messageListener);
            }
        }
        // if we removed everything, remove the empty holder collection
        if (listener == null || listeners.isEmpty()) {
            mapping.remove(holder);
            topicToRemove.add(holder.getArray());
        }
    }
}

From source file:ch.entwine.weblounge.contentrepository.fs.FileSystemContentRepositoryTest.java

/**
 * Test method for/*from   www . j  a v a  2 s.c o m*/
 * {@link ch.entwine.weblounge.contentrepository.impl.AbstractWritableContentRepository#list(ch.entwine.weblounge.common.content.ResourceURI)}
 * .
 * 
 * @throws IOException
 * @throws IllegalStateException
 */
@Test
public void testListResources() throws ContentRepositoryException, IllegalStateException, IOException {
    ResourceSelector selector = new ResourceSelectorImpl(site);
    Collection<String> uris = new ArrayList<String>();
    for (Resource<?> r : pages) {
        uris.add(r.getURI().getIdentifier());
    }
    uris.add(jpeg.getURI().getIdentifier());
    uris.add(file.getURI().getIdentifier());

    populateRepository();
    for (ResourceURI uri : repository.list(selector)) {
        uris.remove(uri.getIdentifier());
    }
    assertTrue(uris.isEmpty());
}

From source file:org.alfresco.repo.audit.AuditComponentImpl.java

private <V> Collection<V> trimStringsIfNecessary(Collection<V> values) {
    Collection<V> processed = values;

    for (V auditValue : values) {
        if (auditValue != null) {
            V processedAuditValue = trimStringsIfNecessary(auditValue);

            if (processedAuditValue != auditValue && !auditValue.equals(processedAuditValue)) {
                if (processed == values) {
                    // defensive copy
                    processed = new HashSet<V>(values);
                }// ww  w.  ja va2s  . co  m
                processed.remove(auditValue);
                processed.add(processedAuditValue);
            }
        }
    }

    return processed;
}

From source file:org.agnitas.web.MailingBaseAction.java

/**
 * Removes target group from the list of chosen targets.
 *
 * @param aForm  MailingBaseForm object//  w  w w  . ja  v a2s  .  c  om
 * @param req request
 * @throws Exception
 */
protected void removeTarget(MailingBaseForm aForm, HttpServletRequest req) throws Exception {
    Collection<Integer> allTargets = aForm.getTargetGroups();
    Integer tmpInt = null;

    if (allTargets != null) {
        Iterator<Integer> aIt = allTargets.iterator();
        while (aIt.hasNext()) {
            tmpInt = aIt.next();
            if (aForm.getTargetID() == tmpInt.intValue()) {
                allTargets.remove(tmpInt);
                break;
            }
        }
    }

    if (allTargets.isEmpty()) {
        aForm.setTargetGroups(null);
    }
}

From source file:org.nabucco.alfresco.enhScriptEnv.common.script.registry.VersionRegisterableScriptClasspathScanner.java

/**
 * Matches and processes a folder level defining a specific edition of alfresco a script is applicable to.
 *
 * @param resourcePattern/*w ww. ja  va 2s . c om*/
 *            the resource pattern for the current level
 * @param patternStack
 *            the stack of patterns evaluated thus far
 * @param versionDataContainer
 *            the container for collection version information
 * @param subRegistry
 *            the sub-registry to register the script in or {@code null} if no sub-registry is to be used
 * @param fileName
 *            the name of the file currently evaluated
 * @throws IOException
 *             if any exception occurs handling the resource
 */
protected void matchEdition(final String resourcePattern, final Collection<String> patternStack,
        final VersionRegisterableScriptAdapter<Script> versionDataContainer, final String subRegistry,
        final String fileName) throws IOException {
    final Boolean community;
    if ("community".equalsIgnoreCase(fileName)) {
        community = Boolean.TRUE;
        LOGGER.debug("Matched COMMUNITY edition fragment");
    } else if ("enterprise".equalsIgnoreCase(fileName)) {
        community = Boolean.FALSE;
        LOGGER.debug("Matched ENTERPRISE edition fragment");
    } else {
        community = null;
        LOGGER.debug("Matched edition agnostic fragment");
    }

    versionDataContainer.setForCommunity(community);
    patternStack.add(EDITION_PATTERN);
    try {
        this.scanNextLevel(resourcePattern + "/" + fileName, patternStack, versionDataContainer, subRegistry);
    } finally {
        versionDataContainer.setForCommunity(null);
        patternStack.remove(EDITION_PATTERN);
    }
}

From source file:org.intermine.api.profile.InterMineBag.java

/**
 * Add the given ids to the bag, this updates the bag contents in the database.  The type can
 * be a qualified or un-qualified class name.
 * @param ids the ids to add/*from  ww w .  j av  a 2  s .c  om*/
 * @param type the type of ids being added
 * @throws ObjectStoreException
 *             if problem storing
 */
public void addIdsToBag(Collection<Integer> ids, String type) throws ObjectStoreException {
    if (!isOfType(type)) {
        throw new IncompatibleTypesException("Cannot add type " + type + " to bag of type " + getType() + ".");
    }
    if (profileId != null) {
        //we add only the ids not already contained
        Collection<Integer> idsContained = getIdsContained(ids);
        for (Integer idContained : idsContained) {
            ids.remove(idContained);
        }
        if (!ids.isEmpty()) {
            addBagValuesFromIds(ids);
        }
    }
    ObjectStoreWriter oswProduction = null;
    try {
        oswProduction = os.getNewWriter();
        oswProduction.addAllToBag(osb, ids);
    } finally {
        if (oswProduction != null) {
            oswProduction.close();
        }
    }
}

From source file:ubic.gemma.core.loader.expression.ExpressionExperimentPlatformSwitchService.java

/**
 * Find the bioassaydimension that covers all the biomaterials.
 * /*from   w  ww.  java 2 s  .  c o m*/
 * @param ee
 * @param unusedBADs
 * @return
 */
private BioAssayDimension doMultiSample(ExpressionExperiment ee, Collection<BioAssayDimension> unusedBADs) {

    int maxSize = 0;
    BioAssayDimension maxBAD = null;
    for (BioAssay ba : ee.getBioAssays()) {
        Collection<BioAssayDimension> oldBioAssayDims = bioAssayService.findBioAssayDimensions(ba);
        for (BioAssayDimension bioAssayDim : oldBioAssayDims) {
            unusedBADs.add(bioAssayDim);
            int size = bioAssayDim.getBioAssays().size();

            if (size > maxSize) {
                maxSize = size;
                maxBAD = bioAssayDim;
            }
        }
    }

    assert unusedBADs.size() > 1; // otherwise we shouldn't be here.
    unusedBADs.remove(maxBAD);

    /*
     * Make sure all biomaterials in the study are included in the chosen bioassaydimension. If not, we'd have
     * to make a new BAD. I haven't implemented that case.
     */
    if (maxBAD != null) {
        Collection<BioMaterial> bmsInmaxBAD = new HashSet<>();
        for (BioAssay ba : maxBAD.getBioAssays()) {
            bmsInmaxBAD.add(ba.getSampleUsed());
        }

        for (BioAssay ba : ee.getBioAssays()) {
            if (!bmsInmaxBAD.contains(ba.getSampleUsed())) {

                ExpressionExperimentPlatformSwitchService.log
                        .warn("This experiment looked like it had samples run on more than one platform, "
                                + "but it also has no BioAssayDimension that is eligible to accomodate all samples (Example: "
                                + ba.getSampleUsed());
                maxBAD = null;
                break;
            }
        }

    }
    return maxBAD;
}