org.basex.query.iter
Class ValueBuilder

java.lang.Object
  extended by org.basex.query.iter.Iter
      extended by org.basex.query.iter.ValueIter
          extended by org.basex.query.iter.ValueBuilder
All Implemented Interfaces:
java.lang.Iterable<Item>, Result

public final class ValueBuilder
extends ValueIter
implements Result

This class can be used to build new sequences. At the same time, it serves as an iterator.

Author:
BaseX Team 2005-12, BSD License, Christian Gruen

Field Summary
 Item[] item
          Item container.
 
Constructor Summary
ValueBuilder()
          Constructor.
ValueBuilder(int c)
          Constructor.
ValueBuilder(Item[] arr, int s)
          Constructor.
 
Method Summary
 ValueBuilder add(Item it)
          Adds a single item.
 ValueBuilder add(Value val)
          Adds the contents of a value.
 Item get(long i)
          Returns the specified item, or an arbitrary item if the index is invalid.
 Item next()
          Returns the next item or null if no other items are found.
 boolean reset()
          Resets the iterator and returns true if operation was successful.
 boolean sameAs(Result v)
          Compares results for equality.
 ArrayOutput serialize()
          Serializes the result, using the standard serializer, and returns the cached result.
 void serialize(Serializer ser)
          Serializes the complete result.
 void serialize(Serializer ser, int n)
          Serializes the specified result.
 void set(Item i, int p)
          Sets an item to the specified position.
 long size()
          Returns the iterator size.
 void size(int s)
          Sets the iterator size.
 java.lang.String toString()
           
 Value value()
          Returns a sequence with all iterator values.
 
Methods inherited from class org.basex.query.iter.ValueIter
iterator
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

item

public Item[] item
Item container.

Constructor Detail

ValueBuilder

public ValueBuilder()
Constructor.


ValueBuilder

public ValueBuilder(int c)
Constructor.

Parameters:
c - initial capacity

ValueBuilder

public ValueBuilder(Item[] arr,
                    int s)
Constructor.

Parameters:
arr - initial array
s - initial size
Method Detail

add

public ValueBuilder add(Value val)
Adds the contents of a value.

Parameters:
val - value to be added
Returns:
self reference

add

public ValueBuilder add(Item it)
Adds a single item.

Parameters:
it - item to be added
Returns:
self reference

sameAs

public boolean sameAs(Result v)
Description copied from interface: Result
Compares results for equality.

Specified by:
sameAs in interface Result
Parameters:
v - result to be compared
Returns:
true if results are equal

serialize

public void serialize(Serializer ser)
               throws java.io.IOException
Description copied from interface: Result
Serializes the complete result.

Specified by:
serialize in interface Result
Parameters:
ser - serializer
Throws:
java.io.IOException - I/O exception

serialize

public void serialize(Serializer ser,
                      int n)
               throws java.io.IOException
Description copied from interface: Result
Serializes the specified result.

Specified by:
serialize in interface Result
Parameters:
ser - serializer
n - offset of result to serialize
Throws:
java.io.IOException - I/O exception

next

public Item next()
Description copied from class: Iter
Returns the next item or null if no other items are found.

Specified by:
next in class ValueIter
Returns:
resulting item or null

size

public void size(int s)
Sets the iterator size.

Parameters:
s - size

reset

public boolean reset()
Description copied from class: Iter
Resets the iterator and returns true if operation was successful. false is returned if the iterator cannot be reset.

Specified by:
reset in class ValueIter
Returns:
true if operator could be reset

size

public long size()
Description copied from class: Iter
Returns the iterator size. Note: -1 is returned if the result size is unknown. If this method is implemented by an iterator, Iter.get(long) needs to be implemented as well.

Specified by:
size in interface Result
Specified by:
size in class ValueIter
Returns:
number of entries

get

public Item get(long i)
Description copied from class: Iter
Returns the specified item, or an arbitrary item if the index is invalid. This method needs to be implemented - and should only be called - if Iter.size() returns the correct number of results. A calling method should call Iter.reset() after the last items has been retrieved.

Specified by:
get in class ValueIter
Parameters:
i - value offset
Returns:
specified item

set

public void set(Item i,
                int p)
Sets an item to the specified position.

Parameters:
i - item to be set
p - position

value

public Value value()
Description copied from class: Iter
Returns a sequence with all iterator values. Must only be called if Iter.next() has not been called before.

Overrides:
value in class ValueIter
Returns:
sequence

serialize

public ArrayOutput serialize()
                      throws java.io.IOException
Description copied from interface: Result
Serializes the result, using the standard serializer, and returns the cached result.

Specified by:
serialize in interface Result
Returns:
serialized value
Throws:
java.io.IOException - I/O exception

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object