com.hp.hpl.jena.daml.common
Class DAMLListImpl

java.lang.Object
  |
  +--com.hp.hpl.mesa.rdf.jena.common.ResourceImpl
        |
        +--com.hp.hpl.jena.daml.common.DAMLCommonImpl
              |
              +--com.hp.hpl.jena.daml.common.DAMLListImpl
All Implemented Interfaces:
DAMLCommon, DAMLList, RDFNode, Resource, ResourceI

public class DAMLListImpl
extends DAMLCommonImpl
implements DAMLList

Java representation of a DAML List. A list is the specified interpretation of rdf:parseType="daml:Collection" attributes, where a sequence of values is interpreted as a nested sequence of head/tail list cells. One consequence of this is that the list is quite specifically ordered, whereas the daml:collection is said to be an unordered collection. Consquently, we must caution that future versions of the DAML specificiation may create an unordered interpretation of daml:collection, and client code should not rely on the positionality of elements in the current list interpretation.

Version:
CVS info: $Id: DAMLListImpl.java,v 1.1 2001/09/24 17:02:42 ijd Exp $
Author:
Ian Dickinson, HP Labs (email)

Constructor Summary
DAMLListImpl(java.lang.String uri, DAMLModel store, DAMLVocabulary vocabulary)
          Constructor, takes the URI for this list, and the underlying model it will be attached to.
DAMLListImpl(java.lang.String namespace, java.lang.String name, DAMLModel store, DAMLVocabulary vocabulary)
          Constructor, takes the name and namespace for this list, and the underlying model it will be attached to.
 
Method Summary
 void add(DAMLCommon value)
          Add an element to the list.
 DAMLList cons(DAMLCommon value)
          Answer a new list formed by creating a new DAMLList element whose first is the given value and whose rest is the current list.
 DAMLList findLast()
          Find the last list element, i.e.
 java.util.Iterator getAll()
          Answer an iteration over the values in the list.
 int getCount()
          Answer a count of the items in the list.
 DAMLCommon getFirst()
          Answer the first value from the list.
 DAMLCommon getItem(int i)
          Answer the i'th element of the list, if it exists.
 DAMLList getNil()
          Answer the well-known constant denototing the nil list.
 DAMLList getRest()
          Answer a new list that consists of all values of the list save the first.
 boolean isEmpty()
          Answer true if the list has no values.
 boolean isNil(Resource resource)
          Answer true if the given resource is the nil list.
 void remove(DAMLCommon value)
          Remove the given value from the list.
 void setFirst(DAMLCommon value)
          Set the property daml:first for the given list element.
 void setRest(DAMLList tail)
          Set the property daml:rest for the given list element.
 void setRestNil()
          Set the property daml:rest for the given list element to be the nil list.
 
Methods inherited from class com.hp.hpl.jena.daml.common.DAMLCommonImpl
getAll, getDAMLModel, getEquivalenceSet, getEquivalentValues, getNumPropertyValues, getPropertyValue, getPropertyValues, getRDFTypes, getSelfIterator, getVocabulary, hasRDFType, hasRDFType, prop_comment, prop_equivalentTo, prop_label, prop_type, remove, removeAll, removeProperty, replaceProperty, setPropertyValue, setRDFType, setRDFType, toString
 
Methods inherited from class com.hp.hpl.mesa.rdf.jena.common.ResourceImpl
abort, addProperty, addProperty, addProperty, addProperty, addProperty, addProperty, addProperty, addProperty, addProperty, begin, commit, equals, getEmbeddedResource, getId, getLocalName, getModel, getNameSpace, getProperty, getURI, hashCode, hasProperty, hasProperty, hasProperty, hasProperty, hasProperty, hasProperty, hasProperty, hasProperty, hasProperty, hasProperty, isAnon, listProperties, listProperties, port, removeProperties
 
Methods inherited from class java.lang.Object
getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface com.hp.hpl.jena.daml.DAMLCommon
getAll, getDAMLModel, getEquivalenceSet, getEquivalentValues, getNumPropertyValues, getPropertyValue, getPropertyValues, getRDFTypes, getVocabulary, hasRDFType, hasRDFType, prop_comment, prop_equivalentTo, prop_label, prop_type, remove, removeAll, removeProperty, replaceProperty, setPropertyValue, setRDFType, setRDFType
 
Methods inherited from interface com.hp.hpl.mesa.rdf.jena.model.Resource
abort, addProperty, addProperty, addProperty, addProperty, addProperty, addProperty, addProperty, addProperty, addProperty, begin, commit, equals, getId, getLocalName, getModel, getNameSpace, getProperty, getURI, hasProperty, hasProperty, hasProperty, hasProperty, hasProperty, hasProperty, hasProperty, hasProperty, hasProperty, hasProperty, isAnon, listProperties, listProperties, removeProperties, toString
 

Constructor Detail

DAMLListImpl

public DAMLListImpl(java.lang.String uri,
                    DAMLModel store,
                    DAMLVocabulary vocabulary)
Constructor, takes the URI for this list, and the underlying model it will be attached to.
Parameters:
uri - The URI of the list
store - The RDF store that contains the RDF statements defining the properties of the list
vocabulary - Reference to the DAML vocabulary used by this list.

DAMLListImpl

public DAMLListImpl(java.lang.String namespace,
                    java.lang.String name,
                    DAMLModel store,
                    DAMLVocabulary vocabulary)
Constructor, takes the name and namespace for this list, and the underlying model it will be attached to.
Parameters:
namespace - The namespace the list inhabits, or null
name - The name of the list
store - The RDF store that contains the RDF statements defining the properties of the list
vocabulary - Reference to the DAML vocabulary used by this list.
Method Detail

add

public void add(DAMLCommon value)
Add an element to the list. The element will in fact be added to the end of the list, but DAML collections are, strictly speaking, unordered, so the position of the element in the list should not be relied upon. This is a side-effectful operation. See cons(com.hp.hpl.jena.daml.DAMLCommon) for an operation that always returns a new list (i.e. no side-effects on this list).
Specified by:
add in interface DAMLList
Parameters:
value - A DAML value to add to the list

remove

public void remove(DAMLCommon value)
Remove the given value from the list. If the value is not in the list, has no effect. If the value is in the list multiple times, only one of them will be removed.
Specified by:
remove in interface DAMLList
Parameters:
value - A DAML value to be removed from the list.

getAll

public java.util.Iterator getAll()
Answer an iteration over the values in the list.
Specified by:
getAll in interface DAMLList
Returns:
An iterator over the DAML values in the list

getFirst

public DAMLCommon getFirst()
Answer the first value from the list. Since, strictly speaking, DAML collections are unordered, the position items in the list should not be relied on in client code, as the definition of 'first' in the list may change in future releases. However, the identity
      List L = L.getFirst() + L.getRest()
 
is guaranteed, providing that the contents of L do not change.
Specified by:
getFirst in interface DAMLList
Returns:
The first value in the list, or, strictly, an unspecified value from the list.

getRest

public DAMLList getRest()
Answer a new list that consists of all values of the list save the first. Since, strictly speaking, DAML collections are unordered, this corresponds to returning the collection minus an unspecified one of its values. However, the identity
      List L = L.getFirst() + L.getRest()
 
is guaranteed, providing that the contents of L do not change.
Specified by:
getRest in interface DAMLList
Returns:
a list that contains all the elements of the current list save one.

getCount

public int getCount()
Answer a count of the items in the list. Does not check for duplications, so this is the count of entries in the list, not the count of distinct items in the list.
Specified by:
getCount in interface DAMLList
Returns:
The number of entries in the list

isEmpty

public boolean isEmpty()
Answer true if the list has no values. The nil list is empty, as is the list with no first and no rest. Note that we retain both conditions as we define the primary resource of a DAML value to be invariant (for indexing purposes). Therefore, a newly created list must be empty, but must not be identical to the nil list since we could never then change it to be a list of values.
Specified by:
isEmpty in interface DAMLList
Returns:
true for an empty list

setFirst

public void setFirst(DAMLCommon value)
Set the property daml:first for the given list element. This is a single value that denotes the value at this position of the list.
Specified by:
setFirst in interface DAMLList
Parameters:
value - The value to be assigned to the 'first' property of a list cell

setRest

public void setRest(DAMLList tail)
Set the property daml:rest for the given list element. This is a single value that denotes the tail of the list.
Specified by:
setRest in interface DAMLList
Parameters:
value - The value to be assigned to the tail of the list.

setRestNil

public void setRestNil()
Set the property daml:rest for the given list element to be the nil list. This correctly terminates the list at this point.
Specified by:
setRestNil in interface DAMLList

cons

public DAMLList cons(DAMLCommon value)
Answer a new list formed by creating a new DAMLList element whose first is the given value and whose rest is the current list. This is the 'cons' operator familiar from other list processing languages.
Specified by:
cons in interface DAMLList
Parameters:
The - new value to be added to the head of the list
Returns:
a new list whose daml:first is the value, and whose daml:rest is this list.

getNil

public DAMLList getNil()
Answer the well-known constant denototing the nil list.
Specified by:
getNil in interface DAMLList
Returns:
The resource denoting nil

isNil

public boolean isNil(Resource resource)
Answer true if the given resource is the nil list. Will check the namespace of the current vocabulary only.
Specified by:
isNil in interface DAMLList
Parameters:
resource - A resource, that may be the nil list
Returns:
true if the resource has the same URI as the nil list.

findLast

public DAMLList findLast()
Find the last list element, i.e. the one whose rest is nil.
Specified by:
findLast in interface DAMLList
Returns:
A list element

getItem

public DAMLCommon getItem(int i)
Answer the i'th element of the list, if it exists. If i is less than 1, or is larger than the length of the list, throw an illegal argument exception.
Specified by:
getItem in interface DAMLList
Parameters:
i - The position of the list to return
Returns:
The DAML value at the i'th position in the list
Throws:
java.lang.IllegalArgumentException - if i is less than one, or larger than the length of the list.


Copyright © 2001 Hewlett-Packard. All Rights Reserved.