de.grogra.util
Class HierarchicalQueue

java.lang.Object
  extended by java.io.OutputStream
      extended by de.grogra.util.OutputQueue
          extended by de.grogra.util.HierarchicalQueue
All Implemented Interfaces:
java.io.Closeable, java.io.DataOutput, java.io.Flushable, java.io.ObjectOutput
Direct Known Subclasses:
GraphQueue, XAQueue

public class HierarchicalQueue
extends OutputQueue
implements java.io.ObjectOutput

A HierarchicalQueue equips an OutputQueue with a record-like, hierarchical structure. Each record is called an item, the type of which is identified by the first int-value of the record. Items follow each other in a linked list (the link is established by relative addresses which are stored in an item's header structure, see below). The item of type BEGIN_LEVEL indicates a nesting of items, it contains another linked list of items.

A whole item is represented by the following structure in the int-queue:

  1. int-value at offset 0: item type
  2. int-value at offset 1: difference between this item's address (the absolute index of offset 0) and the address of the previous item. If no previous item exists, -1 is used for the latter address. The first item which is contained in a new level has no previous item.
  3. The following ints contain the total number of int, byte, long, float, double, Object-values in this order. If the total number of values of one of these types is always the same for the item type, this number is not present in the structure. The total number of values for an item type is set by the method setItemSize(int, int, int, int, int, int, int).
  4. The following ints represent the data of the item in its specific format

An item of type BEGIN_LEVEL is used to store the whole information of the nested items it contains. It uses an additional int-value as first value of its data: Its value is the difference between the address of the last contained item and this item.

Author:
Ole Kniemeyer

Nested Class Summary
 class HierarchicalQueue.Cursor
           
static class HierarchicalQueue.Data
           
 class HierarchicalQueue.Reader
           
 
Field Summary
static int BEGIN_LEVEL
           
static int IS_FINISHED
           
static int ITEM_AND_BITS_MASK
           
static int ITEM_MASK
           
static int MAX_UNUSED_BIT
           
static int MIN_UNUSED_BIT
           
static int MIN_UNUSED_ITEM
           
static int NEXT_EXISTS
           
protected  java.io.ObjectOutputStream out
           
 
Constructor Summary
HierarchicalQueue(boolean usesObjectQueue, boolean createBackLinks)
           
 
Method Summary
 void beginLevel()
           
 int beginSkipBlock()
           
 void clear()
           
 HierarchicalQueue.Data cloneData()
           
protected  HierarchicalQueue.Data createData()
           
 void discardLevel()
           
 void endLevel()
           
 void endSkipBlock(int beginIndex)
           
 HierarchicalQueue.Cursor getCursor(HierarchicalQueue.Cursor c)
           
 HierarchicalQueue.Data getData()
           
 boolean hasItems()
           
 boolean hasItemsInCurrentLevel()
           
 void moveTo(HierarchicalQueue.Cursor c)
           
 void restore(HierarchicalQueue.Data data)
           
 void setItemSize(int item, int bsize, int isize, int lsize, int fsize, int dsize, int asize)
           
 void writeItem(int item)
           
 void writeObject(java.lang.Object o)
           
 void writeObjectInStream(java.lang.Object o)
           
 
Methods inherited from class de.grogra.util.OutputQueue
close, dump, flush, write, write, write, writeBoolean, writeByte, writeBytes, writeChar, writeChars, writeDouble, writeFloat, writeInt, writeLong, writeObjectInQueue, writeShort, writeUTF
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface java.io.ObjectOutput
close, flush, write, write, write
 
Methods inherited from interface java.io.DataOutput
writeBoolean, writeByte, writeBytes, writeChar, writeChars, writeDouble, writeFloat, writeInt, writeLong, writeShort, writeUTF
 

Field Detail

BEGIN_LEVEL

public static final int BEGIN_LEVEL
See Also:
Constant Field Values

IS_FINISHED

public static final int IS_FINISHED
See Also:
Constant Field Values

ITEM_AND_BITS_MASK

public static final int ITEM_AND_BITS_MASK
See Also:
Constant Field Values

ITEM_MASK

public static final int ITEM_MASK
See Also:
Constant Field Values

MAX_UNUSED_BIT

public static final int MAX_UNUSED_BIT
See Also:
Constant Field Values

MIN_UNUSED_BIT

public static final int MIN_UNUSED_BIT
See Also:
Constant Field Values

MIN_UNUSED_ITEM

public static final int MIN_UNUSED_ITEM
See Also:
Constant Field Values

NEXT_EXISTS

public static final int NEXT_EXISTS
See Also:
Constant Field Values

out

protected final java.io.ObjectOutputStream out
Constructor Detail

HierarchicalQueue

public HierarchicalQueue(boolean usesObjectQueue,
                         boolean createBackLinks)
Method Detail

beginLevel

public final void beginLevel()

beginSkipBlock

public final int beginSkipBlock()

clear

public void clear()
Overrides:
clear in class OutputQueue

cloneData

public final HierarchicalQueue.Data cloneData()

createData

protected HierarchicalQueue.Data createData()

discardLevel

public final void discardLevel()

endLevel

public final void endLevel()

endSkipBlock

public final void endSkipBlock(int beginIndex)

getCursor

public final HierarchicalQueue.Cursor getCursor(HierarchicalQueue.Cursor c)

getData

public final HierarchicalQueue.Data getData()

hasItems

public final boolean hasItems()

hasItemsInCurrentLevel

public final boolean hasItemsInCurrentLevel()

moveTo

public final void moveTo(HierarchicalQueue.Cursor c)

restore

public void restore(HierarchicalQueue.Data data)

setItemSize

public final void setItemSize(int item,
                              int bsize,
                              int isize,
                              int lsize,
                              int fsize,
                              int dsize,
                              int asize)

writeItem

public final void writeItem(int item)

writeObject

public void writeObject(java.lang.Object o)
                 throws java.io.IOException
Specified by:
writeObject in interface java.io.ObjectOutput
Overrides:
writeObject in class OutputQueue
Throws:
java.io.IOException

writeObjectInStream

public void writeObjectInStream(java.lang.Object o)
                         throws java.io.IOException
Throws:
java.io.IOException