|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectde.fu_berlin.ties.io.FieldContainer
public class 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(String key)
Helper method that adds a key to the set of all keys. |
int |
attributeCount()
Returns the number of attributes stored in this container. |
Iterator<String> |
attributeIterator()
Returns an iterator over the names of the attributes stored in this container. |
FieldMap |
backgroundMap()
This map can be used to extend newly added field maps: at each add(FieldMap) operation, any key/value pairs from this map are
added to field map prior to storing it. |
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. |
FieldContainer |
createNestedContainer(String name)
Creates and returns a new nested subcontainer. |
List<Object> |
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<FieldMap> |
entryIterator()
Returns an iterator over the FieldMap s in this container in the
order they were added. |
Object |
getAttribute(String name)
Returns the value of an attribute. |
FieldContainer |
getNestedContainer(String name)
Returns a nested subcontainer managed by this instance. |
int |
keyCount()
Returns the number of keys in this container. |
Iterator<String> |
keyIterator()
Returns an iterator over the set of all keys used in contained field maps. |
int |
nestedCount()
Returns the number of nested containers managed by container. |
Iterator<String> |
nestedIterator()
Returns an iterator over the names of nested containers managed by this container. |
static String |
recommendedExtension()
Returns the file extension recommended for FieldContainer s. |
Object |
setAttribute(String name,
Object value)
Sets name and value of an attribute. |
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. Internally uses
IOUtils.openCompressableInStream(InputStream)
so
gzip
-compressed streams are also supported.
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(String 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 int attributeCount()
public Iterator<String> attributeIterator()
public FieldMap backgroundMap()
add(FieldMap)
operation, any key/value pairs from this map are
added to field map prior to storing it. The map is empty by default.
public FieldContainer createNestedContainer(String name) throws IllegalArgumentException
name
- the name of the new subcontainer
IllegalArgumentException
- if the specified name contains
whitespace or is null or empty or if a nested container with the
given name already existspublic List<Object> 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<FieldMap> entryIterator()
FieldMap
s in this container in the
order they were added.
public Object getAttribute(String name)
name
- the name of the attribute to look up
null
if the
attribute doesn't existpublic FieldContainer getNestedContainer(String name)
name
- the name of the container to retrieve
null
if there is no
container with this namepublic int keyCount()
public Iterator<String> keyIterator()
public int nestedCount()
public Iterator<String> nestedIterator()
public int size()
public void store(OutputStream out) throws IOException
store(Writer)
.
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 Object setAttribute(String name, Object value) throws IllegalArgumentException
name
- the name of the attribute, must not contain whitespacevalue
- to value of the attribute
null
if there was no previous value
IllegalArgumentException
- if the specified name contains
whitespace or is null or emptypublic 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()
toString
in class Object
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |