Example usage for org.apache.commons.collections15.multimap MultiHashMap putAll

List of usage examples for org.apache.commons.collections15.multimap MultiHashMap putAll

Introduction

In this page you can find the example usage for org.apache.commons.collections15.multimap MultiHashMap putAll.

Prototype

public void putAll(MultiMap<? extends K, ? extends V> map) 

Source Link

Usage

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

/**
 * Get an Collection for the members of the RDFList construct provided
 * /*from w  w  w . ja v a2  s  .  c  om*/
 * @param list
 *            Resource of RDFList object
 * @param dataset
 *            Dataset containing data
 * @return Collection containing data contained within RDFContainer
 */
public static MultiMap<URI, Value> getCollectionMembers(Resource list, IDataset dataset) { // NO_UCD
    MultiHashMap<URI, Value> statements = new MultiHashMap<URI, Value>();
    if (dataset.contains(list, RDF.first, null) && dataset.contains(list, RDF.rest, null)) {
        Collection<Statement> firstStatements = dataset.find(list, RDF.first, null);
        if (!firstStatements.isEmpty()) {
            Statement first = firstStatements.iterator().next();
            if (!statements.containsValue(first.getNamedGraphUri(), first.getObject())) {
                statements.put(first.getNamedGraphUri(), first.getObject());
            }
        }

        Collection<Statement> restStatements = dataset.find(list, RDF.rest, null);
        if (!restStatements.isEmpty()) {
            Statement rest = restStatements.iterator().next();
            if (!statements.containsValue(rest.getNamedGraphUri(), rest.getObject())
                    && rest.getObject() instanceof Resource) {
                statements.putAll(getCollectionMembers((Resource) rest.getObject(), dataset));
            }
        }
    }
    return statements;
}