|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectde.fu_berlin.ties.io.FieldContainer
A container of FieldMap
s. A container stores all
field maps added to itself and keeps a set of all keys found in the field
maps. This is an "append-only" container; field maps can only be added but
never removed.
Instances of this class are not thread-safe and must be synchronized externally, if required.
Constructor Summary | |
FieldContainer()
Creates a new empty instance. |
|
FieldContainer(StorableContainer contents)
Creates a new instance and populates it from a StorableContainer . |
Method Summary | |
void |
add(FieldMap map)
Adds a field map to this container. |
protected void |
add(FieldMap map,
boolean checkKeys)
Helper method for adding a field map to this container. |
void |
add(List values)
Adds a field map created from the specified values, using the n-th key from the set of all keys for the n-th specified value. |
void |
add(Storable storable)
Adds the representation of a Storable to this container, by
calling its Storable.storeFields() method and adding the
resulting field map. |
protected boolean |
addKey(Object key)
Helper method that adds a key to to the set of all keys. |
static FieldContainer |
createFieldContainer()
Factory method that creates a field container in DelimSepValues
format. |
static FieldContainer |
createFieldContainer(CharSequence input)
Factory method that creates a field container from serialized data in DelimSepValues format. |
static FieldContainer |
createFieldContainer(InputStream in)
Factory method that creates a field container from serialized data in DelimSepValues format. |
static FieldContainer |
createFieldContainer(Reader reader)
Factory method that creates a field container from serialized data in DelimSepValues format. |
List |
createObjects(Class type)
Creates (deserializes) an list of objects of a specified type by calling FieldMap.createObject(Class) for each of the field maps contained
in this container. |
Iterator |
entryIterator()
Returns an iterator over the FieldMap s in this container in the
order they were added. |
int |
keyCount()
Returns the number of keys in this container. |
Iterator |
keyIterator()
Returns an iterator over the set of all keys used in contained field maps. |
static String |
recommendedExtension()
Returns the file extension recommended for FieldContainer s. |
int |
size()
Returns the number of entries stored in this container. |
void |
store(OutputStream out)
Serializes contents by wrapping the stream in a writer with UTF-8 character set and delegating to store(Writer) . |
void |
store(Writer writer)
Subclasses can overwrite this method to serialize their contents in a class-specific format. |
String |
toString()
Returns a string representation of this object. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Constructor Detail |
public FieldContainer()
public FieldContainer(StorableContainer contents)
StorableContainer
.
contents
- the contents to add by calling
StorableContainer.storeEntries(FieldContainer)
Method Detail |
public static FieldContainer createFieldContainer()
DelimSepValues
format.
public static FieldContainer createFieldContainer(CharSequence input) throws IllegalArgumentException
DelimSepValues
format.
input
- the input data to process
IllegalArgumentException
- if the input data contains errorspublic static FieldContainer createFieldContainer(InputStream in) throws IOException, IllegalArgumentException
DelimSepValues
format.
in
- a stream containing the input data to process, must use the
UTF-8 charset; the stream is not closed by this method
IOException
- if an I/O error occurs while reading from the stream
IllegalArgumentException
- if the input data contains errorspublic static FieldContainer createFieldContainer(Reader reader) throws IOException, IllegalArgumentException
DelimSepValues
format.
reader
- a reader containing the input data to process; not closed
by this method
IOException
- if an I/O error occurs while reading from the stream
IllegalArgumentException
- if the input data contains errorspublic static String recommendedExtension()
FieldContainer
s.
DelimSepValues.FILE_EXT
protected boolean addKey(Object key)
key
- the key to add
true
if the set did not already contain the
specified elementpublic void add(FieldMap map)
map
- the field map to addpublic void add(Storable storable)
Storable
to this container, by
calling its Storable.storeFields()
method and adding the
resulting field map.
storable
- the storable whose fields to addprotected void add(FieldMap map, boolean checkKeys)
map
- the field map to addcheckKeys
- whether to check the keys of the field map and add any
missing keys to the set of all keys; subclasses calling this method can
set this to false
iff they know for sure that the map does
not contain any new keyspublic void add(List values) throws IllegalArgumentException
null
values are omitted
(the corresponding key is skipped).
values
- the list of values to store in the field map
IllegalArgumentException
- if the specified array contains more
elements than the set of all keyspublic List createObjects(Class type) throws InstantiationException, SecurityException
FieldMap.createObject(Class)
for each of the field maps contained
in this container. The contained field maps are deserialized in the order
they were added to this container.
type
- the class of the objects to create; must have a constructor
whose only argument is a FieldMap
InstantiationException
- if instantiation failed
SecurityException
- if access to the required reflection
information is deniedpublic Iterator entryIterator()
FieldMap
s in this container in the
order they were added.
public int keyCount()
public Iterator keyIterator()
public int size()
public void store(OutputStream out) throws IOException
store(Writer)
. Subclasses can
overwrite this method, e.g. if they prefer another character set.
out
- the output stream to write to; flushed but not closed by this
method
IOException
- if an I/O error occurs while writing to the streampublic void store(Writer writer) throws IOException, UnsupportedOperationException
UnsupportedOperationException
instead.
writer
- the writer to write to; not closed by this method
IOException
- might be thrown by subclasses if an I/O error occurs
while serializing the data
UnsupportedOperationException
- always thrown by instances of this
classpublic String toString()
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |