Class RDFListImpl
- All Implemented Interfaces:
FrontsNode
,RDFList
,RDFNode
,Resource
Standard implementation the list abstraction from rdf.model.
-
Nested Class Summary
Nested classes/interfaces inherited from interface org.apache.jena.rdf.model.RDFList
RDFList.ApplyFn, RDFList.ReduceFn
-
Field Summary
Modifier and TypeFieldDescriptionstatic Implementation
A factory for generating RDFList facets from nodes in enhanced graphs.Fields inherited from class org.apache.jena.rdf.model.impl.ResourceImpl
rdfNodeFactory
-
Constructor Summary
ConstructorDescriptionRDFListImpl
(Node n, EnhGraph g) Construct an implementation of RDFList in the given graph, where the given node is the head of the list. -
Method Summary
Modifier and TypeMethodDescriptionvoid
Add the given value to the end of the list.Answer a new list that is formed by adding each element of this list to the head of the the list formed from the givennodes
.Answer a new list that is formed by adding each element of this list to the head of the givenlist
.void
apply
(RDFList.ApplyFn fn) Apply a function to each value in the list in turn.Answer the contents of this RDF list as a Java list of RDFNode values.Answer a set of all of the RDF statements whose subject is one of the cells of this list.void
concatenate
(Iterator<? extends RDFNode> nodes) Add the nodes returned by the given iterator to the end of this list.void
concatenate
(RDFList list) Change the tail of this list to point to the given list, so that this list becomes the list of the concatenation of the elements of both lists.Return a reference to a new list cell whose head isvalue
and whose tail is this list.boolean
Answer true if the given node appears as the value of a value of any of the cells of this list.copy()
Answer a list that contains all of the elements of this list in the same order, but is a duplicate copy in the underlying model.get
(int i) Answer the node that is the i'th element of the list, assuming that the head is item zero.getHead()
Answer the value that is at the head of the list.boolean
Answer true lists are operating in strict mode, in which the well- formedness of the list is checked at every operation.getTail()
Answer the list that is the tail of this list.Answer the error message returned by the last failed validity check, if any.int
Answer the index of the first occurrence of the given value in the list, or -1 if the value is not in the list.int
Answer the index of the first occurrence of the given value in the list after indexstart
, or -1 if the value is not in the list after the given start point.boolean
isEmpty()
Answer true if this list is the empty list.boolean
isValid()
Answer true if the list is well-formed, by checking that each node is correctly typed, and has a head and tail pointer from the correct vocabulary.iterator()
Answer an iterator over the elements of the list.listNil()
listRest()
listType()
<T> ExtendedIterator<T>
Answer an iterator of the elements of this list, to each of which the given map function has been applied.newListCell
(RDFNode value, Resource tail) Construct a new list cell with the given value and tail.reduce
(RDFList.ReduceFn fn, Object initial) Apply a function to each value in the list in turn, accumulating the results in an accumulator.Remove the given value from this list.Remove the value from the head of the list.void
Remove all of the components of this list from the model.Replace the value at the i'th position in the list with the given value.boolean
sameListAs
(RDFList list) Answer true if this list has the same elements in the same order as the given list.Update the head of the list to have the given value, and return the previous value.void
setStrict
(boolean strict) Set a flag to indicate whether to strictly check the well-formedness of lists at each operation.Update the list cell at the front of the list to have the given list as tail.int
size()
Answer the number of elements in the list.Answer the list that is this list with the given value added to the end of the list.Methods inherited from class org.apache.jena.rdf.model.impl.ResourceImpl
abort, addLiteral, addLiteral, addLiteral, addLiteral, addLiteral, addLiteral, addLiteral, addProperty, addProperty, addProperty, addProperty, addProperty, addProperty, addProperty, asLiteral, asResource, begin, commit, getId, getLocalName, getModel, getNameSpace, getProperty, getProperty, getPropertyResourceValue, getRequiredProperty, getRequiredProperty, getStmtTerm, getURI, hasLiteral, hasLiteral, hasLiteral, hasLiteral, hasLiteral, hasLiteral, hasProperty, hasProperty, hasProperty, hasProperty, hasURI, inModel, listProperties, listProperties, listProperties, removeAll, removeProperties, toString, visitWith
Methods inherited from class org.apache.jena.enhanced.EnhNode
as, asNode, canAs, equals, getGraph, hashCode, isAnon, isLiteral, isResource, isStmtResource, isURIResource, viewAs
Methods inherited from class org.apache.jena.enhanced.Polymorphic
addView, supports
Methods inherited from interface org.apache.jena.graph.FrontsNode
asNode
Methods inherited from interface org.apache.jena.rdf.model.RDFNode
as, asLiteral, asResource, canAs, getModel, isAnon, isLiteral, isResource, isStmtResource, isURIResource, visitWith
Methods inherited from interface org.apache.jena.rdf.model.Resource
abort, addLiteral, addLiteral, addLiteral, addLiteral, addLiteral, addLiteral, addLiteral, addProperty, addProperty, addProperty, addProperty, begin, commit, equals, getId, getLocalName, getNameSpace, getProperty, getProperty, getPropertyResourceValue, getRequiredProperty, getRequiredProperty, getStmtTerm, getURI, hasLiteral, hasLiteral, hasLiteral, hasLiteral, hasLiteral, hasLiteral, hasProperty, hasProperty, hasProperty, hasProperty, hasURI, inModel, listProperties, listProperties, listProperties, removeAll, removeProperties, toString
-
Field Details
-
factory
A factory for generating RDFList facets from nodes in enhanced graphs.
-
-
Constructor Details
-
RDFListImpl
Construct an implementation of RDFList in the given graph, where the given node is the head of the list.
- Parameters:
n
- The node that is the head of the list, currentlyg
- The enh graph that contains n
-
-
Method Details
-
listType
-
listNil
-
listFirst
-
listRest
-
listAbstractionClass
-
size
public int size()Answer the number of elements in the list.
-
getHead
Answer the value that is at the head of the list.
- Specified by:
getHead
in interfaceRDFList
- Returns:
- The value that is associated with the head of the list.
- Throws:
EmptyListException
- if this list is the empty list
-
setHead
Update the head of the list to have the given value, and return the previous value.
- Specified by:
setHead
in interfaceRDFList
- Parameters:
value
- The value that will become the value of the list head- Throws:
EmptyListException
- if this list is the empty list
-
getTail
Answer the list that is the tail of this list.
- Specified by:
getTail
in interfaceRDFList
- Returns:
- The tail of the list, as a list
- Throws:
EmptyListException
- if this list is the empty list
-
setTail
Update the list cell at the front of the list to have the given list as tail. The old tail is returned, and remains in the model.
-
isEmpty
public boolean isEmpty()Answer true if this list is the empty list. -
cons
Return a reference to a new list cell whose head is
value
and whose tail is this list. -
add
Add the given value to the end of the list. This is a side-effecting operation on the underlying model that is only defined if this is not the empty list. If this list is the empty (nil) list, we cannot perform a side-effecting update without changing the URI of this node (from
rdf:nil
) to a blank-node for the new list cell) without violating a Jena invariant. Therefore, this update operation will throw an exception if an attempt is made to add to the nil list. Safe ways to add to an empty list includewith(org.apache.jena.rdf.model.RDFNode)
andcons(org.apache.jena.rdf.model.RDFNode)
.- Specified by:
add
in interfaceRDFList
- Parameters:
value
- A value to add to the end of the list- Throws:
EmptyListUpdateException
- if an attempt is made toadd
to the empty list.
-
with
Answer the list that is this list with the given value added to the end of the list. This operation differs from
add(org.apache.jena.rdf.model.RDFNode)
in that it will always work, even on an empty list, but the return value is the updated list. Specifically, in the case of adding a value to the empty list, the returned list will not be the same as this list. Client code should not assume that this is an in-place update, but should ensure that the resulting list is asserted back into the graph into the appropriate relationships. -
get
Answer the node that is the i'th element of the list, assuming that the head is item zero. If the list is too short to have an i'th element, throws a
ListIndexException
.- Specified by:
get
in interfaceRDFList
- Parameters:
i
- The index into the list, from 0- Returns:
- The list value at index i, or null
- Throws:
ListIndexException
- if the list has fewer than (i + 1) elements.
-
replace
Replace the value at the i'th position in the list with the given value. If the list is too short to have an i'th element, throws a
ListIndexException
.- Specified by:
replace
in interfaceRDFList
- Parameters:
i
- The index into the list, from 0value
- The new value to associate with the i'th list element- Returns:
- The value that was previously at position i in the list
- Throws:
ListIndexException
- if the list has fewer than (i + 1) elements.
-
contains
Answer true if the given node appears as the value of a value of any of the cells of this list.
-
indexOf
Answer the index of the first occurrence of the given value in the list, or -1 if the value is not in the list.
-
indexOf
Answer the index of the first occurrence of the given value in the list after index
start
, or -1 if the value is not in the list after the given start point.- Specified by:
indexOf
in interfaceRDFList
- Parameters:
value
- The value to search forstart
- The index into the list to start searching from- Returns:
- The index (from zero, the front of the list) of the first
occurrence of
value
in the list not less thanstart
, or-1
if not found. - Throws:
ListIndexException
- ifstart
is greater than the length of the list.
-
append
Answer a new list that is formed by adding each element of this list to the head of the the list formed from the given
nodes
. This is a non side-effecting operation on either this list or the given list, but generates a copy of this list. For a more storage efficient alternative, seeconcatenate
. -
append
Answer a new list that is formed by adding each element of this list to the head of the given
list
. This is a non side-effecting operation on either this list or the given list, but generates a copy of this list. For a more storage efficient alternative, seeconcatenate
. -
concatenate
Change the tail of this list to point to the given list, so that this list becomes the list of the concatenation of the elements of both lists. This is a side-effecting operation on this list; for a non side-effecting alternative, see
append(java.util.Iterator<? extends org.apache.jena.rdf.model.RDFNode>)
. Due to the problem of maintaining the URI invariant on a node, this operation will throw an exception if an attempt is made to concatenate onto an empty list. To avoid this, test for an empty list: if true replace the empty list with the argument list, otherwise proceed with the concatenate as usual. An alternative solution is to useappend(java.util.Iterator<? extends org.apache.jena.rdf.model.RDFNode>)
and replace the original list with the return value.- Specified by:
concatenate
in interfaceRDFList
- Parameters:
list
- The argument list to concatenate to this list- Throws:
EmptyListUpdateException
- if this list is the nil list
-
concatenate
Add the nodes returned by the given iterator to the end of this list.
- Specified by:
concatenate
in interfaceRDFList
- Parameters:
nodes
- An iterator whose range is RDFNode- Throws:
EmptyListUpdateException
- if this list is the nil list- See Also:
-
copy
Answer a list that contains all of the elements of this list in the same order, but is a duplicate copy in the underlying model.
-
apply
Apply a function to each value in the list in turn.
-
reduce
Apply a function to each value in the list in turn, accumulating the results in an accumulator. The final value of the accumulator is returned as the value of
reduce()
. -
mapWith
Answer an iterator of the elements of this list, to each of which the given map function has been applied.
-
removeHead
Remove the value from the head of the list. The tail of the list remains in the model. Note that no changes are made to list cells that point to this list cell as their tail. Immediately following a
removeHead
operation, such lists will be in a non-valid state.- Specified by:
removeHead
in interfaceRDFList
- Returns:
- The remainder of the list after the head is removed (i.e. the pre-removal list tail)
-
remove
Remove the given value from this list. If
val
does not occur in the list, no action is taken. Since removing the head of the list will invalidate the list head cell, in general the list must return the list that results from this operation. However, in many cases the return value will be the same as the object that this method is invoked on -
removeList
public void removeList()Remove all of the components of this list from the model. Once this operation has completed, the
RDFList
resource on which it was called will no longer be a resource in the model, so further methods calls on the list object (for example,size()
will fail. Due to restrictions on the encoding of lists in RDF, it is not possible to perform an operation which empties a list and then adds further values to that list. Client code wishing to perform such an operation should do so in two steps: first remove the old list, then create a new list with the new contents. It is important that RDF statements that reference the old list (in the object position) be updated to point to the newly created list. Note that this is operation is only removing the list cells themselves, not the resources referenced by the list - unless being the object of anrdf:first
statement is the only mention of that resource in the model.- Specified by:
removeList
in interfaceRDFList
-
collectStatements
Answer a set of all of the RDF statements whose subject is one of the cells of this list.
- Returns:
- A list of the statements that form the encoding of this list.
-
iterator
Answer an iterator over the elements of the list. Note that this iterator does not take a snapshot of the list, so changes to the list statements in the model while iterating will affect the behaviour of the iterator. To get an iterator that is not affected by model changes, use
asJavaList()
. -
asJavaList
Answer the contents of this RDF list as a Java list of RDFNode values.
- Specified by:
asJavaList
in interfaceRDFList
- Returns:
- The contents of this list as a Java List.
-
sameListAs
Answer true if this list has the same elements in the same order as the given list. Note that the standard
equals
test just tests for equality of two given list cells. While such a test is sufficient for many purposes, this test provides a broader equality definition, but is correspondingly more expensive to test.- Specified by:
sameListAs
in interfaceRDFList
- Parameters:
list
- The list to test against- Returns:
- True if the given list and this list are the same length, and contain equal elements in the same order.
-
getStrict
public boolean getStrict()Answer true lists are operating in strict mode, in which the well- formedness of the list is checked at every operation.
-
setStrict
public void setStrict(boolean strict) Set a flag to indicate whether to strictly check the well-formedness of lists at each operation. Default false. Note that the flag that is manipulated is actually a static: it applies to all lists. However, RDFList is a Java interface, and Java does not permit static methods in interfaces.
-
isValid
public boolean isValid()Answer true if the list is well-formed, by checking that each node is correctly typed, and has a head and tail pointer from the correct vocabulary.
-
getValidityErrorMessage
Answer the error message returned by the last failed validity check, if any.
- Specified by:
getValidityErrorMessage
in interfaceRDFList
- Returns:
- The most recent error message, or null.
- See Also:
-
newListCell
Construct a new list cell with the given value and tail.
- Parameters:
value
- The value at the head of the new list celltail
- The tail of the list cell- Returns:
- A new list cell as a resource
-