public interface Buffer
extends java.io.Serializable, java.lang.Cloneable
An Item may have a compound value that contains another Buffer. Buffers can be nested to arbitrary level. Leafs of a Buffer tree structure are always simple values like String or Integer, so Buffers can be easily serialized to a byte or character stream.
More formally a buffer can represent any data structure that meets the following BNF definition:
Buffer ::= [Header] {Item} Item ::= [Name] [Type] [Status] Value Value ::= String | Integer | Date | Buffer where [X] means 0 or 1 occurrences of X, and {X} means 0, 1 or many occurrences of XA Buffer can contain meta-data (name and type of each item in the buffer structure), data (value of each item), or both.
A Buffer can have many String representations, which are created by BufferFormatters.
WRITE access to the Buffer:
The following method appends a specified Item to the end of the item list in this Buffer and returns the position of the newly created item. This may lead to duplicate item names.
public int addItem( Item item );The following methods create and append a new Item to the end of the item list in this Buffer and returns the position of the newly created item. This may lead to duplicate item names.
public int addItem( String itemName, XXX value );where XXX is one of: Buffer, String, Int, ... (a value of an item)
READ access to the Buffer:
The following methods return the indexed item or the first occurrence of the named item. They throw an exception or return a default value, if such item does not exist.
public XXX getXXX( int position ); // throws RuntimeException public XXX getXXX( String itemName ) throws ItemNotFoundException; public XXX getXXX( String itemName, XXX default_value );where XXX is one of:
Item (an item itself) or Buffer, String, Int, ... (a value of an item)
Modifier and Type | Method and Description |
---|---|
int |
addItem(Item item)
Append a specified Item to the end of the item list in this Buffer.
|
int |
addItem(java.lang.String itemName,
Buffer value)
Create and append a new Item to this buffer.
|
int |
addItem(java.lang.String itemName,
int value)
Create and append a new Item to this buffer.
|
int |
addItem(java.lang.String itemName,
java.lang.Object value)
Create and append a new Item to this buffer.
|
int |
addItem(java.lang.String itemName,
java.lang.String value)
Create and append a new Item to this buffer.
|
void |
clear()
Clear the contents of this buffer.
|
java.lang.Object |
clone()
Clone this Buffer.
|
int |
countItems()
Return the number of items collected in this Buffer.
|
int |
countItems(java.lang.String name)
Return the number of items with the specified name.
|
boolean |
equals(java.lang.Object obj)
Compares this buffer to another one.
|
Item |
findItem(java.lang.String itemName)
Find a named Item inthis Buffer.
|
void |
freeze()
Freezes this buffer.
|
Buffer |
getBuffer(int position)
Get the value of the item at the specified position.
|
Buffer |
getBuffer(java.lang.String itemName)
Get the value of the item with the specified name.
|
Buffer |
getBuffer(java.lang.String itemName,
Buffer defaultValue)
Get the value of the item with the specified name.
|
java.lang.String |
getHeader()
Get the header of this Buffer.
|
int |
getInt(int position)
Get the value of the item at the specified position.
|
int |
getInt(java.lang.String itemName)
Get the value of the item with the specified name.
|
int |
getInt(java.lang.String itemName,
int defaultValue)
Get the value of the item with the specified name.
|
Item |
getItem(int position)
Get the item at the specified position.
|
Item |
getItem(java.lang.String itemName)
Get the item with the specified name.
|
Item |
getItem(java.lang.String itemName,
Item defaultValue)
Get the item with the specified name.
|
int |
getItemPosition(java.lang.String itemName)
Get the position of the first occurrence of a named Item.
|
java.lang.Object |
getObject(int position)
Get the value of the item at the specified position.
|
java.lang.Object |
getObject(java.lang.String itemName)
Get the value of the item with the specified name.
|
java.lang.Object |
getObject(java.lang.String itemName,
java.lang.Object defaultValue)
Get the value of the item with the specified name.
|
java.lang.String |
getString(int position)
Get the value of the item at the specified position.
|
java.lang.String |
getString(java.lang.String itemName)
Get the value of the item with the specified name.
|
java.lang.String |
getString(java.lang.String itemName,
java.lang.String defaultValue)
Get the value of the item with the specified name.
|
int |
hashCode()
Compute the hash code for this Buffer
|
int |
insertItem(Item item,
int position)
Insert a specified Item at the specified position (0,1, ...) in
the item list.
|
boolean |
isFrozen()
Indicates if this buffer is frozen.
|
BufferIterator |
iterator()
Return an iterator over all items in this Buffer.
|
Buffer |
newInstance()
Return a new (empty) instance of the same class as this Buffer
|
Item |
newItem()
Return a new instance of Item
|
void |
removeItem(int position)
Remove the Item at a specified position (0,1, ...) in this Buffer
|
void |
removeItem(java.lang.String name)
Remove the named item from the item list in this Buffer.
|
void |
removeItems()
Remove all items from this Buffer
|
void |
setHeader(java.lang.String header)
Set the header of this Buffer.
|
int |
setItem(java.lang.String itemName,
int value)
Mofify the first occurence of a named item, or create a new item,
if such item does not exist.
|
int |
setItem(java.lang.String itemName,
java.lang.String value)
Mofify the first occurence of a named item, or create a new item,
if such item does not exist.
|
void |
unfreeze()
Un-freezes this buffer.
|
void setHeader(java.lang.String header)
header
- string describing the contents of this bufferjava.lang.String getHeader()
int countItems()
int countItems(java.lang.String name)
name
- item nameBufferIterator iterator()
int addItem(Item item)
item
- an item to add to this bufferint addItem(java.lang.String itemName, java.lang.Object value)
itemName
- item namevalue
- item valueint addItem(java.lang.String itemName, Buffer value)
itemName
- item namevalue
- item valueint addItem(java.lang.String itemName, java.lang.String value)
itemName
- item namevalue
- item valueint addItem(java.lang.String itemName, int value)
itemName
- item namevalue
- item valueint insertItem(Item item, int position)
item
- the item to insertposition
- a zero-bassed indexint setItem(java.lang.String itemName, java.lang.String value)
itemName
- item namevalue
- item valueint setItem(java.lang.String itemName, int value)
itemName
- item namevalue
- item valueint getItemPosition(java.lang.String itemName)
itemName
- item nameItem getItem(int position)
position
- a zero-based index of an existing item in the bufferItem getItem(java.lang.String itemName) throws ItemNotFoundException
itemName
- item nameItemNotFoundException
- if the specified item does not existItem getItem(java.lang.String itemName, Item defaultValue)
itemName
- item namedefaultValue
- the default value (possibly null)java.lang.String getString(int position)
position
- an index to an existing item in the bufferjava.lang.String getString(java.lang.String itemName) throws ItemNotFoundException
itemName
- item nameItemNotFoundException
- if the specified item does not existjava.lang.String getString(java.lang.String itemName, java.lang.String defaultValue)
itemName
- item namedefaultValue
- the default value (possibly null)int getInt(int position)
position
- an index to an existing item in the bufferint getInt(java.lang.String itemName) throws ItemNotFoundException
itemName
- item nameItemNotFoundException
- if the specified item does not existint getInt(java.lang.String itemName, int defaultValue)
itemName
- item namedefaultValue
- the default valuejava.lang.Object getObject(int position)
position
- an index of an existing item in the bufferjava.lang.Object getObject(java.lang.String itemName) throws ItemNotFoundException
itemName
- item nameItemNotFoundException
- if the specified item does not existjava.lang.Object getObject(java.lang.String itemName, java.lang.Object defaultValue)
itemName
- item namedefaultValue
- the default value (possibly null)Buffer getBuffer(int position)
position
- an index to an existing item in the bufferBuffer getBuffer(java.lang.String itemName) throws ItemNotFoundException
itemName
- item nameItemNotFoundException
- if the specified item does not existBuffer getBuffer(java.lang.String itemName, Buffer defaultValue)
itemName
- item namedefaultValue
- the default value (possibly null)void removeItem(java.lang.String name)
name
- the name of an itemvoid removeItem(int position)
position
- zero-based index of an existing itemvoid removeItems()
Item findItem(java.lang.String itemName)
itemName
- item namevoid clear()
Buffer newInstance()
boolean equals(java.lang.Object obj)
equals
in class java.lang.Object
java.lang.Object clone()
int hashCode()
hashCode
in class java.lang.Object
Item newItem()
boolean isFrozen()
void freeze()
void unfreeze()