|
|||||||||
| Home >> All >> com >> hp >> hpl >> jena >> rdf >> [ model overview ] | PREV CLASS NEXT CLASS | ||||||||
SUMMARY: JAVADOC | SOURCE | DOWNLOAD | NESTED | FIELD | CONSTR | METHOD |
DETAIL: FIELD | CONSTR | METHOD | ||||||||
com.hp.hpl.jena.rdf.model
Interface RDFList

- All Superinterfaces:
- com.hp.hpl.jena.graph.FrontsNode, RDFNode, Resource
- public interface RDFList
- extends Resource
Provides a convenience encapsulation for lists formed from chains of RDF statements arranged to form a head/tail cons-cell structure. The properties that form the links between cells, and from cells to values, are specified by a vocabulary interface, so this abstraction is designed to cope equally well with DAML lists, RDF lists, and user-defined lists.
A well-formed list has cells that are made up of three statements: one
denoting the rdf:type of the list cell, one denoting the link
to the value of the list at that point, and one pointing to the list tail. If
a list cell is not well-formed, list operations may fail in unpredictable
ways. However, to explicitly check that the list is well-formed at all times
is expensive. Therefore the list operates in two modes: in strict
mode, the well-formedness of the list is checked at the start of each list
operation, and an InvalidListException is thrown if the list is not
well- formed. This ensures that list operations are safe, but will slow down
processing. In non-strict mode, this checking is switched off, but can
be invoked explicitly by clients by calling isValid() 55 . By default, RDF
lists are processed in non-strict mode.
- Version:
- Release ($Id: RDFList.java,v 1.10 2005/02/21 12:14:21 andy_seaborne Exp $)
| Nested Class Summary | |
static interface |
RDFList.ApplyFn
Interface that encapsulates a function to apply to every element in a list. |
static interface |
RDFList.ReduceFn
Interface that encapsulates a function to apply to each element of a list in turn, and passing the result to an accumulator. |
| Method Summary | |
void |
add(RDFNode value)
Add the given value to the end of the list. |
RDFList |
append(java.util.Iterator nodes)
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. |
RDFList |
append(RDFList list)
Answer a new list that is formed by adding each element of this list to the head of the given list. |
void |
apply(RDFList.ApplyFn fn)
Apply a function to each value in the list in turn. |
java.util.List |
asJavaList()
Answer the contents of this RDF list as a Java list of RDFNode values. |
void |
concatenate(java.util.Iterator 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. |
RDFList |
cons(RDFNode value)
Return a reference to a new list cell whose head is value
and whose tail is this list. |
boolean |
contains(RDFNode value)
Answer true if the given node appears as the value of a value of any of the cells of this list. |
RDFList |
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. |
RDFNode |
get(int i)
Answer the node that is the i'th element of the list, assuming that the head is item zero. |
RDFNode |
getHead()
Answer the value that is at the head of the list. |
boolean |
getStrict()
Answer true lists are operating in strict mode, in which the well- formedness of the list is checked at every operation. |
RDFList |
getTail()
Answer the list that is the tail of this list. |
java.lang.String |
getValidityErrorMessage()
Answer the error message returned by the last failed validity check, if any. |
int |
indexOf(RDFNode value)
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 |
indexOf(RDFNode value,
int start)
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. |
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. |
com.hp.hpl.jena.util.iterator.ExtendedIterator |
iterator()
Answer an iterator over the elements of the list. |
com.hp.hpl.jena.util.iterator.ExtendedIterator |
mapWith(com.hp.hpl.jena.util.iterator.Map1 fn)
Answer an iterator of the elements of this list, to each of which the given map function has been applied. |
java.lang.Object |
reduce(RDFList.ReduceFn fn,
java.lang.Object initial)
Apply a function to each value in the list in turn, accumulating the results in an accumulator. |
RDFList |
remove(RDFNode val)
Remove the given value from this list. |
void |
removeAll()
Deprecated. Replaced by removeList() 55 |
RDFList |
removeHead()
Remove the value from the head of the list. |
void |
removeList()
Remove all of the components of this list from the model. |
RDFNode |
replace(int i,
RDFNode value)
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. |
RDFNode |
setHead(RDFNode value)
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. |
RDFList |
setTail(RDFList tail)
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. |
RDFList |
with(RDFNode value)
Answer the list that is this list with the given value added to the end of the list. |
| Methods inherited from interface com.hp.hpl.jena.rdf.model.Resource |
abort, addProperty, addProperty, addProperty, addProperty, addProperty, addProperty, addProperty, addProperty, addProperty, begin, commit, equals, getId, getLocalName, getModel, getNameSpace, getNode, getProperty, getRequiredProperty, getURI, hasProperty, hasProperty, hasProperty, hasProperty, hasProperty, hasProperty, hasProperty, hasProperty, hasProperty, hasProperty, hasURI, isAnon, listProperties, listProperties, removeAll, removeProperties, toString |
| Methods inherited from interface com.hp.hpl.jena.rdf.model.RDFNode |
as, canAs, inModel, visitWith |
| Methods inherited from interface com.hp.hpl.jena.graph.FrontsNode |
asNode |
| Method Detail |
size
public int size()
Answer the number of elements in the list.
getHead
public RDFNode getHead()
Answer the value that is at the head of the list.
setHead
public RDFNode setHead(RDFNode value)
Update the head of the list to have the given value, and return the previous value.
getTail
public RDFList getTail()
Answer the list that is the tail of this list.
setTail
public RDFList setTail(RDFList tail)
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
public RDFList cons(RDFNode value)
Return a reference to a new list cell whose head is
valueand whose tail is this list.
add
public void add(RDFNode value)
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:nilwith(com.hp.hpl.jena.rdf.model.RDFNode)55 andcons(com.hp.hpl.jena.rdf.model.RDFNode)55 .
with
public RDFList with(RDFNode value)
Answer the list that is this list with the given value added to the end of the list. This operation differs from
add(com.hp.hpl.jena.rdf.model.RDFNode)55 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
public RDFNode get(int i)
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.
replace
public RDFNode replace(int i, RDFNode value)
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.
contains
public boolean contains(RDFNode value)
Answer true if the given node appears as the value of a value of any of the cells of this list.
indexOf
public int indexOf(RDFNode value)
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
public int indexOf(RDFNode value, int start)
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.
append
public RDFList append(RDFList list)
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, see concatenate 55 .
append
public RDFList append(java.util.Iterator nodes)
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, see concatenate 55 .
concatenate
public 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. This is a side-effecting operation on this list; for a non side-effecting alternative, see
append(com.hp.hpl.jena.rdf.model.RDFList)55 . 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(com.hp.hpl.jena.rdf.model.RDFList)55 and replace the original list with the return value.
concatenate
public void concatenate(java.util.Iterator nodes)
Add the nodes returned by the given iterator to the end of this list.
copy
public RDFList 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
public void apply(RDFList.ApplyFn fn)
Apply a function to each value in the list in turn.
reduce
public java.lang.Object reduce(RDFList.ReduceFn fn, java.lang.Object initial)
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
public com.hp.hpl.jena.util.iterator.ExtendedIterator mapWith(com.hp.hpl.jena.util.iterator.Map1 fn)
Answer an iterator of the elements of this list, to each of which the given map function has been applied.
removeHead
public RDFList 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
removeHeadoperation, such lists will be in a non-valid state.
removeAll
public void removeAll()
- Deprecated. Replaced by
removeList()55Deprecated. Since an
RDFListdoes not behave like a Java container, it is not the case that the contents of the list can be removed and the container filled with values again. Therefore, this method name has been deprecated in favour ofremoveList()55
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()55 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:firststatement is the only mention of that resource in the model.
remove
public RDFList remove(RDFNode val)
Remove the given value from this list. If
valdoes 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
iterator
public com.hp.hpl.jena.util.iterator.ExtendedIterator 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()55 .
asJavaList
public java.util.List asJavaList()
Answer the contents of this RDF list as a Java list of RDFNode values.
sameListAs
public boolean sameListAs(RDFList list)
Answer true if this list has the same elements in the same order as the given list. Note that the standard
equalstest 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.
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. If the list is invalid, the reason is available via
getValidityErrorMessage()55 .
getValidityErrorMessage
public java.lang.String getValidityErrorMessage()
Answer the error message returned by the last failed validity check, if any.
|
|||||||||
| Home >> All >> com >> hp >> hpl >> jena >> rdf >> [ model overview ] | PREV CLASS NEXT CLASS | ||||||||
SUMMARY: JAVADOC | SOURCE | DOWNLOAD | NESTED | FIELD | CONSTR | METHOD |
DETAIL: FIELD | CONSTR | METHOD | ||||||||
JAVADOC