org.openrdf.model.util
Class ModelUtil

java.lang.Object
  extended by org.openrdf.model.util.ModelUtil

public class ModelUtil
extends Object

Author:
Arjohn Kampman

Constructor Summary
ModelUtil()
           
 
Method Summary
static boolean equals(Iterable<? extends Statement> model1, Iterable<? extends Statement> model2)
          Compares two models, defined by two statement collections, and returns true if they are equal.
static boolean equals(Set<? extends Statement> model1, Set<? extends Statement> model2)
          Compares two models, defined by two statement collections, and returns true if they are equal.
static Value getOptionalObject(Model model, Resource subj, URI pred, Resource... contexts)
          Gets the object of the statement(s) with the specified subject and predicate from the specified contexts in the supplied model.
static Literal getOptionalObjectLiteral(Model model, Resource subj, URI pred)
          Utility method that casts the return value of getOptionalObject(Model, Resource, URI, Resource[]) to a Literal, or throws a ModelUtilException if that value is not a Literal.
static Resource getOptionalObjectResource(Model model, Resource subj, URI pred)
          Utility method that casts the return value of getOptionalObject(Model, Resource, URI, Resource[]) to a Resource, or throws a ModelUtilException if that value is not a Resource.
static String getOptionalObjectStringValue(Model model, Resource subj, URI pred)
          Utility method that returns the value of getOptionalObject(Model, Resource, URI, Resource[])'s stringValue.
static URI getOptionalObjectURI(Model model, Resource subj, URI pred)
          Utility method that casts the return value of getOptionalObject(Model, Resource, URI, Resource[]) to a URI, or throws a ModelUtilException if that value is not a URI.
static Resource getOptionalSubject(Model model, URI pred, Value obj, Resource... contexts)
          Gets the subject of the statement(s) with the specified predicate and object from the specified contexts in the supplied model.
static URI getOptionalSubjectURI(Model model, URI pred, Value obj, Resource... contexts)
          Utility method that casts the return value of getOptionalSubject(Model, URI, Value, Resource[]) to a URI, or throws a ModelUtilException if that value is not a URI.
static Value getUniqueObject(Model model, Resource subj, URI pred, Resource... contexts)
          Gets the object of the statement(s) with the specified subject and predicate from the specified contexts in the supplied model.
static Literal getUniqueObjectLiteral(Model model, Resource subj, URI pred)
          Utility method that casts the return value of getUniqueObject(Model, Resource, URI, Resource[]) to a Literal, or throws a ModelUtilException if that value is not a Literal.
static Resource getUniqueObjectResource(Model model, Resource subj, URI pred)
          Utility method that casts the return value of getUniqueObject(Model, Resource, URI, Resource[]) to a Resource, or throws a ModelUtilException if that value is not a Resource.
static URI getUniqueObjectURI(Model model, Resource subj, URI pred)
          Utility method that casts the return value of getUniqueObject(Model, Resource, URI, Resource[]) to a URI, or throws a ModelUtilException if that value is not a URI.
static Resource getUniqueSubject(Model model, URI pred, Value obj, Resource... contexts)
          Gets the subject of the statement(s) with the specified predicate and object from the specified contexts in the supplied model.
static URI getUniqueSubjectURI(Model model, URI pred, Value obj, Resource... contexts)
          Utility method that casts the return value of getUniqueSubject(Model, URI, Value, Resource[]) to a URI, or throws a ModelUtilException if that value is not a URI.
static boolean isSubset(Iterable<? extends Statement> model1, Iterable<? extends Statement> model2)
          Compares two models, defined by two statement collections, and returns true if the first model is a subset of the second model.
static boolean isSubset(Set<? extends Statement> model1, Set<? extends Statement> model2)
          Compares two models, defined by two statement collections, and returns true if the first model is a subset of the second model.
static void setUniqueObject(Model model, Resource subj, URI pred, Value obj, Resource... contexts)
          Adds the specified statement and makes sure that no other statements are present in the Model with the same subject and predicate.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ModelUtil

public ModelUtil()
Method Detail

equals

public static boolean equals(Iterable<? extends Statement> model1,
                             Iterable<? extends Statement> model2)
Compares two models, defined by two statement collections, and returns true if they are equal. Models are equal if they contain the same set of statements. Blank node IDs are not relevant for model equality, they are mapped from one model to the other by using the attached properties.


equals

public static boolean equals(Set<? extends Statement> model1,
                             Set<? extends Statement> model2)
Compares two models, defined by two statement collections, and returns true if they are equal. Models are equal if they contain the same set of statements. Blank node IDs are not relevant for model equality, they are mapped from one model to the other by using the attached properties.


isSubset

public static boolean isSubset(Iterable<? extends Statement> model1,
                               Iterable<? extends Statement> model2)
Compares two models, defined by two statement collections, and returns true if the first model is a subset of the second model.


isSubset

public static boolean isSubset(Set<? extends Statement> model1,
                               Set<? extends Statement> model2)
Compares two models, defined by two statement collections, and returns true if the first model is a subset of the second model.


getUniqueSubject

public static Resource getUniqueSubject(Model model,
                                        URI pred,
                                        Value obj,
                                        Resource... contexts)
                                 throws ModelException
Gets the subject of the statement(s) with the specified predicate and object from the specified contexts in the supplied model. The combination of predicate, object and contexts must match at least one statement. In case more than one statement matches -- for example statements from multiple contexts -- all these statements should have the same subject. A ModelException is thrown if these conditions are not met. See Model#match(Resource, URI, Value, Resource[]) for a description of the parameter values.

Returns:
The subject of the matched statement(s).
Throws:
ModelException - If the statements matched by the specified parameters do not have exactly one unique subject.

getUniqueSubjectURI

public static URI getUniqueSubjectURI(Model model,
                                      URI pred,
                                      Value obj,
                                      Resource... contexts)
                               throws ModelException
Utility method that casts the return value of getUniqueSubject(Model, URI, Value, Resource[]) to a URI, or throws a ModelUtilException if that value is not a URI.

Returns:
The subject of the matched statement(s).
Throws:
ModelException - If such an exception is thrown by getUniqueSubject(Model, URI, Value, Resource[]) or if its return value is not a URI.

getOptionalSubject

public static Resource getOptionalSubject(Model model,
                                          URI pred,
                                          Value obj,
                                          Resource... contexts)
                                   throws ModelException
Gets the subject of the statement(s) with the specified predicate and object from the specified contexts in the supplied model. If the combination of predicate, object and contexts matches one or more statements, all these statements should have the same subject. A RepositoryConfigException is thrown if this is not the case. See Model#match(Resource, URI, Value, Resource[]) for a description of the parameter values.

Returns:
The subject 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 subject.

getOptionalSubjectURI

public static URI getOptionalSubjectURI(Model model,
                                        URI pred,
                                        Value obj,
                                        Resource... contexts)
                                 throws ModelException
Utility method that casts the return value of getOptionalSubject(Model, URI, Value, Resource[]) to a URI, or throws a ModelUtilException if that value is not a URI.

Returns:
The subject of the matched statement(s), or null if no matching statements were found.
Throws:
ModelException - If such an exception is thrown by getOptionalSubject(Model, URI, Value, Resource[]) or if its return value is not a URI.

getUniqueObject

public static Value getUniqueObject(Model model,
                                    Resource subj,
                                    URI pred,
                                    Resource... contexts)
                             throws ModelException
Gets the object of the statement(s) with the specified subject and predicate from the specified contexts in the supplied model. The combination of subject, predicate and contexts must match at least one statement. In case more than one statement matches -- for example statements from multiple contexts -- all these statements should have the same object. A ModelException is thrown if these conditions are not met. See Model#match(Resource, URI, Value, Resource[]) for a description of the parameter values.

Returns:
The object of the matched statement(s).
Throws:
ModelException - If the statements matched by the specified parameters do not have exactly one unique object.

setUniqueObject

public static void setUniqueObject(Model model,
                                   Resource subj,
                                   URI pred,
                                   Value obj,
                                   Resource... contexts)
Adds the specified statement and makes sure that no other statements are present in the Model with the same subject and predicate. When contexts are specified, the (subj, pred) pair will occur exactly once in each context, else the (subj, pred) pair will occur exactly once in the entire Model.


getUniqueObjectResource

public static Resource getUniqueObjectResource(Model model,
                                               Resource subj,
                                               URI pred)
                                        throws ModelException
Utility method that casts the return value of getUniqueObject(Model, Resource, URI, Resource[]) to a Resource, or throws a ModelUtilException if that value is not a Resource.

Returns:
The object of the matched statement(s).
Throws:
ModelException - If such an exception is thrown by getUniqueObject(Model, Resource, URI, Resource[]) or if its return value is not a Resource.

getUniqueObjectURI

public static URI getUniqueObjectURI(Model model,
                                     Resource subj,
                                     URI pred)
                              throws ModelException
Utility method that casts the return value of getUniqueObject(Model, Resource, URI, Resource[]) to a URI, or throws a ModelUtilException if that value is not a URI.

Returns:
The object of the matched statement(s).
Throws:
ModelException - If such an exception is thrown by getUniqueObject(Model, Resource, URI, Resource[]) or if its return value is not a URI.

getUniqueObjectLiteral

public static Literal getUniqueObjectLiteral(Model model,
                                             Resource subj,
                                             URI pred)
                                      throws ModelException
Utility method that casts the return value of getUniqueObject(Model, Resource, URI, Resource[]) to a Literal, or throws a ModelUtilException if that value is not a Literal.

Returns:
The object of the matched statement(s).
Throws:
ModelException - If such an exception is thrown by getUniqueObject(Model, Resource, URI, Resource[]) or if its return value is not a Literal.

getOptionalObject

public static Value getOptionalObject(Model model,
                                      Resource subj,
                                      URI pred,
                                      Resource... contexts)
                               throws ModelException
Gets the object of the statement(s) with the specified subject and predicate from the specified contexts in the supplied model. If the combination of subject, predicate and contexts matches one or more statements, all these statements should have the same object. A RepositoryConfigException is thrown if this is not the case. See Model#match(Resource, URI, Value, Resource[]) for a description of the parameter values.

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.

getOptionalObjectResource

public static Resource getOptionalObjectResource(Model model,
                                                 Resource subj,
                                                 URI pred)
                                          throws ModelException
Utility method that casts the return value of getOptionalObject(Model, Resource, URI, Resource[]) to a Resource, or throws a ModelUtilException if that value is not a Resource.

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 getOptionalObject(Model, Resource, URI, Resource[]) or if its return value is not a Resource.

getOptionalObjectURI

public static URI getOptionalObjectURI(Model model,
                                       Resource subj,
                                       URI pred)
                                throws ModelException
Utility method that casts the return value of getOptionalObject(Model, Resource, URI, Resource[]) to a URI, or throws a ModelUtilException if that value is not a URI.

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 getOptionalObject(Model, Resource, URI, Resource[]) or if its return value is not a URI.

getOptionalObjectLiteral

public static Literal getOptionalObjectLiteral(Model model,
                                               Resource subj,
                                               URI pred)
                                        throws ModelException
Utility method that casts the return value of getOptionalObject(Model, Resource, URI, Resource[]) to a Literal, or throws a ModelUtilException if that value is not a Literal.

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 getOptionalObject(Model, Resource, URI, Resource[]) or if its return value is not a Literal.

getOptionalObjectStringValue

public static String getOptionalObjectStringValue(Model model,
                                                  Resource subj,
                                                  URI pred)
                                           throws ModelException
Utility method that returns the value of getOptionalObject(Model, Resource, URI, Resource[])'s stringValue.

Returns:
The stirngValue of the matched statement's object, or null if no matching statements were found.
Throws:
ModelException - If such an exception is thrown by getOptionalObject(Model, Resource, URI, Resource[]).


Copyright © 2001-2009 Aduna. All Rights Reserved.