org.exist.fluent
Class ItemList

java.lang.Object
  extended by org.exist.fluent.Resource
      extended by org.exist.fluent.ItemList
All Implemented Interfaces:
Iterable<Item>

public class ItemList
extends Resource
implements Iterable<Item>

The result of a query on the database, holding a collection of items. The items can be accessed either as structured resources or as string values. It is also possible to further refine the query by executing queries within the context of the results.

Version:
$Revision: 1.17 $ ($Date: 2006/08/14 23:18:22 $)
Author:
Piotr Kaminski

Nested Class Summary
 class ItemList.NodesFacet
          A facet that treats each item in the list as a node.
 class ItemList.ValuesFacet
          A facet that treats each item in the list as its effective string value.
 
Method Summary
 List<Item> asList()
          Return an unmodifiable list view over the list of items.
 void deleteAllNodes()
          Delete all nodes contained in this item list; skip over any items (values) that it doesn't make sense to try to delete.
 boolean equals(Object o)
           
 Item get(int index)
          Return the item at the given index in this result.
 int hashCode()
          The hash code computation can be expensive, and the hash codes may not be very well distributed.
 boolean isEmpty()
          Return whether this item list is empty.
 Iterator<Item> iterator()
          Return an iterator over all the items in this list.
 ItemList.NodesFacet nodes()
          Return a view of this item list as a list of nodes.
 void removeDeletedNodes()
          Remove all deleted nodes from this list.
 int size()
          Return the number of elements in this item list.
 Item[] toArray()
          Convert this list of items to an array.
 Item[] toArray(Item[] a)
          Convert this list of items to an array.
 String toString()
           
 ItemList.ValuesFacet values()
          Return a view of this item list as a list of effective string values.
 
Methods inherited from class org.exist.fluent.Resource
database, namespaceBindings, query
 
Methods inherited from class java.lang.Object
getClass, notify, notifyAll, wait, wait, wait
 

Method Detail

removeDeletedNodes

public void removeDeletedNodes()
Remove all deleted nodes from this list. Trying to access the list in a query context when it contains a deleted node will cause a stale reference exception. You can call this method whenever you suspect this will be the case, preferably just prior to access. This will also update the results for all direct access methods that wouldn't throw an exception, but could return a stale result. The updates aren't done automatically since they involve tricky synchronization issues and are expensive when not batched up, and since most clients won't need this feature.


size

public int size()
Return the number of elements in this item list.

Returns:
the number of elements in this item list

isEmpty

public boolean isEmpty()
Return whether this item list is empty.

Returns:
true if this item list has no elements

get

public Item get(int index)
Return the item at the given index in this result. Indexing starts at 0.

Parameters:
index - the index of the desired item
Returns:
the item at the given index
Throws:
IndexOutOfBoundsException - if the index is out of bounds

deleteAllNodes

public void deleteAllNodes()
Delete all nodes contained in this item list; skip over any items (values) that it doesn't make sense to try to delete.


equals

public boolean equals(Object o)
Overrides:
equals in class Object

hashCode

public int hashCode()
The hash code computation can be expensive, and the hash codes may not be very well distributed. You probably shouldn't use item lists in situations where they might get hashed.

Overrides:
hashCode in class Object

iterator

public Iterator<Item> iterator()
Return an iterator over all the items in this list.

Specified by:
iterator in interface Iterable<Item>
Returns:
an iterator over this item list

asList

public List<Item> asList()
Return an unmodifiable list view over the list of items.

Returns:
a list view

toArray

public Item[] toArray()
Convert this list of items to an array.

Returns:
an array of items

toArray

public Item[] toArray(Item[] a)
Convert this list of items to an array. If the given array is large enough, fill it; if it's larger than necessary, put a null marker after the end of the list. If the array is not large enough, allocate a new one.

Parameters:
a - the array to fill with items
Returns:
an array of items

toString

public String toString()
Overrides:
toString in class Object

values

public ItemList.ValuesFacet values()
Return a view of this item list as a list of effective string values. Note that no extra memory is used to present this view; effective string values are computed on demand.

Returns:
a virtual collection of string values contained in this item list

nodes

public ItemList.NodesFacet nodes()
Return a view of this item list as a list of nodes. If this list contains any items that are not nodes, operations on the facet may fail. Note that no extra memory is used to present this view.

Returns:
a virtual collection of nodes contained in this item list


Copyright (C) All rights reserved.