Skip to content

Commit

Permalink
Improvements to RdfStream type facilities
Browse files Browse the repository at this point in the history
  • Loading branch information
ajs6f committed Oct 28, 2013
1 parent 2edb4b8 commit 858b3d1
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 15 deletions.
Expand Up @@ -93,9 +93,9 @@ private void putPropertiesIntoContext() throws RepositoryException {
final Node subject =
graphSubjects().getGraphSubject(node()).asNode();
// add triples representing parent-to-content-child relationship
concat(Iterators.forArray(new Triple[] {
concat(new Triple[] {
create(subject, HAS_CONTENT.asNode(), contentSubject),
create(contentSubject, IS_CONTENT_OF.asNode(), subject)}));
create(contentSubject, IS_CONTENT_OF.asNode(), subject)});
// add properties from content child
concat(new PropertiesRdfContext(node().getNode(JCR_CONTENT),
graphSubjects(), lowLevelStorageService()));
Expand Down
Expand Up @@ -20,14 +20,10 @@
import static com.google.common.collect.Iterators.singletonIterator;
import static com.google.common.collect.Iterators.transform;
import static com.hp.hpl.jena.rdf.model.ModelFactory.createDefaultModel;
import static java.util.Collections.emptySet;

import java.util.Collection;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;

import com.google.common.base.Function;
import com.google.common.collect.ForwardingIterator;
import com.google.common.collect.Iterables;
Expand All @@ -47,14 +43,14 @@ public class RdfStream extends ForwardingIterator<Triple> implements

protected Iterator<Triple> triples;

private final static Set<Triple> none = emptySet();
private final static Triple[] NONE = new Triple[] {};

/**
* Constructor that begins the stream with proffered triples.
*
* @param triples
*/
public <T extends Triple> RdfStream(final Iterator<T> triples) {
public <Tr extends Triple, T extends Iterator<Tr>> RdfStream(final T triples) {
super();
this.triples = Iterators.transform(triples, cast());
}
Expand All @@ -64,26 +60,34 @@ public <T extends Triple> RdfStream(final Iterator<T> triples) {
*
* @param triples
*/
public <T extends Triple> RdfStream(final Iterable<T> triples) {
super();
this.triples = Iterators.transform(triples.iterator(), cast());
public <Tr extends Triple, T extends Iterable<Tr>> RdfStream(final T triples) {
this(triples.iterator());
}

/**
* Constructor that begins the stream with proffered triples.
*
* @param triples
*/
public <T extends Triple> RdfStream(final Collection<T> triples) {
super();
this.triples = Iterators.transform(triples.iterator(), cast());
public <Tr extends Triple, T extends Collection<Tr>> RdfStream(
final T triples) {
this(triples.iterator());
}

/**
* Constructor that begins the stream with proffered triples.
*
* @param triples
*/
public <T extends Triple> RdfStream(final T[] triples) {
this(Iterators.forArray(triples));
}

/**
* Constructor that begins the stream without any triples.
*/
public RdfStream() {
this(none);
this(NONE);
}

/**
Expand Down

0 comments on commit 858b3d1

Please sign in to comment.