com.hp.hpl.jena.daml
Class PropertyIterator

java.lang.Object
  |
  +--com.hp.hpl.jena.daml.PropertyIterator
All Implemented Interfaces:
java.util.Iterator

public class PropertyIterator
extends java.lang.Object
implements java.util.Iterator

Provides a means of traversing the relationships in a DAML model, respecting some of the extended semantics of DAML+OIL over RDF. In particular, the PropertyIterator knows about class, property and instance equivalence, transitive properties, inverse properties, the class hierarchy and the property hierarchy.

Given a property P, and a resource x, iterates over all the y such that x P y, respecting the fact that P may be transitive (so x P y and y P z implies x P z), and symmetric (so x P y implies y P x). The iterator is lazily evaluated, so changes to the model while iterating could generate unpredictable results. The iterator does do loop detection, so should always terminate (assuming the model is finite!). Deletion is not supported.

This iterator also supports the setting of a default value. The default value is an object that will be returned as the last value of the iteration, unless it has already been returned earlier.

Since:
Jena 1.3.0 (was previously in package com.hp.hpl.jena.daml.common).
Version:
CVS info: $Id: PropertyIterator.java,v 1.3 2002/02/22 17:07:58 ian_dickinson Exp $
Author:
Ian Dickinson, HP Labs (email)

Constructor Summary
PropertyIterator(java.util.Iterator roots, Property pred, Property inverse, boolean isTransitive, boolean isReflexive)
          Construct a property iterator for the given property, starting from the given set of resources.
PropertyIterator(java.util.Iterator roots, Property pred, Property inverse, boolean isTransitive, boolean isReflexive, boolean useEquivalence)
          Construct a property iterator for the given property, starting from the given set of resources.
PropertyIterator(Resource root, Property pred, Property inverse, boolean isTransitive, boolean isReflexive)
          Construct a property iterator for the given property, starting from the given resource.
PropertyIterator(Resource root, Property pred, Property inverse, boolean isTransitive, boolean isReflexive, boolean useEquivalence)
          Construct a property iterator for the given property, starting from the given resource.
 
Method Summary
 boolean hasDefaultValue()
          Answer true if this iteration has a default value.
 boolean hasNext()
          Answer true if the iteration over the closure of the predicate will answer any values that have not yet been returned.
 java.lang.Object next()
          Answer the next RDFNode in the iteration over the given predicate.
 void remove()
          Unsupported operation in this iterator.
 void setDefaultValue(java.lang.Object defaultValue)
          Set the default value for this iteration, which will be a value that is guaranteed to be returned as a member of the iteration.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

PropertyIterator

public PropertyIterator(Resource root,
                        Property pred,
                        Property inverse,
                        boolean isTransitive,
                        boolean isReflexive)
Construct a property iterator for the given property, starting from the given resource. The property may be defined to be symmetric by supplying its inverse (which could be itself), and/or transitive. The property may also be defined to be reflexive, in which case root itself will be returned as a member of the iteration.
Parameters:
root - The root resource from whence to start iterating over the closure of pred
pred - The property to iterate over
inverse - The inverse of pred, or null if pred has no inverse. The inverse is used to include resource y in the iteration if P' = inverse(P) and y P' x.
isTransitive - If true, the property is transitive
isReflexive - If true, the property is reflexive (so, the root resource will be included in the iteration).

PropertyIterator

public PropertyIterator(Resource root,
                        Property pred,
                        Property inverse,
                        boolean isTransitive,
                        boolean isReflexive,
                        boolean useEquivalence)
Construct a property iterator for the given property, starting from the given resource. The property may be defined to be symmetric by supplying its inverse (which could be itself), and/or transitive. The property may also be defined to be reflexive, in which case root itself will be returned as a member of the iteration.
Parameters:
root - The root resource from whence to start iterating over the closure of pred
pred - The property to iterate over
inverse - The inverse of pred, or null if pred has no inverse. The inverse is used to include resource y in the iteration if P' = inverse(P) and y P' x.
isTransitive - If true, the property is transitive
isReflexive - If true, the property is reflexive (so, the root resource will be included in the iteration).
useEquivalence - If true, equivalence between DAML values will be included in the iteration (unless the model containing the DAML values has equivalence switched off via com.hp.hpl.jena.daml.Model#setUseEquivalence.

PropertyIterator

public PropertyIterator(java.util.Iterator roots,
                        Property pred,
                        Property inverse,
                        boolean isTransitive,
                        boolean isReflexive)
Construct a property iterator for the given property, starting from the given set of resources. The property may be defined to be symmetric by supplying its inverse (which could be itself), and/or transitive. The property may also be defined to be reflexive, in which case all of the given root resources will be returned as members of the iteration.
Parameters:
roots - A set of root resources from whence to start iterating over the closure of pred, represented as an iterator
pred - The property to iterate over
inverse - The inverse of pred, or null if pred has no inverse. The inverse is used to include resource y in the iteration if P' = inverse(P) and y P' x.
isTransitive - If true, the property is transitive
isReflexive - If true, the property is reflexive (so, the root resources will be included in the iteration).

PropertyIterator

public PropertyIterator(java.util.Iterator roots,
                        Property pred,
                        Property inverse,
                        boolean isTransitive,
                        boolean isReflexive,
                        boolean useEquivalence)
Construct a property iterator for the given property, starting from the given set of resources. The property may be defined to be symmetric by supplying its inverse (which could be itself), and/or transitive. The property may also be defined to be reflexive, in which case all of the given root resources will be returned as members of the iteration.
Parameters:
roots - A set of root resources from whence to start iterating over the closure of pred, represented as an iterator
pred - The property to iterate over
inverse - The inverse of pred, or null if pred has no inverse. The inverse is used to include resource y in the iteration if P' = inverse(P) and y P' x.
isTransitive - If true, the property is transitive
isReflexive - If true, the property is reflexive (so, the root resources will be included in the iteration).
useEquivalence - If true, equivalence between DAML values will be included in the iteration (unless the model containing the DAML values has equivalence switched off via com.hp.hpl.jena.daml.Model#setUseEquivalence.
Method Detail

hasNext

public boolean hasNext()
Answer true if the iteration over the closure of the predicate will answer any values that have not yet been returned.
Specified by:
hasNext in interface java.util.Iterator
Returns:
True if there is at least one more element in the iteration

next

public java.lang.Object next()
Answer the next RDFNode in the iteration over the given predicate. Note that each node in the closure of the predicate will be answered only once, to avoid endless loops.
Specified by:
next in interface java.util.Iterator
Returns:
The next RDFNode in the iteration over the closure of the predicate.
Throws:
java.util.NoSuchElementException - if the iterator has no more elements

remove

public void remove()
Unsupported operation in this iterator.
Specified by:
remove in interface java.util.Iterator
Throws:
java.lang.UnsupportedOperationException -  

setDefaultValue

public void setDefaultValue(java.lang.Object defaultValue)
Set the default value for this iteration, which will be a value that is guaranteed to be returned as a member of the iteration. To guarantee that the default value is only returned if it has not already been returned by the iterator, setting the default value should occur before the first call to next().
Parameters:
defaultValue - The default value for the iteration, or null for there to be no default value. The default default value is null.

hasDefaultValue

public boolean hasDefaultValue()
Answer true if this iteration has a default value.
Returns:
true if there is a default value


Copyright © 2001 Hewlett-Packard. All Rights Reserved.