Example usage for org.apache.commons.collections15 MultiMap entrySet

List of usage examples for org.apache.commons.collections15 MultiMap entrySet

Introduction

In this page you can find the example usage for org.apache.commons.collections15 MultiMap entrySet.

Prototype

Set<Map.Entry<K, Collection<V>>> entrySet();

Source Link

Document

Returns a set view of the mappings contained in this map.

Usage

From source file:org.openanzo.combus.realtime.RealtimeUpdatePublisher.java

private void removeDestination(Destination destination) {
    synchronized (datasetTrackers) {
        MultiMap<URI, DestinationDatasetTracker> toRemove = new MultiHashMap<URI, DestinationDatasetTracker>();
        for (Map.Entry<URI, Collection<DestinationDatasetTracker>> entry : datasetTrackers.entrySet()) {
            for (DestinationDatasetTracker tracker : entry.getValue()) {
                if (tracker.getDestination().equals(destination)) {
                    toRemove.put(entry.getKey(), tracker);
                }/*from w  ww  .j  a  v  a2s  .  c o m*/
            }
        }
        for (Map.Entry<URI, Collection<DestinationDatasetTracker>> entry : toRemove.entrySet()) {
            for (DestinationDatasetTracker tracker : entry.getValue()) {
                datasetTrackers.remove(entry.getKey(), tracker);
            }
        }
    }
    synchronized (namedGraphTrackers) {
        MultiMap<URI, DestinationNamedgraphTracker> toRemove = new MultiHashMap<URI, DestinationNamedgraphTracker>();
        for (Map.Entry<URI, Collection<DestinationNamedgraphTracker>> entry : namedGraphTrackers.entrySet()) {
            for (DestinationNamedgraphTracker dest : entry.getValue()) {
                if (dest.getDestination().equals(destination)) {
                    toRemove.put(entry.getKey(), dest);
                }
            }
        }
        for (Map.Entry<URI, Collection<DestinationNamedgraphTracker>> entry : toRemove.entrySet()) {
            for (DestinationNamedgraphTracker dest : entry.getValue()) {
                namedGraphTrackers.remove(entry.getKey(), dest);
            }
        }
    }
}

From source file:org.openanzo.datasource.update.MultiStageUpdatesProcessor.java

private static IUpdates convertStatementsToUpdates(IOperationContext context, boolean bulkUpdate,
        MultiMap<URI, Statement> statements, Collection<Statement> graphTemplate,
        IServerQuadStore serverQuadStore) throws AnzoException {
    IUpdates updates = new Updates(context.getOperationId());
    IUpdateTransaction transaction = new UpdateTransaction(UriGenerator.generateTransactionURI(), 0, null,
            null);//from  w w w  .  ja v  a  2 s  .co m
    updates.getTransactions().add(transaction);
    // the orderedResourceMaps, once filled will have everything in order
    Map<URI, Collection<Statement>> statementMap = new HashMap<URI, Collection<Statement>>();
    Map<URI, Collection<Statement>> metaStatementMap = new HashMap<URI, Collection<Statement>>();
    Collection<Statement> datasetNG = null;
    Collection<Statement> metaDatasetNG = null;

    for (Map.Entry<URI, Collection<Statement>> entry : statements.entrySet()) {
        if (entry.getKey().equals(GRAPHS.METADATA_GRAPHS_DATASET_META)) {
            metaDatasetNG = entry.getValue();
        } else if (entry.getKey().equals(GRAPHS.GRAPHS_DATASET_META)) {
            datasetNG = entry.getValue();
        } else if (UriGenerator.isMetadataGraphUri(entry.getKey())) {
            metaStatementMap.put(entry.getKey(), entry.getValue());
        } else {
            statementMap.put(entry.getKey(), entry.getValue());
        }
    }

    for (Map.Entry<URI, Collection<Statement>> entry : metaStatementMap.entrySet()) {
        URI ngURI = UriGenerator.stripEncapsulatedURI(NAMESPACES.METADATAGRAPH_PREFIX, entry.getKey());
        Collection<Statement> ngStatements = statementMap.remove(ngURI);
        Collection<Statement> ngmdStatements = entry.getValue();
        if (ngStatements == null) {
            ngStatements = new ArrayList<Statement>();
        }

        INamedGraphUpdate ngu = new NamedGraphUpdate(ngURI, null, ngStatements, null, ngmdStatements, null);
        transaction.addNamedGraphUpdate(ngu);
    }
    if (datasetNG != null) {
        Collection<Statement> ngStatements = statementMap.remove(GRAPHS.GRAPHS_DATASET);
        Collection<Statement> ngmdStatements = datasetNG;
        if (ngStatements == null) {
            ngStatements = new ArrayList<Statement>();
        }
        INamedGraphUpdate ngu = new NamedGraphUpdate(GRAPHS.GRAPHS_DATASET, null, ngStatements, null,
                ngmdStatements, null);
        transaction.addNamedGraphUpdate(ngu);
    }
    if (metaDatasetNG != null) {

        Collection<Statement> ngStatements = statementMap.remove(GRAPHS.METADATA_GRAPHS_DATASET);
        Collection<Statement> ngmdStatements = metaDatasetNG;
        if (ngStatements == null) {
            ngStatements = new ArrayList<Statement>();
        }
        INamedGraphUpdate ngu = new NamedGraphUpdate(GRAPHS.METADATA_GRAPHS_DATASET, null, ngStatements, null,
                ngmdStatements, null);
        transaction.addNamedGraphUpdate(ngu);
    }
    for (Map.Entry<URI, Collection<Statement>> entry : statementMap.entrySet()) {
        INamedGraphUpdate ngu = new NamedGraphUpdate(entry.getKey(), null, entry.getValue(),
                new ArrayList<Statement>(), new ArrayList<Statement>(), new ArrayList<Statement>());
        if (!serverQuadStore.containsNamedGraph(entry.getKey()) && graphTemplate != null) {
            URI metaURI = UriGenerator.generateMetadataGraphUri(entry.getKey());
            for (Statement initStatement : graphTemplate) {
                if (initStatement.getSubject().equals(GRAPHS.DEFAULT_GRAPH_TEMPLATE)) {
                    ngu.getMetaAdditions().add(Constants.valueFactory.createStatement(entry.getKey(),
                            initStatement.getPredicate(), initStatement.getObject(), metaURI));
                } else if (initStatement.getSubject().equals(GRAPHS.DEFAULT_METADATA_GRAPH_TEMPLATE)) {
                    ngu.getMetaAdditions().add(Constants.valueFactory.createStatement(metaURI,
                            initStatement.getPredicate(), initStatement.getObject(), metaURI));
                } else if (initStatement.getSubject().equals(GRAPHS.DEFAULT_METADATA_GRAPH_TEMPLATE)) {
                    ngu.getMetaAdditions().add(Constants.valueFactory.createStatement(metaURI,
                            initStatement.getPredicate(), initStatement.getObject(), metaURI));
                }
            }
            ngu.getMetaAdditions().add(
                    Constants.valueFactory.createStatement(entry.getKey(), RDF.TYPE, NamedGraph.TYPE, metaURI));
            ngu.getMetaAdditions().add(Constants.valueFactory.createStatement(entry.getKey(),
                    NamedGraph.hasMetadataGraphProperty, metaURI, metaURI));
        }
        transaction.addNamedGraphUpdate(ngu);
    }

    return updates;
}

From source file:org.openanzo.rdf.utils.MultiTreeMap.java

/**
 * Constructor that copies the input MultiMap creating an independent copy.
 * <p/>//from www.  ja v  a 2  s. c o  m
 * Each internal collection is also cloned.
 * <p/>
 * NOTE: From Commons Collections 3.1 this method correctly copies a MultiMap to form a truly independent new map.
 * 
 * @param mapToCopy
 *            a Map to copy
 */
public MultiTreeMap(MultiMap<K, V> mapToCopy) {
    this();
    for (Iterator<Map.Entry<K, Collection<V>>> it = mapToCopy.entrySet().iterator(); it.hasNext();) {
        Map.Entry<K, Collection<V>> entry = it.next();
        Collection<V> coll = entry.getValue();
        Collection<V> newColl = createCollection(coll);
        internalMap.put(entry.getKey(), newColl);
    }

}

From source file:org.openanzo.rdf.utils.MultiTreeMap.java

@SuppressWarnings("unchecked")
public void putAll(MultiMap<? extends K, ? extends V> map) {
    for (Iterator it = map.entrySet().iterator(); it.hasNext();) {
        Map.Entry<? extends K, Collection<? extends V>> entry = (Map.Entry<? extends K, Collection<? extends V>>) it
                .next();/*from   w  w w  . ja  v  a  2s . c  o m*/
        for (V v : entry.getValue()) {
            put(entry.getKey(), v);
        }
    }
}