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:graph.module.DepthModule.java

private Collection<Node> getMinimumParents(DAGNode node) {
    // Check for rewrite
    RewriteOfModule rewriteModule = (RewriteOfModule) dag_.getModule(RewriteOfModule.class);
    if (rewriteModule != null)
        node = rewriteModule.getRewrite(node);

    QueryModule querier = (QueryModule) dag_.getModule(QueryModule.class);

    Collection<Node> minParents = new ArrayList<>();

    // Add genls/*  w w w.  j a va2s.c  o m*/
    minParents.addAll(checkParentRelationship(node, CommonConcepts.GENLS, querier));

    // Add isa
    minParents.addAll(checkParentRelationship(node, CommonConcepts.ISA, querier));

    // Add genlPreds
    minParents.addAll(checkParentRelationship(node, CommonConcepts.GENLPREDS, querier));

    // Add genlMt
    minParents.addAll(checkParentRelationship(node, CommonConcepts.GENLMT, querier));

    // If function
    if (node instanceof OntologyFunction) {
        // Add resultIsa
        minParents.addAll(querier.functionResults((OntologyFunction) node, CommonConcepts.RESULT_ISA));

        // Add resultGenls
        minParents.addAll(querier.functionResults((OntologyFunction) node, CommonConcepts.RESULT_GENL));
    }

    minParents.remove(node);
    return CommonQuery.minGeneralFilter(minParents, dag_);
}

From source file:org.alfresco.repo.dictionary.DictionaryDAOImpl.java

private Collection<ConstraintDefinition> getReferenceableConstraintDefs(CompiledModel model) {
    Collection<ConstraintDefinition> conDefs = model.getConstraints();
    Collection<PropertyDefinition> propDefs = model.getProperties();
    for (PropertyDefinition propDef : propDefs) {
        for (ConstraintDefinition conDef : propDef.getConstraints()) {
            conDefs.remove(conDef);
        }//  ww w  .j  av a2 s  .c o  m
    }

    return conDefs;
}

From source file:org.nuclos.server.genericobject.ejb3.GenericObjectFacadeHelper.java

public static Map<Integer, DynamicAttributeVO> getHistoricalAttributes(GenericObjectVO govo,
        Date dateHistorical, final DependantMasterDataMap mpDependantsResult) {

    final Map<Integer, DynamicAttributeVO> result = CollectionUtils.newHashMap();
    for (DynamicAttributeVO attrvo : govo.getAttributes()) {
        result.put(attrvo.getAttributeId(), attrvo);
    }//from  w  w  w .j a  v a  2s. co  m

    DbQueryBuilder builder = SpringDataBaseHelper.getInstance().getDbAccess().getQueryBuilder();
    DbQuery<DbTuple> query = builder.createTupleQuery();
    DbFrom t = query.from("T_UD_LOGBOOK").alias(SystemFields.BASE_ALIAS);
    query.multiselect(t.baseColumn("INTID_T_MD_ATTRIBUTE", Integer.class), // 0
            t.baseColumn("INTID_T_DP_VALUE_OLD", Integer.class), // 1
            t.baseColumn("INTID_EXTERNAL_OLD", Integer.class), // 2
            t.baseColumn("STRVALUE_OLD", String.class), // 3
            t.baseColumn("INTID_MD_EXTERNAL", Integer.class), // 4
            t.baseColumn("STRMD_ACTION", String.class), // 5
            t.baseColumn("INTID_T_AD_MASTERDATA", Integer.class), // 6
            t.baseColumn("INTID_T_AD_MD_FIELD", Integer.class)); // 7
    query.where(
            builder.and(builder.equal(t.baseColumn("INTID_T_UD_GENERICOBJECT", Integer.class), govo.getId()),
                    builder.greaterThanOrEqualTo(t.baseColumn("DATCREATED", InternalTimestamp.class),
                            builder.literal(InternalTimestamp.toInternalTimestamp(dateHistorical)))));
    query.orderBy(builder.desc(t.baseColumn("DATCREATED", InternalTimestamp.class)));

    for (DbTuple tuple : SpringDataBaseHelper.getInstance().getDbAccess().executeQuery(query)) {
        try {
            final Integer iAttributeId = tuple.get(0, Integer.class);
            // If the value of an existing attribute (not generated by a migration) is given...            
            if (iAttributeId != null) {
                try {
                    AttributeCache.getInstance().getAttribute(iAttributeId);
                } catch (NuclosAttributeNotFoundException e) {
                    // Attribute was deleted
                    LOG.debug("getHistoricalAttributes: " + e);
                    continue;
                }
                final Integer iValueId = (tuple.get(1) != null) ? tuple.get(1, Integer.class)
                        : tuple.get(2, Integer.class);
                final String sValue = tuple.get(3, String.class);
                DynamicAttributeVO loavo = result.get(iAttributeId);
                if (loavo != null) {
                    loavo.setValueId(iValueId);
                    loavo.setCanonicalValue(sValue, AttributeCache.getInstance());
                } else {
                    loavo = DynamicAttributeVO.createGenericObjectAttributeVOCanonical(iAttributeId, iValueId,
                            sValue, AttributeCache.getInstance());
                }
                result.put(iAttributeId, loavo);
            } else {
                // If a change in a subform entry is given...
                final Integer iMasterDataRecordId = tuple.get(4, Integer.class);
                if (iMasterDataRecordId != null) {
                    final String sAction = tuple.get(5, String.class);
                    final Integer iMasterDataMetaId = tuple.get(6, Integer.class);
                    final Integer iMasterDataMetaFieldId = tuple.get(7, Integer.class);
                    //final Integer iRecordId = Helper.getInteger(rs, "intid_md_external");

                    final MasterDataMetaVO mdmetavo = MasterDataMetaCache.getInstance()
                            .getMetaDataById(iMasterDataMetaId);
                    final String sEntity = mdmetavo.getEntityName();
                    final MasterDataMetaFieldVO mdmetafieldvo = mdmetavo.getFieldById(iMasterDataMetaFieldId);
                    final String sField = mdmetafieldvo.getFieldName();
                    final String sValue = tuple.get(3, String.class);

                    final Collection<EntityObjectVO> collmdvo = mpDependantsResult.getData(sEntity);

                    // Find the masterdata cvo in the dependencies if possible
                    EntityObjectVO mdvo = null;
                    for (EntityObjectVO mdvo1 : collmdvo) {
                        if (iMasterDataRecordId.equals(IdUtils.toLongId(mdvo1.getId()))) {
                            mdvo = mdvo1;
                            break;
                        }
                    }

                    if ("D".equals(sAction)) {
                        // Entry has been deleted and must be recreated before value can be set
                        if (mdvo == null) {
                            mdvo = new EntityObjectVO();
                            mdvo.setId(IdUtils.toLongId(iMasterDataRecordId));
                            mpDependantsResult.addData(sEntity, mdvo);
                        }
                        mdvo.getFields().put(sField, sValue);
                    } else if ("C".equals(sAction)) {
                        // Entry has been newly created and has simply to be deleted
                        if (mdvo != null) {
                            mpDependantsResult.removeKey(sEntity);
                            collmdvo.remove(mdvo);
                            mpDependantsResult.addAllData(sEntity, collmdvo);
                        }
                    } else if ("M".equals(sAction)) {
                        // Existing entry has just been modified
                        if (mdvo != null) { //ought to be always so with this action
                            mdvo.getFields().put(sField, sValue);
                        }
                    }
                }
                // else it must be a migrated value and can be ignored here
            }
        } catch (CommonValidationException ex) {
            throw new NuclosFatalException(ex);
        }
    }

    return result;
}

From source file:org.infoscoop.request.filter.GadgetViewFilter.java

private byte[] processViewTransform(Document module, String viewType) throws Exception {
    NodeList nodeList = module.getElementsByTagName("Maximize");
    while (nodeList.getLength() > 0) {
        nodeList.item(0).getParentNode().removeChild(nodeList.item(0));
        nodeList = module.getElementsByTagName("Maximize");
    }//from w  w w.  j a  v  a 2 s .c om

    nodeList = module.getElementsByTagName("Content");
    Collection contents = new ArrayList();
    for (int i = 0; i < nodeList.getLength(); i++)
        contents.add(nodeList.item(i));

    Element matches = null;
    for (Iterator ite = contents.iterator(); ite.hasNext();) {
        Element content = (Element) ite.next();
        if ("Maximize".equals(((Element) content.getParentNode()).getTagName()))
            continue;

        if (matches == null)
            matches = content;

        if (content.hasAttribute("view") && !"".equals(content.getAttribute("view"))) {
            if (content.getAttribute("view").toLowerCase().indexOf(viewType) >= 0) {
                matches = content;
                break;
            } else if ("home".equalsIgnoreCase(content.getAttribute("view"))) {
                matches = content;
            }
        } else {
            matches = content;
        }
    }

    contents.remove(matches);
    for (Iterator ite = contents.iterator(); ite.hasNext();) {
        Element content = (Element) ite.next();

        content.getParentNode().removeChild(content);
    }

    ByteArrayOutputStream respOut = new ByteArrayOutputStream();
    try {
        Transformer trans = TransformerFactory.newInstance().newTransformer();
        trans.transform(new DOMSource(module), new StreamResult(respOut));
    } catch (Exception ex) {
        throw ex;
    } finally {
        respOut.close();
    }

    return respOut.toByteArray();
}

From source file:uk.co.modularaudio.util.audio.mad.graph.GraphIOLinkMap.java

public void unmapConsumerChannel(final MadChannelInstance graphChannelInstance,
        final MadChannelInstance channelInstanceExposed)
        throws RecordNotFoundException, MAConstraintViolationException {
    final Collection<MadChannelInstance> mcis = graphConsumerChannelToMadChannelInstanceMap
            .get(graphChannelInstance);/*from   w  w w . j  a  v  a 2s.co m*/

    if (RUNTIME_CHECKING) {
        if (!graphConsumerChannelToMadChannelInstanceMap.containsKey(graphChannelInstance)) {
            throw new RecordNotFoundException("Consumer channel unmapping failed as not mapped");
        }

        if (mcis == null || !mcis.contains(channelInstanceExposed)) {
            throw new MAConstraintViolationException("Consumer channel unmapping failed to find existing map");
        }

        if (!madChannelInstanceToGraphConsumerMap.containsKey(channelInstanceExposed)) {
            throw new MAConstraintViolationException(
                    "Consumer channel unmapping failed to find specific channel");
        }
    }

    mcis.remove(channelInstanceExposed);
    if (mcis.size() == 0) {
        graphConsumerChannelToMadChannelInstanceMap.remove(graphChannelInstance);
    }

    madChannelInstanceToGraphConsumerMap.remove(channelInstanceExposed);

    //      log.debug("Unmapped graph consumer channel \"" + graphChannelInstance.toString() + "\" to ");
    //      log.debug( channelInstanceExposed.instance.getInstanceName() + " \"" +
    //            channelInstanceExposed.toString() + "\"");
}

From source file:com.nextep.designer.vcs.services.impl.DependencyService.java

@Override
public Collection<IReferencer> getReferencersAfterDeletion(IReferenceable ref, Collection<IReferencer> deps,
        Collection<IReferencer> deletedReferencers) {
    // Copying collection because we will alter it
    Collection<IReferencer> dependencies = new ArrayList<IReferencer>(deps);
    if (dependencies != null && dependencies.size() > 0) {
        // If the removed object is a reference container, we remove dependencies
        // which are declared by the removed object. Only to allow removal of objects
        // which have only dependencies to themselves.
        if (ref instanceof IReferenceContainer) {
            Collection<IReference> declaredRefs = new ArrayList<IReference>();
            declaredRefs.addAll(((IReferenceContainer) ref).getReferenceMap().keySet());
            declaredRefs.add(ref.getReference());
            for (IReferencer depRef : new ArrayList<IReferencer>(dependencies)) {
                if (depRef instanceof IReferenceable
                        && declaredRefs.contains(((IReferenceable) depRef).getReference())) {
                    dependencies.remove(depRef);
                }//from   ww w .j  a v a  2s  . co  m
                // Also removing residual container references
                if (depRef instanceof ITypedObject && ((ITypedObject) depRef).getType() == IElementType
                        .getInstance(IVersionContainer.TYPE_ID)) {
                    dependencies.remove(depRef);
                }
            }
        }
        dependencies.removeAll(deletedReferencers);
        // Removing encapsulating dependencies:
        // A table containing a FK will generate 2 dependencies, one from the table, the
        // other from the FK
        // For all remaining dependencies
        for (IReferencer r : new ArrayList<IReferencer>(dependencies)) {
            // If one is a container of referenceable instances
            if (r instanceof IReferenceContainer) {
                // Then we check if this instance is one of the deleted referencers,
                // in which case we "assume"
                // that the upper dependency is no longer valid
                final Collection<IReferenceable> containedItems = ((IReferenceContainer) r).getReferenceMap()
                        .values();
                for (IReferenceable item : containedItems) {
                    if (deletedReferencers.contains(item)) {
                        dependencies.remove(r);
                    }
                    if (dependencies.contains(item)) {
                        dependencies.remove(r);
                    }
                }
            }
        }
    }
    return dependencies;
}

From source file:uk.ac.ebi.intact.editor.services.curate.complex.ComplexEditorService.java

private void initialiseParticipants(Complex parent, Collection<ModelledParticipant> participants) {
    List<ModelledParticipant> originalParticipants = new ArrayList<ModelledParticipant>(participants);
    ModelledParticipantCloner participantCloner = new ModelledParticipantCloner();
    ModelledFeatureCloner featureCloner = new ModelledFeatureCloner();
    uk.ac.ebi.intact.editor.controller.curate.cloner.InteractorCloner interactorCloner = new uk.ac.ebi.intact.editor.controller.curate.cloner.InteractorCloner();
    for (ModelledParticipant det : originalParticipants) {
        ModelledParticipant p = initialiseParticipant(det, interactorCloner, featureCloner, participantCloner);
        if (p != det) {
            participants.remove(det);
            parent.addParticipant(p);/*from ww w  .  j  a va 2 s .  c o  m*/
        }
    }
}

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

/**
 * In the case of edit maintenance deleted the item on the old side.
 *
 * @see org.kuali.rice.krad.uif.service.impl.ViewHelperServiceImpl#processAfterDeleteLine(org.kuali.rice.krad.uif.view.ViewModel, String, String, int)
 *//*from w  ww  . j a va2  s. co m*/
@Override
public void processAfterDeleteLine(ViewModel model, String collectionId, String collectionPath, int lineIndex) {
    super.processAfterDeleteLine(model, collectionId, collectionPath, lineIndex);

    Class<?> collectionObjectClass = (Class<?>) model.getViewPostMetadata().getComponentPostData(collectionId,
            UifConstants.PostMetadata.COLL_OBJECT_CLASS);

    // Check for maintenance documents in edit but exclude notes and ad hoc recipients
    if (model instanceof MaintenanceDocumentForm
            && KRADConstants.MAINTENANCE_EDIT_ACTION
                    .equals(((MaintenanceDocumentForm) model).getMaintenanceAction())
            && !collectionObjectClass.getName().equals(Note.class.getName())
            && !collectionObjectClass.getName().equals(AdHocRoutePerson.class.getName())
            && !collectionObjectClass.getName().equals(AdHocRouteWorkgroup.class.getName())) {
        MaintenanceDocumentForm maintenanceForm = (MaintenanceDocumentForm) model;
        MaintenanceDocument document = maintenanceForm.getDocument();

        BindingInfo bindingInfo = (BindingInfo) model.getViewPostMetadata().getComponentPostData(collectionId,
                UifConstants.PostMetadata.BINDING_INFO);

        // get the old object's collection
        //KULRICE-7970 support multiple level objects
        String bindingPrefix = bindingInfo.getBindByNamePrefix();
        String propertyPath = bindingInfo.getBindingName();
        if (bindingPrefix != "" && bindingPrefix != null) {
            propertyPath = bindingPrefix + "." + propertyPath;
        }

        Collection<Object> oldCollection = ObjectPropertyUtils
                .getPropertyValue(document.getOldMaintainableObject().getDataObject(), propertyPath);

        try {
            // Remove the object at lineIndex from the collection
            oldCollection.remove(oldCollection.toArray()[lineIndex]);
        } catch (Exception e) {
            throw new RuntimeException("Unable to delete line instance for old maintenance object", e);
        }
    }
}

From source file:lu.lippmann.cdb.graph.GraphUtil.java

/**
 * FIXME : 0,0 for counters and no variables
 * //from  w  ww.j a va 2  s  . com
 * @param g1
 * @param g2
 * @return
 */
public static List<GraphOperation> diff(final CUser user, final Graph<CNode, CEdge> g1,
        final Graph<CNode, CEdge> g2) {
    final List<GraphOperation> res = new ArrayList<GraphOperation>();
    final Collection<CNode> nodes1 = g1.getVertices();
    final Collection<CNode> toBeRemoved = new ArrayList<CNode>(nodes1);
    final Collection<CNode> nodes2 = g2.getVertices();
    final Collection<CNode> toBeAdded = new ArrayList<CNode>(nodes2);
    final Collection<CEdge> edges1 = g1.getEdges();
    final Collection<CEdge> edgesToBeRemoved = new ArrayList<CEdge>(g1.getEdges());
    final Collection<CEdge> edges2 = g2.getEdges();
    final Collection<CEdge> edgesToBeAdded = new ArrayList<CEdge>(g2.getEdges());

    toBeRemoved.removeAll(nodes2);
    toBeAdded.removeAll(nodes1);

    /** removing useless nodes **/
    for (CNode node : toBeRemoved) {
        res.add(new GraphOperation(0, 0, user, Operation.NODE_REMOVED,
                new ArrayList<Object>(Arrays.asList(node))));
    }
    /** adding new nodes **/
    for (CNode node : toBeAdded) {
        res.add(new GraphOperation(0, 0, user, Operation.NODE_ADDED,
                new ArrayList<Object>(Arrays.asList(node))));
    }

    /**
     * removing edges in G1 that are in G2 (with the same id/name/condition)
     **/
    for (CEdge edge : edges2) {
        final CEdge foundEdge = g1.findEdge(g2.getSource(edge), g2.getDest(edge));
        if (foundEdge != null) {
            edgesToBeRemoved.remove(foundEdge);
            if (!edge.containsSameFieldsThat(foundEdge)) {
                res.add(new GraphOperation(0, 0, user, Operation.EDGE_DATA_UPDATED,
                        new ArrayList<Object>(Arrays.asList(foundEdge, foundEdge.getName(), edge.getName(),
                                foundEdge.getExpression(), edge.getExpression(), foundEdge.getTags(),
                                edge.getTags()))));
            }
        }
    }

    /**
     * removing edges in G2 that are in G1 (with the same id/name/condition)
     **/
    for (CEdge edge : edges1) {
        final CEdge foundEdge = g2.findEdge(g1.getSource(edge), g1.getDest(edge));
        if (foundEdge != null) {
            edgesToBeAdded.remove(foundEdge);
        }
    }

    /** removing nodes edges **/
    for (CEdge edge : edgesToBeRemoved) {
        res.add(new GraphOperation(0, 0, user, Operation.EDGE_REMOVED,
                new ArrayList<Object>(Arrays.asList(edge, g2.getSource(edge), g2.getDest(edge)))));
    }

    /** adding usefull edges **/
    for (CEdge edge : edgesToBeAdded) {
        res.add(new GraphOperation(0, 0, user, Operation.EDGE_ADDED,
                new ArrayList<Object>(Arrays.asList(edge, g2.getSource(edge), g2.getDest(edge)))));
    }
    return res;
}