org.openrdf.model.impl
Class LinkedHashModel

java.lang.Object
  extended by java.util.AbstractCollection<E>
      extended by java.util.AbstractSet<Statement>
          extended by org.openrdf.model.impl.LinkedHashModel
All Implemented Interfaces:
Serializable, Iterable<Statement>, Collection<Statement>, Set<Statement>, Model

public class LinkedHashModel
extends AbstractSet<Statement>
implements Model

Model implementation using LinkedHashSet.

Author:
James Leigh
See Also:
Serialized Form

Constructor Summary
LinkedHashModel()
           
LinkedHashModel(Collection<? extends Statement> c)
           
LinkedHashModel(int size)
           
LinkedHashModel(Map<String,String> namespaces)
           
LinkedHashModel(Map<String,String> namespaces, Collection<? extends Statement> c)
           
LinkedHashModel(Map<String,String> namespaces, int size)
           
 
Method Summary
 boolean add(Resource subj, URI pred, Value obj, Resource... contexts)
          Adds one or more statements to the model.
 boolean add(Statement st)
           
 void clear()
           
 boolean clear(Resource... contexts)
          Removes statements with the specified context exist in this model.
 boolean contains(Object o)
           
 boolean contains(Resource subj, URI pred, Value obj, Resource... contexts)
          Determines if statements with the specified subject, predicate, object and (optionally) context exist in this model.
 Set<Resource> contexts()
          Returns a Set view of the contexts contained in this model.
 boolean equals(Object o)
           
 Model filter(Resource subj, URI pred, Value obj, Resource... contexts)
          Returns a view of the statements with the specified subject, predicate, object and (optionally) context.
 String getNamespace(String prefix)
          Gets the namespace that is associated with the specified prefix, if any.
 Map<String,String> getNamespaces()
          Gets the map that contains the assigned namespaces.
 int hashCode()
           
 Iterator iterator()
           
 Literal objectLiteral()
          Utility method that casts the return value of Model.objectValue() to a Literal, or throws a ModelUtilException if that value is not a Literal.
 Resource objectResource()
          Utility method that casts the return value of Model.objectValue() to a Resource, or throws a ModelUtilException if that value is not a Resource.
 Set<Value> objects()
          Returns a Set view of the objects contained in this model.
 String objectString()
          Utility method that returns the string value of Model.objectValue().
 URI objectURI()
          Utility method that casts the return value of Model.objectValue() to a URI, or throws a ModelUtilException if that value is not a URI.
 Value objectValue()
          Gets the object of the statement(s).
 Set<URI> predicates()
          Returns a Set view of the predicates contained in this model.
 boolean remove(Object o)
           
 boolean remove(Resource subj, URI pred, Value obj, Resource... contexts)
          Removes statements with the specified subject, predicate, object and (optionally) context exist in this model.
 void removeNamespace(String prefix)
          Removes a namespace declaration by removing the association between a prefix and a namespace name.
 String setNamespace(String prefix, String name)
          Sets the prefix for a namespace.
 int size()
           
 Set<Resource> subjects()
          Returns a Set view of the subjects contained in this model.
 
Methods inherited from class java.util.AbstractSet
removeAll
 
Methods inherited from class java.util.AbstractCollection
addAll, containsAll, isEmpty, retainAll, toArray, toArray, toString
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.util.Set
addAll, containsAll, isEmpty, removeAll, retainAll, toArray, toArray
 

Constructor Detail

LinkedHashModel

public LinkedHashModel()

LinkedHashModel

public LinkedHashModel(Collection<? extends Statement> c)

LinkedHashModel

public LinkedHashModel(int size)

LinkedHashModel

public LinkedHashModel(Map<String,String> namespaces,
                       Collection<? extends Statement> c)

LinkedHashModel

public LinkedHashModel(Map<String,String> namespaces)

LinkedHashModel

public LinkedHashModel(Map<String,String> namespaces,
                       int size)
Method Detail

getNamespace

public String getNamespace(String prefix)
Description copied from interface: Model
Gets the namespace that is associated with the specified prefix, if any.

Specified by:
getNamespace in interface Model
Parameters:
prefix - A namespace prefix.
Returns:
The namespace name that is associated with the specified prefix, or null if there is no such namespace.

getNamespaces

public Map<String,String> getNamespaces()
Description copied from interface: Model
Gets the map that contains the assigned namespaces.

Specified by:
getNamespaces in interface Model
Returns:
Map of prefix to namespace

setNamespace

public String setNamespace(String prefix,
                           String name)
Description copied from interface: Model
Sets the prefix for a namespace.

Specified by:
setNamespace in interface Model
Parameters:
prefix - The new prefix.
name - The namespace name that the prefix maps to.

removeNamespace

public void removeNamespace(String prefix)
Description copied from interface: Model
Removes a namespace declaration by removing the association between a prefix and a namespace name.

Specified by:
removeNamespace in interface Model
Parameters:
prefix - The namespace prefix of which the assocation with a namespace name is to be removed.

size

public int size()
Specified by:
size in interface Collection<Statement>
Specified by:
size in interface Set<Statement>
Specified by:
size in class AbstractCollection<Statement>

add

public boolean add(Statement st)
Specified by:
add in interface Collection<Statement>
Specified by:
add in interface Set<Statement>
Overrides:
add in class AbstractCollection<Statement>

add

public boolean add(Resource subj,
                   URI pred,
                   Value obj,
                   Resource... contexts)
Description copied from interface: Model
Adds one or more statements to the model. This method creates a statement for each specified context and adds those to the model. If no contexts are specified, a single statement with no associated context is added. If this Model is a filtered Model then null (if context empty) values are permitted and will used the corresponding filtered values.

Specified by:
add in interface Model
Parameters:
subj - The statement's subject.
pred - The statement's predicate.
obj - The statement's object.
contexts - The contexts to add statements to.

clear

public void clear()
Specified by:
clear in interface Collection<Statement>
Specified by:
clear in interface Set<Statement>
Overrides:
clear in class AbstractCollection<Statement>

remove

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

contains

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

iterator

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

contains

public boolean contains(Resource subj,
                        URI pred,
                        Value obj,
                        Resource... contexts)
Description copied from interface: Model
Determines if statements with the specified subject, predicate, object and (optionally) context exist in this model. The subject, predicate and object parameters can be null to indicate wildcards. The contexts parameter is a wildcard and accepts zero or more values. If no contexts are specified, statements will match disregarding their context. If one or more contexts are specified, statements with a context matching one of these will match. Note: to match statements without an associated context, specify the value null and explicitly cast it to type Resource.

Examples: model.contains(s1, null, null) is true if any statements in this model have subject s1,
model.contains(null, null, null, c1) is true if any statements in this model have context c1,
model.contains(null, null, null, (Resource)null) is true if any statements in this model have no associated context,
model.contains(null, null, null, c1, c2, c3) is true if any statements in this model have context c1, c2 or c3.

Specified by:
contains in interface Model
Parameters:
subj - The subject of the statements to match, null to match statements with any subject.
pred - The predicate of the statements to match, null to match statements with any predicate.
obj - The object of the statements to match, null to match statements with any object.
contexts - The contexts of the statements to match. If no contexts are specified, statements will match disregarding their context. If one or more contexts are specified, statements with a context matching one of these will match.
Returns:
true if statements match the specified pattern.

remove

public boolean remove(Resource subj,
                      URI pred,
                      Value obj,
                      Resource... contexts)
Description copied from interface: Model
Removes statements with the specified subject, predicate, object and (optionally) context exist in this model. The subject, predicate and object parameters can be null to indicate wildcards. The contexts parameter is a wildcard and accepts zero or more values. If no contexts are specified, statements will be removed disregarding their context. If one or more contexts are specified, statements with a context matching one of these will be removed. Note: to remove statements without an associated context, specify the value null and explicitly cast it to type Resource.

Examples: model.remove(s1, null, null) removes any statements in this model have subject s1,
model.remove(null, null, null, c1) removes any statements in this model have context c1,
model.remove(null, null, null, (Resource)null) removes any statements in this model have no associated context,
model.remove(null, null, null, c1, c2, c3) removes any statements in this model have context c1, c2 or c3.

Specified by:
remove in interface Model
Parameters:
subj - The subject of the statements to remove, null to remove statements with any subject.
pred - The predicate of the statements to remove, null to remove statements with any predicate.
obj - The object of the statements to remove, null to remove statements with any object.
contexts - The contexts of the statements to remove. If no contexts are specified, statements will be removed disregarding their context. If one or more contexts are specified, statements with a context matching one of these will be removed.
Returns:
true if one or more statements have been removed.

clear

public boolean clear(Resource... contexts)
Description copied from interface: Model
Removes statements with the specified context exist in this model.

Specified by:
clear in interface Model
Parameters:
contexts - The context of the statements to remove.
Returns:
true if one or more statements have been removed.

filter

public Model filter(Resource subj,
                    URI pred,
                    Value obj,
                    Resource... contexts)
Description copied from interface: Model
Returns a view of the statements with the specified subject, predicate, object and (optionally) context. The subject, predicate and object parameters can be null to indicate wildcards. The contexts parameter is a wildcard and accepts zero or more values. If no contexts are specified, statements will match disregarding their context. If one or more contexts are specified, statements with a context matching one of these will match. Note: to match statements without an associated context, specify the value null and explicitly cast it to type Resource.

The returned model is backed by this Model, so changes to this Model are reflected in the returned model, and vice-versa. If this Model is modified while an iteration over the returned model is in progress (except through the iterator's own remove operation), the results of the iteration are undefined. The model supports element removal, which removes the corresponding statement from this Model, via the Iterator.remove, Set.remove, removeAll, retainAll, and clear operations. The statements passed to the add and addAll operations must match the parameter pattern.

Examples: model.filter(s1, null, null) matches all statements that have subject s1,
model.filter(null, null, null, c1) matches all statements that have context c1,
model.filter(null, null, null, (Resource)null) matches all statements that have no associated context,
model.filter(null, null, null, c1, c2, c3) matches all statements that have context c1, c2 or c3.

Specified by:
filter in interface Model
Parameters:
subj - The subject of the statements to match, null to match statements with any subject.
pred - The predicate of the statements to match, null to match statements with any predicate.
obj - The object of the statements to match, null to match statements with any object.
contexts - The contexts of the statements to match. If no contexts are specified, statements will match disregarding their context. If one or more contexts are specified, statements with a context matching one of these will match.
Returns:
The statements that match the specified pattern.

subjects

public Set<Resource> subjects()
Description copied from interface: Model
Returns a Set view of the subjects contained in this model. The set is backed by the model, so changes to the model are reflected in the set, and vice-versa. If the model is modified while an iteration over the set is in progress (except through the iterator's own remove operation), the results of the iteration are undefined. The set supports element removal, which removes the corresponding statement from the model, via the Iterator.remove, Set.remove, removeAll, retainAll, and clear operations. It does not support the add or addAll operations if the parameters pred or obj are null.

Specified by:
subjects in interface Model
Returns:
a set view of the subjects contained in this model

predicates

public Set<URI> predicates()
Description copied from interface: Model
Returns a Set view of the predicates contained in this model. The set is backed by the model, so changes to the model are reflected in the set, and vice-versa. If the model is modified while an iteration over the set is in progress (except through the iterator's own remove operation), the results of the iteration are undefined. The set supports element removal, which removes the corresponding statement from the model, via the Iterator.remove, Set.remove, removeAll, retainAll, and clear operations. It does not support the add or addAll operations if the parameters subj or obj are null.

Specified by:
predicates in interface Model
Returns:
a set view of the predicates contained in this model

objects

public Set<Value> objects()
Description copied from interface: Model
Returns a Set view of the objects contained in this model. The set is backed by the model, so changes to the model are reflected in the set, and vice-versa. If the model is modified while an iteration over the set is in progress (except through the iterator's own remove operation), the results of the iteration are undefined. The set supports element removal, which removes the corresponding statement from the model, via the Iterator.remove, Set.remove, removeAll, retainAll, and clear operations. It does not support the add or addAll operations if the parameters subj or pred are null.

Specified by:
objects in interface Model
Returns:
a set view of the objects contained in this model

contexts

public Set<Resource> contexts()
Description copied from interface: Model
Returns a Set view of the contexts contained in this model. The set is backed by the model, so changes to the model are reflected in the set, and vice-versa. If the model is modified while an iteration over the set is in progress (except through the iterator's own remove operation), the results of the iteration are undefined. The set supports element removal, which removes the corresponding statement from the model, via the Iterator.remove, Set.remove, removeAll, retainAll, and clear operations. It does not support the add or addAll operations if the parameters subj , pred or obj are null.

Specified by:
contexts in interface Model
Returns:
a set view of the contexts contained in this model

objectValue

public Value objectValue()
                  throws ModelException
Description copied from interface: Model
Gets the object of the statement(s). If contains one or more statements, all these statements should have the same object. A ModelException is thrown if this is not the case.

Specified by:
objectValue in interface Model
Returns:
The object of the matched statement(s), or null if no matching statements were found.
Throws:
ModelException - If the statements matched by the specified parameters have more than one unique object.

objectLiteral

public Literal objectLiteral()
                      throws ModelException
Description copied from interface: Model
Utility method that casts the return value of Model.objectValue() to a Literal, or throws a ModelUtilException if that value is not a Literal.

Specified by:
objectLiteral in interface Model
Returns:
The object of the matched statement(s), or null if no matching statements were found.
Throws:
ModelException - If such an exception is thrown by Model.objectValue() or if its return value is not a Literal.

objectResource

public Resource objectResource()
                        throws ModelException
Description copied from interface: Model
Utility method that casts the return value of Model.objectValue() to a Resource, or throws a ModelUtilException if that value is not a Resource.

Specified by:
objectResource in interface Model
Returns:
The object of the matched statement(s), or null if no matching statements were found.
Throws:
ModelException - If such an exception is thrown by Model.objectValue() or if its return value is not a Resource.

objectURI

public URI objectURI()
              throws ModelException
Description copied from interface: Model
Utility method that casts the return value of Model.objectValue() to a URI, or throws a ModelUtilException if that value is not a URI.

Specified by:
objectURI in interface Model
Returns:
The object of the matched statement(s), or null if no matching statements were found.
Throws:
ModelException - If such an exception is thrown by Model.objectValue() or if its return value is not a URI.

objectString

public String objectString()
                    throws ModelException
Description copied from interface: Model
Utility method that returns the string value of Model.objectValue().

Specified by:
objectString in interface Model
Returns:
The object string value of the matched statement(s), or null if no matching statements were found.
Throws:
ModelException - If the statements matched by the specified parameters have more than one unique object.

hashCode

public int hashCode()
Specified by:
hashCode in interface Collection<Statement>
Specified by:
hashCode in interface Set<Statement>
Overrides:
hashCode in class AbstractSet<Statement>

equals

public boolean equals(Object o)
Specified by:
equals in interface Collection<Statement>
Specified by:
equals in interface Set<Statement>
Overrides:
equals in class AbstractSet<Statement>


Copyright © 2004-2011 James Leigh Services Inc.. All Rights Reserved.