Class DocumentList<D extends Document>

  • 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:
    1. Documents in the list are ordered (and keeping this order).
    2. A DocumentList can contain multiple Documents with same name, a Document can't.
    3. 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
      void addDocument​(D doc)
      Adds given document to list (at last position).
      boolean containsDocument​(java.lang.String id)
      Returns true if the list contains a document with name equal to parameter name.
      D getDocumentAt​(int pos)
      Returns the document at the given position in the list.
      D getDocumentById​(java.lang.String id)
      Returns document with given name, if it exists in the list.
      int getElementCount()
      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.
      D getObject​(java.lang.String key)
      This method is used by the storage to save not only the container, but the underlying data too.
      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.
      java.lang.String getStorageId()
      Returns the id which is used to store this object.
      void insertDocumentAt​(D doc, int pos)
      Inserts given into the list at position with parameter 'pos'.
      void removeDocument​(D doc)
      Removes given document from the list.
      void removeDocumentAt​(int pos)
      Removes document with given position from the list.
      void removeDocumentById​(java.lang.String id)
      Removes document with parameter name from the list, if such a document exists in the list.
      java.lang.String toString()
      Returns the String representation of this list.
      net.anotheria.util.xml.XMLNode toXMLNode()
      toXMLNode.
      • Methods inherited from class java.lang.Object

        equals, finalize, getClass, notify, notifyAll, wait, wait, wait
    • Constructor Detail

      • DocumentList

        public DocumentList​(java.lang.String name)
        Creates a new list with given name.
        Parameters:
        name - a String object.
    • 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 List object.
      • 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 - a String object.
        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 - a String object.
        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 - a String object.
      • 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:
        getObject in interface ICompositeDataObject
        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:
        getStorageId in interface IBasicStoreableObject
        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:
        toString in class java.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:
        getSizeInBytes in class DataHolder
        Returns:
        a long.
        See Also:
        DataHolder.getSizeInBytes()
      • toXMLNode

        public net.anotheria.util.xml.XMLNode toXMLNode()

        toXMLNode.

        Overrides:
        toXMLNode in class DataHolder
        Returns:
        a XMLNode object.