All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.mindswap.pellet.jena.SimpleUnion Maven / Gradle / Ivy

The newest version!
package org.mindswap.pellet.jena;

import com.hp.hpl.jena.graph.Graph;
import com.hp.hpl.jena.graph.Triple;
import com.hp.hpl.jena.graph.TripleMatch;
import com.hp.hpl.jena.graph.compose.Polyadic;
import com.hp.hpl.jena.util.iterator.ExtendedIterator;
import com.hp.hpl.jena.util.iterator.NullIterator;

/**
 * A simple union graph implementation whose find function may contain duplicate
 * triples. The contains function is overridden so as not to call the find method.
 * 
 * @author Evren Sirin
 */
public class SimpleUnion extends Polyadic {
	/**
	 * @param graphs
	 */
	public SimpleUnion(Iterable graphs) {
		super( graphs.iterator() );
	}

	/**
	 * {@inheritDoc}
	 */
	@Override
	protected ExtendedIterator graphBaseFind(TripleMatch m) {
		ExtendedIterator result = NullIterator.instance();
		for (final Graph g : m_subGraphs) {
			result = result.andThen(g.find(m));
		}

		return result;
	}

	/**
	 * {@inheritDoc}
	 */
	@Override
	protected boolean graphBaseContains(Triple t) {
		for (final Graph g : m_subGraphs) {
			if( g.contains( t ) )
				return true;
		}
		
		return false;
	}

	/**
	 * {@inheritDoc}
	 */
	@Override
	public boolean isEmpty() {
		for (final Graph g : m_subGraphs) {
			if( !g.isEmpty() )
				return false;
		}
		
		return true;
	}
	
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy