Package net.anotheria.anodoc.data
Class DocumentList<D extends Document>
- java.lang.Object
-
- net.anotheria.anodoc.data.DataHolder
-
- net.anotheria.anodoc.data.DocumentList<D>
-
- All Implemented Interfaces:
java.io.Serializable,java.lang.Cloneable,IBasicStoreableObject,ICompositeDataObject
public class DocumentList<D extends Document> extends DataHolder implements ICompositeDataObject
DocumentList represents a list holder for documents. The difference between holding the documents in another document to holding the documents in a list is:
- Documents in the list are ordered (and keeping this order).
- A DocumentList can contain multiple Documents with same name, a Document can't.
- Documents in the list can be accessed by name and position
- Since:
- 1.0
- Version:
- $Id: $Id
- Author:
- another
- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor Description DocumentList(java.lang.String name)Creates a new list with given name.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddDocument(D doc)Adds given document to list (at last position).booleancontainsDocument(java.lang.String id)Returns true if the list contains a document with name equal to parameter name.DgetDocumentAt(int pos)Returns the document at the given position in the list.DgetDocumentById(java.lang.String id)Returns document with given name, if it exists in the list.intgetElementCount()Returns the number of elements in this list.java.util.Enumeration<java.lang.String>getKeys()Returns the keys of the contained documents.java.util.List<D>getList()Returns the underlying list.DgetObject(java.lang.String key)This method is used by the storage to save not only the container, but the underlying data too.longgetSizeInBytes()The 'size' of a DataHolder is needed for the quota calculation.
The size of an atomic DataHolder like a Property should be the real amount of bytes it uses, whether the size of complex objects should be cumulated.
The overhead for administration shouldn't be counted (i.e.java.lang.StringgetStorageId()Returns the id which is used to store this object.voidinsertDocumentAt(D doc, int pos)Inserts given into the list at position with parameter 'pos'.voidremoveDocument(D doc)Removes given document from the list.voidremoveDocumentAt(int pos)Removes document with given position from the list.voidremoveDocumentById(java.lang.String id)Removes document with parameter name from the list, if such a document exists in the list.java.lang.StringtoString()Returns the String representation of this list.net.anotheria.util.xml.XMLNodetoXMLNode()toXMLNode.-
Methods inherited from class net.anotheria.anodoc.data.DataHolder
clone, getId, hashCode, setId
-
-
-
-
Method Detail
-
getDocumentAt
public D getDocumentAt(int pos)
Returns the document at the given position in the list.- Parameters:
pos- a int.- Returns:
- a D object.
-
addDocument
public void addDocument(D doc)
Adds given document to list (at last position).- Parameters:
doc- a D object.
-
getList
public java.util.List<D> getList()
Returns the underlying list. Don't use it, if you don't know for sure.- Returns:
- a
Listobject.
-
removeDocument
public void removeDocument(D doc)
Removes given document from the list. warning: could make problems in distributed environment, unless equals method of the document is distribution save.- Parameters:
doc- a D object.
-
removeDocumentAt
public void removeDocumentAt(int pos)
Removes document with given position from the list.- Parameters:
pos- a int.
-
containsDocument
public boolean containsDocument(java.lang.String id)
Returns true if the list contains a document with name equal to parameter name. Otherwise returns false.- Parameters:
id- aStringobject.- Returns:
- a boolean.
-
getDocumentById
public D getDocumentById(java.lang.String id)
Returns document with given name, if it exists in the list. Otherwise throws a NoSuchDocumentException.- Parameters:
id- aStringobject.- Returns:
- a D object.
- Throws:
NoSuchDocumentException
-
insertDocumentAt
public void insertDocumentAt(D doc, int pos)
Inserts given into the list at position with parameter 'pos'.- Parameters:
doc- a D object.pos- a int.
-
removeDocumentById
public void removeDocumentById(java.lang.String id)
Removes document with parameter name from the list, if such a document exists in the list. Otherwise does nothing.- Parameters:
id- aStringobject.
-
getKeys
public java.util.Enumeration<java.lang.String> getKeys()
Returns the keys of the contained documents.- Specified by:
getKeysin interfaceICompositeDataObject- Returns:
- a
Enumerationobject. - See Also:
ICompositeDataObject.getKeys()
-
getObject
public D getObject(java.lang.String key)
This method is used by the storage to save not only the container, but the underlying data too. It's also used by debug or administration programs to trace a composite object, such as Document. Returns the Document contained in this list under the given key.
Note: a DocumentList can contain more then one entry with a given name, therefore a name of the document isn't unique in the list, but the key is.- Specified by:
getObjectin interfaceICompositeDataObject- Parameters:
key- the key (id) of the contained element/object.- Returns:
- the object associated to the key.
- See Also:
ICompositeDataObject.getObject(String)
-
getStorageId
public java.lang.String getStorageId()
Returns the id which is used to store this object. This id should be an unique identifier in the objects environment (container). Returns the storage id of this list.- Specified by:
getStorageIdin interfaceIBasicStoreableObject- Returns:
- id which is used to store this object
- See Also:
IBasicStoreableObject.getStorageId()
-
toString
public java.lang.String toString()
Returns the String representation of this list.- Overrides:
toStringin classjava.lang.Object
-
getElementCount
public int getElementCount()
Returns the number of elements in this list.- Returns:
- a int.
-
getSizeInBytes
public long getSizeInBytes()
The 'size' of a DataHolder is needed for the quota calculation.
The size of an atomic DataHolder like a Property should be the real amount of bytes it uses, whether the size of complex objects should be cumulated.
The overhead for administration shouldn't be counted (i.e. the size of an IntProperty is the amount of bytes needed to store the int value itself, not the amount of bytes needed to store the DataHolder object). Returns the cumulative size of contained documents.- Specified by:
getSizeInBytesin classDataHolder- Returns:
- a long.
- See Also:
DataHolder.getSizeInBytes()
-
toXMLNode
public net.anotheria.util.xml.XMLNode toXMLNode()
toXMLNode.
- Overrides:
toXMLNodein classDataHolder- Returns:
- a
XMLNodeobject.
-
-