org.apache.clerezza.rdf.core.impl
Class AbstractTripleCollection

java.lang.Object
  extended by java.util.AbstractCollection<Triple>
      extended by org.apache.clerezza.rdf.core.impl.AbstractTripleCollection
All Implemented Interfaces:
Iterable<Triple>, Collection<Triple>, TripleCollection
Direct Known Subclasses:
AbstractGraph, AbstractMGraph, SimpleMGraph

public abstract class AbstractTripleCollection
extends AbstractCollection<Triple>
implements TripleCollection

An abstract implementation of TripleCollection implementing iterator and contains calling filter.

Author:
reto

Constructor Summary
AbstractTripleCollection()
           
 
Method Summary
 boolean add(Triple triple)
           
 void addGraphListener(GraphListener listener, FilterTriple filter)
          Adds the specified GraphListener to the graph.
 void addGraphListener(GraphListener listener, FilterTriple filter, long delay)
          Adds the specified GraphListener to the graph.
 boolean contains(Object o)
           
protected  void dispatchEvent(GraphEvent event)
          Dispatches a GraphEvent to all registered listeners for which the specified Triple matches the FilterTriples of the listeners.
 Iterator<Triple> filter(NonLiteral subject, UriRef predicate, Resource object)
          Filters triples given a pattern.
 Iterator<Triple> iterator()
           
protected  boolean performAdd(Triple e)
          A subclass of AbstractTripleCollection should override this method instead of add for graph event support to be added.
protected abstract  Iterator<Triple> performFilter(NonLiteral subject, UriRef predicate, Resource object)
          A subclass of AbstractTripleCollection should override this method instead of filter for graph event support to be added.
protected  boolean performRemove(Triple triple)
          A subclass of AbstractTripleCollection should override this method instead of remove for graph event support to be added.
 boolean remove(Object o)
           
 boolean removeAll(Collection<?> c)
           
 void removeGraphListener(GraphListener listener)
          Removes the specified GraphListener from the graph.
 
Methods inherited from class java.util.AbstractCollection
addAll, clear, containsAll, isEmpty, retainAll, size, toArray, toArray, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.util.Collection
addAll, clear, containsAll, equals, hashCode, isEmpty, retainAll, size, toArray, toArray
 

Constructor Detail

AbstractTripleCollection

public AbstractTripleCollection()
Method Detail

iterator

public Iterator<Triple> iterator()
Specified by:
iterator in interface Iterable<Triple>
Specified by:
iterator in interface Collection<Triple>
Specified by:
iterator in class AbstractCollection<Triple>

contains

public boolean contains(Object o)
Specified by:
contains in interface Collection<Triple>
Overrides:
contains in class AbstractCollection<Triple>

filter

public Iterator<Triple> filter(NonLiteral subject,
                               UriRef predicate,
                               Resource object)
Description copied from interface: TripleCollection
Filters triples given a pattern. filter(null, null, null) returns the same as iterator()

Specified by:
filter in interface TripleCollection
Returns:
Iterator

performFilter

protected abstract Iterator<Triple> performFilter(NonLiteral subject,
                                                  UriRef predicate,
                                                  Resource object)
A subclass of AbstractTripleCollection should override this method instead of filter for graph event support to be added. The Iterator returned by filter will dispatch a GraphEvent after invoking the remove method of the iterator returned by this method.

Parameters:
subject -
predicate -
object -
Returns:

add

public boolean add(Triple triple)
Specified by:
add in interface Collection<Triple>
Overrides:
add in class AbstractCollection<Triple>

performAdd

protected boolean performAdd(Triple e)
A subclass of AbstractTripleCollection should override this method instead of add for graph event support to be added.

Parameters:
e - The triple to be added to the triple collection
Returns:

remove

public boolean remove(Object o)
Specified by:
remove in interface Collection<Triple>
Overrides:
remove in class AbstractCollection<Triple>

removeAll

public boolean removeAll(Collection<?> c)
Specified by:
removeAll in interface Collection<Triple>
Overrides:
removeAll in class AbstractCollection<Triple>

performRemove

protected boolean performRemove(Triple triple)
A subclass of AbstractTripleCollection should override this method instead of remove for graph event support to be added.

Parameters:
o - The triple to be removed from the triple collection
Returns:

dispatchEvent

protected void dispatchEvent(GraphEvent event)
Dispatches a GraphEvent to all registered listeners for which the specified Triple matches the FilterTriples of the listeners.

Parameters:
triple - The Triple that was modified
type - The type of modification

addGraphListener

public void addGraphListener(GraphListener listener,
                             FilterTriple filter)
Description copied from interface: TripleCollection
Adds the specified GraphListener to the graph. This listener will be notified, when the graph is modified and the Triple that was part of the modifiaction matched the specified FilterTriple. The notification will be passed without delay. Same as addGraphListener(listener, filter, 0).

Specified by:
addGraphListener in interface TripleCollection
Parameters:
listener - The listener that will be notified
filter - The triple filter with which triples are tested, that were part of the modification.

addGraphListener

public void addGraphListener(GraphListener listener,
                             FilterTriple filter,
                             long delay)
Description copied from interface: TripleCollection
Adds the specified GraphListener to the graph. This listener will be notified, when the graph is modified and the Triple that was part of the modifiaction matched the specified FilterTriple. The notification will be passed to the listener after the specified delay time (in milli-seconds) has passed. If more matching events occur during the delay period, then they are passed all together at the end of the delay period. If the the listener unregisters or the platform is stopped within the period then the already occurred events may not be delivered. All implementations support this method, immutable implementations will typically provide an empty implementation, they shall not throw an exception. Implementation of which the triples change over time without add- and remove-methods being called (e.g. implementation dynamically generating their triples on invocation of the filer-method) may choose not to, or only partially propagate their changes to the listener. They should describe the behavior in the documentation of the class. Implementations should keep weak references the listeners, so that the listener can be garbage collected if its no longer referenced by another object. If delay is 0 notification will happen synchroneously.

Specified by:
addGraphListener in interface TripleCollection
Parameters:
listener - The listener that will be notified
filter - The triple filter with which triples are tested, that were part of the modification.
delay - The time period afer which the listener will be notified in milliseconds.

removeGraphListener

public void removeGraphListener(GraphListener listener)
Description copied from interface: TripleCollection
Removes the specified GraphListener from the graph. This listener will no longer be notified, when the graph is modified.

Specified by:
removeGraphListener in interface TripleCollection
Parameters:
listener - The listener to be removed.


Copyright © 2012 The Apache Software Foundation. All Rights Reserved.