chemaxon.marvin.view
Class MDocStorage

java.lang.Object
  extended by chemaxon.marvin.view.MDocStorage

public class MDocStorage
extends java.lang.Object

Sparse dynamic document storage and reader.

Since:
Marvin 4.1, 04/13/2006
Version:
5.1.2, 09/18/2008
Author:
Peter Csizmadia, Szilveszter Juhos

Nested Class Summary
 class MDocStorage.CancellationException
          Exception indicating that records are not available because the user cancelled file reading.
static interface MDocStorage.Listener
          Document production listener.
 class MDocStorage.RecordUnavailableException
          Requested record is not available in the source.
 
Constructor Summary
MDocStorage()
          Constructs a document storage.
MDocStorage(int n)
          Constructs a document storage.
 
Method Summary
 void addListener(MDocStorage.Listener l)
          Adds a listener if it is not yet added.
 boolean aromatize(int k, java.lang.String key, boolean v, int method, java.lang.String[] warn)
          Aromatize or dearomatize molecule in the specified cell.
 boolean aromatizeAll(boolean v, int method, java.lang.String[] warn)
          Aromatize or dearomatize molecules in all cells.
 boolean clean(int k, java.lang.String key, int dim, java.lang.String opts, MProgressMonitor pm, java.lang.String[] warn)
          Clean the specified cell.
 boolean cleanAll(int dim, java.lang.String opts, MProgressMonitor pm, java.lang.String[] warn)
          Clean all cells.
 boolean contractOrExpandSgroups(int k, java.lang.String key, boolean contr)
          Contract or expand S-groups in the specified cell.
 boolean contractOrExpandSgroupsAll(boolean contract)
          Contract or expand S-groups in all molecules.
 int countRecordsInFraction(double q, int ncols, MProgressMonitor pmon)
          Counts the number of records between the start and the specified fraction of the total, estimated number of records.
 void doSetSetSeqs(Molecule[] mols, int k, java.lang.String key)
           
 void fillWithNulls()
          Set all stored document entries to null.
 int getCacheCapacity()
          Gets the maximum number of cached documents.
 MDocument getCachedDoc(int k, java.lang.String key)
          Gets the specified document if it is present in the memory.
 int[] getCachedDocIndices()
          Gets the indices of cached records.
 java.lang.Object getCacheLock()
          Gets the synchronization lock for caching operations.
 int getCapacity()
          Gets the total capacity.
 MDocument getDoc(int k, java.lang.String key, MProgressMonitor pmon)
          Gets the specified document.
 java.lang.String getDocLabel(int k, MDocument doc)
          Returns the display label for the given document and document index.
 MDocSource getDocSource()
          Gets the document source.
 int getDocSourcePosition()
          Gets the current position in the input.
 MFieldAccessor getFieldAccessor()
          Gets the field accessor.
 MPropertyContainer getGlobalGUIProperties()
          Gets the Global GUI properties.
 java.lang.String getL(int k, int j)
          Gets a text label in a record.
 MDocStorage.Listener[] getListeners()
           
 MDocument getMainDoc(int k, MProgressMonitor pmon)
          Gets the document at the specified position.
 int getMaxDimCached()
          Gets the maximum molecule dimension.
 DPoint3 getMolCenter(int k, java.lang.String key)
          Gets a molecule center.
 chemaxon.marvin.paint.internal.MolPainter getMolPainter(int k, java.lang.String key)
          Gets a molecule painter.
 int getOffset()
          Gets the offset in the document source.
 int[] getSelectedAtoms(int k, java.lang.String key)
          Gets the selected atom indices.
 int getSize()
          Gets the total number of entries.
 java.lang.String getT(int k, int j)
          Gets a text field in a record.
 boolean hydrogenize(int k, java.lang.String key, boolean hydr, java.lang.String[] warn)
          Hydrogenize molecule in the specified cell.
 boolean hydrogenizeAll(boolean hydr, java.lang.String[] warn)
          Hydrogenize molecules in all cells.
 boolean isEnabledT(int k, int j)
          Tests whether a text field is enabled.
 boolean isFixed(int k)
          Tests whether a record is fixed.
 boolean isFractionQuicklyAvailable(double x)
          Tests whether the specified fraction of the total (estimated) number of records is quickly available.
 boolean isRewindable()
          Tests whether the document storage is rewindable.
 boolean isSizeFinal()
          Tests whether the storage size is final.
 void removeListener(MDocStorage.Listener l)
          Removes a listener.
 void setAtomSetSeq(int k, java.lang.String key, int atom, int seq)
          Sets the atom set sequence number of an atom.
 void setAtomSetSeq(int k, java.lang.String key, java.lang.String str, int setSeq)
          Sets atom set sequence numbers.
 void setAtomSetSeqs(int k, java.lang.String key, int[] seqs)
          Sets atom set sequence numbers.
 void setBondSetSeq(int k, java.lang.String key, int j1, int j2, int seq)
          Sets bond set sequence numbers.
 void setBondSetSeq(int k, java.lang.String key, java.lang.String str, int setSeq)
          Sets bond set sequence numbers.
 void setBondSetSeqAll(int k, java.lang.String key, int seq)
          Sets all bond set sequence numbers.
 void setBondSetSeqs(int k, java.lang.String key, java.util.Vector seqs)
          Sets bond set sequence numbers.
 void setCacheCapacity(int max)
          Sets the maximum number of cached documents.
 void setDocSource(MDocSource dp, int offset, int max)
          Sets the document source.
 void setEnabledT(int k, int j, boolean l)
          Set the enabled state of a text field in a record.
 void setFieldAccessor(MFieldAccessor fa)
          Sets the field accessor.
 void setFixed(int k)
          Sets a document as fixed.
 void setL(int k, int j, java.lang.String l)
          Sets a text label in a record.
 void setListeners(MDocStorage.Listener[] arr)
           
 void setMolCenter(int k, java.lang.String key, DPoint3 p)
          Sets a molecule center.
 void setMolPainter(int k, java.lang.String key, chemaxon.marvin.paint.internal.MolPainter p)
          Sets a molecule painter.
 void setSelectedAtoms(int k, java.lang.String key, int[] sel)
          Sets the selected atom indices.
 void setSelectedAtoms(int k, java.lang.String key, java.lang.String str)
          Sets the selected atom indices.
 void setSize(int n)
          Sets the total number of entries.
 void setT(int k, int j, java.lang.String l)
          Sets a text field in a record.
 void storeDoc(MDocument doc, int k, java.lang.String key)
          Store new document and free the oldest accessed if the number of documents is too much to fit in memory.
 void storeMainDoc(MDocument doc, int k)
          Store new document and free the oldest accessed if the number of documents is too much to fit in memory.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MDocStorage

public MDocStorage()
Constructs a document storage.


MDocStorage

public MDocStorage(int n)
Constructs a document storage.

Parameters:
n - number of documents to store
Method Detail

getDocSource

public MDocSource getDocSource()
Gets the document source.

Returns:
the document source
Since:
Marvin 4.1.6, 03/08/2007

setDocSource

public void setDocSource(MDocSource dp,
                         int offset,
                         int max)
Sets the document source.

Parameters:
dp - the document (molecule) source
offset - number of documents to skip in the source
max - maximum allowed number of documents or 0 (no restriction)

getFieldAccessor

public MFieldAccessor getFieldAccessor()
Gets the field accessor.

Returns:
the field accessor
Since:
Marvin 5.0, 11/09/2007

setFieldAccessor

public void setFieldAccessor(MFieldAccessor fa)
Sets the field accessor.

Parameters:
fa - the field accessor
Since:
Marvin 5.0, 11/09/2007

getOffset

public int getOffset()
Gets the offset in the document source.

Returns:
the first record index
Since:
Marvin 5.0, 11/18/2007

getDocSourcePosition

public int getDocSourcePosition()
Gets the current position in the input.

Returns:
the position or -1 if there is no document source

addListener

public void addListener(MDocStorage.Listener l)
Adds a listener if it is not yet added.

Parameters:
l - the listener

removeListener

public void removeListener(MDocStorage.Listener l)
Removes a listener.

Parameters:
l - the listener

getListeners

public MDocStorage.Listener[] getListeners()

setListeners

public void setListeners(MDocStorage.Listener[] arr)

getSize

public int getSize()
Gets the total number of entries.

Returns:
the total number of entries

setSize

public void setSize(int n)
Sets the total number of entries. (Resize the arrays.)

Parameters:
n - new capacity (maximum number of documents)

isSizeFinal

public boolean isSizeFinal()
Tests whether the storage size is final.

Returns:
true is the storage will not grow, false if it may grow

getCapacity

public int getCapacity()
Gets the total capacity.

Returns:
the maximum number of entries (without reallocation)

getCacheCapacity

public int getCacheCapacity()
Gets the maximum number of cached documents.

Returns:
the cache capacity or 0 if everything is stored

setCacheCapacity

public void setCacheCapacity(int max)
Sets the maximum number of cached documents.

Parameters:
max - maximum number of documents in memory or 0 to store everything

getCachedDocIndices

public int[] getCachedDocIndices()
Gets the indices of cached records.

Returns:
array of indices

isRewindable

public boolean isRewindable()
Tests whether the document storage is rewindable. It is rewindable if either the document source is rewindable (e.g. a seekable input stream) or all documents are stored permanently in memory after reading (if cache size equals the total capacity).

Returns:
true if backward seeking is possible, false otherwise

getDoc

public MDocument getDoc(int k,
                        java.lang.String key,
                        MProgressMonitor pmon)
                 throws MDocStorage.RecordUnavailableException,
                        MDocStorage.CancellationException,
                        java.io.IOException
Gets the specified document.

Parameters:
k - the record index
key - the molecule (or document) field name, null for the main document (molecule)
pmon - progress monitor or null
Throws:
MDocStorage.RecordUnavailableException - if the requested record is not available (probably end of file reached too early)
MDocStorage.CancellationException - if the user cancelled the operation
java.io.IOException - if read error occured

getMainDoc

public MDocument getMainDoc(int k,
                            MProgressMonitor pmon)
                     throws MDocStorage.RecordUnavailableException,
                            MDocStorage.CancellationException,
                            java.io.IOException
Gets the document at the specified position.

Parameters:
k - the record index
pmon - progress monitor or null
Returns:
the document or null
Throws:
MDocStorage.RecordUnavailableException - if the requested record is not available (probably end of file reached too early)
MDocStorage.CancellationException - if the user cancelled the operation
java.io.IOException - if read error occured

getDocLabel

public java.lang.String getDocLabel(int k,
                                    MDocument doc)
Returns the display label for the given document and document index. The default implementation returns k+1 as String, where k is the document index.

Parameters:
k - the document index
doc - the document
Returns:
the document label
Since:
Marvin 5.0

countRecordsInFraction

public int countRecordsInFraction(double q,
                                  int ncols,
                                  MProgressMonitor pmon)
                           throws java.io.IOException
Counts the number of records between the start and the specified fraction of the total, estimated number of records.

Parameters:
q - the fraction, floating point number between 0 and 1
ncols - the number of columns (1 if there are no more columns)
pmon - progress monitor or null
Returns:
the estimated number of records in the specified fraction or -1 if the user canceled the progress monitor
Throws:
java.io.IOException - if read error occured

isFractionQuicklyAvailable

public boolean isFractionQuicklyAvailable(double x)
Tests whether the specified fraction of the total (estimated) number of records is quickly available. A record is quickly available if its file position is known (because it was previously retrieved or skipped) or it is in the memory (if no document source is present).

Parameters:
x - the fraction, floating point number between 0 and 1
Returns:
true if the specified fraction is quickly available, false otherwise

getCacheLock

public java.lang.Object getCacheLock()
Gets the synchronization lock for caching operations.

Returns:
the lock object
Since:
Marvin 5.0, 12/04/2007

getMaxDimCached

public int getMaxDimCached()
Gets the maximum molecule dimension.

Returns:
the maximum dimension

getCachedDoc

public MDocument getCachedDoc(int k,
                              java.lang.String key)
Gets the specified document if it is present in the memory.

Parameters:
k - the record index
key - the molecule (or document) field name, null for the main document (molecule)
Returns:
the document or null
Since:
Marvin 5.0, 11/18/2007

storeDoc

public void storeDoc(MDocument doc,
                     int k,
                     java.lang.String key)
Store new document and free the oldest accessed if the number of documents is too much to fit in memory.

Parameters:
doc - the new document
k - record index (minus doc source offset)
key - the molecule (or document) field name, null for the main document (molecule)

storeMainDoc

public void storeMainDoc(MDocument doc,
                         int k)
Store new document and free the oldest accessed if the number of documents is too much to fit in memory.

Parameters:
doc - the new document
k - record index (minus doc source offset)

isFixed

public boolean isFixed(int k)
Tests whether a record is fixed.

Parameters:
k - the record index
Returns:
true if the document object will remain in memory until the end of life of this storage object, false if it can be freed and reloaded dynamically to save memory
Throws:
java.lang.IndexOutOfBoundsException - if the specified index is negative.

setFixed

public void setFixed(int k)
Sets a document as fixed. Fixed documents are never freed, they remain in memory until the end of life of this storage object.

Parameters:
k - the document entry index
Throws:
java.lang.IndexOutOfBoundsException - if the specified index is negative or larger than the number of capacity

getMolPainter

public chemaxon.marvin.paint.internal.MolPainter getMolPainter(int k,
                                                               java.lang.String key)
Gets a molecule painter.

Parameters:
k - the document entry index
key - the molecule field name, null for the main document (molecule)
Returns:
the molecule painter or null

setMolPainter

public void setMolPainter(int k,
                          java.lang.String key,
                          chemaxon.marvin.paint.internal.MolPainter p)
Sets a molecule painter.

Parameters:
k - the document entry index
key - the molecule field name, null for the main document (molecule)
p - the painter

getMolCenter

public DPoint3 getMolCenter(int k,
                            java.lang.String key)
Gets a molecule center.

Parameters:
k - the document entry index
key - the molecule field name, null for the main document (molecule)
Returns:
the center

setMolCenter

public void setMolCenter(int k,
                         java.lang.String key,
                         DPoint3 p)
Sets a molecule center.

Parameters:
k - the document entry index
key - the molecule field name, null for the main document (molecule)
p - the center point

getSelectedAtoms

public int[] getSelectedAtoms(int k,
                              java.lang.String key)
Gets the selected atom indices.

Parameters:
k - the record index
key - the molecule field name, null for the main document (molecule)
Returns:
selected atom indices

setSelectedAtoms

public void setSelectedAtoms(int k,
                             java.lang.String key,
                             int[] sel)
Sets the selected atom indices.

Parameters:
k - the record index
key - the molecule field name, null for the main document (molecule)
sel - array containing the selected atom indices

setSelectedAtoms

public void setSelectedAtoms(int k,
                             java.lang.String key,
                             java.lang.String str)
Sets the selected atom indices.

Parameters:
k - the record index
key - the molecule field name, null for the main document (molecule)
str - string containing a comma separated list of atom indices

setAtomSetSeqs

public void setAtomSetSeqs(int k,
                           java.lang.String key,
                           int[] seqs)
Sets atom set sequence numbers.

Parameters:
k - the record index
key - the molecule field name, null for the main document (molecule)
seqs - array of atom set sequence numbers

setAtomSetSeq

public void setAtomSetSeq(int k,
                          java.lang.String key,
                          java.lang.String str,
                          int setSeq)
Sets atom set sequence numbers.

Parameters:
k - the record index
key - the molecule field name, null for the main document (molecule)
str - string containing a comma separated list of atom indices
setSeq - atom set sequence number

setAtomSetSeq

public void setAtomSetSeq(int k,
                          java.lang.String key,
                          int atom,
                          int seq)
Sets the atom set sequence number of an atom.

Parameters:
k - the record index
key - the molecule field name, null for the main document (molecule)
atom - atom index
seq - atom set sequence number

setBondSetSeqs

public void setBondSetSeqs(int k,
                           java.lang.String key,
                           java.util.Vector seqs)
Sets bond set sequence numbers.

Parameters:
k - the record index
key - the molecule field name, null for the main document (molecule)
seqs - vector of bond set sequence numbers

setBondSetSeq

public void setBondSetSeq(int k,
                          java.lang.String key,
                          java.lang.String str,
                          int setSeq)
Sets bond set sequence numbers.

Parameters:
k - the record index
key - the molecule field name, null for the main document (molecule)
str - string containing a comma separated list of bonds in j1-j2 format, where j1 and j2 are atom indices
setSeq - bond set sequence number

setBondSetSeq

public void setBondSetSeq(int k,
                          java.lang.String key,
                          int j1,
                          int j2,
                          int seq)
Sets bond set sequence numbers.

Parameters:
k - the record index
key - the molecule field name, null for the main document (molecule)
j1 - first atom index
j2 - second atom index
seq - bond set sequence number

setBondSetSeqAll

public void setBondSetSeqAll(int k,
                             java.lang.String key,
                             int seq)
Sets all bond set sequence numbers.

Parameters:
k - the record index
key - the molecule field name, null for the main document (molecule)
seq - bond set sequence number

doSetSetSeqs

public void doSetSetSeqs(Molecule[] mols,
                         int k,
                         java.lang.String key)

getL

public java.lang.String getL(int k,
                             int j)
Gets a text label in a record.

Parameters:
k - the record index
j - label index
Returns:
the label or null

setL

public void setL(int k,
                 int j,
                 java.lang.String l)
Sets a text label in a record.

Parameters:
k - the record index
j - label index
l - the label or null

getT

public java.lang.String getT(int k,
                             int j)
Gets a text field in a record.

Parameters:
k - the record index
j - text field index
Returns:
the text or null

setT

public void setT(int k,
                 int j,
                 java.lang.String l)
Sets a text field in a record.

Parameters:
k - the record index
j - label index
l - the text or null

isEnabledT

public boolean isEnabledT(int k,
                          int j)
Tests whether a text field is enabled.

Parameters:
k - the record index
j - text field index
Returns:
true if enabled, false otherwise

setEnabledT

public void setEnabledT(int k,
                        int j,
                        boolean l)
Set the enabled state of a text field in a record.

Parameters:
k - the record index
j - label index
l - enable (true) or disable (false)

fillWithNulls

public void fillWithNulls()
Set all stored document entries to null.


contractOrExpandSgroupsAll

public boolean contractOrExpandSgroupsAll(boolean contract)
Contract or expand S-groups in all molecules.

Parameters:
contract - contract (true or expand (false)
Returns:
true if the document is changed, false otherwise

contractOrExpandSgroups

public boolean contractOrExpandSgroups(int k,
                                       java.lang.String key,
                                       boolean contr)
Contract or expand S-groups in the specified cell.

Parameters:
k - the record index
key - the molecule field name, null for the main document (molecule)
contr - contract (true or expand (false)
Returns:
true if the document is changed, false otherwise

hydrogenizeAll

public boolean hydrogenizeAll(boolean hydr,
                              java.lang.String[] warn)
Hydrogenize molecules in all cells.

Parameters:
hydr - hydrogenize (true or dehydrogenize (false)
warn - 1-element array to store the warning message, or null
Returns:
true if the document is changed, false otherwise

hydrogenize

public boolean hydrogenize(int k,
                           java.lang.String key,
                           boolean hydr,
                           java.lang.String[] warn)
Hydrogenize molecule in the specified cell.

Parameters:
k - the record index
key - the molecule field name, null for the main document (molecule)
hydr - hydrogenize (true or dehydrogenize (false)
warn - 1-element array to store the warning message, or null
Returns:
true if the document is changed, false otherwise

aromatizeAll

public boolean aromatizeAll(boolean v,
                            int method,
                            java.lang.String[] warn)
Aromatize or dearomatize molecules in all cells.

Parameters:
v - aromatize (true or dearomatize (false)
method - aromatization method or 0
warn - 1-element array to store the warning message, or null
Returns:
true if the document is changed, false otherwise
Since:
Marvin 4.1.1, 09/08/2006

aromatize

public boolean aromatize(int k,
                         java.lang.String key,
                         boolean v,
                         int method,
                         java.lang.String[] warn)
Aromatize or dearomatize molecule in the specified cell.

Parameters:
k - the record index
key - the molecule field name, null for the main document (molecule)
v - aromatize (true or dearomatize (false)
method - aromatization method or 0
warn - 1-element array to store the warning message, or null
Returns:
true if the document is changed, false otherwise
Since:
Marvin 4.1.1, 09/08/2006

cleanAll

public boolean cleanAll(int dim,
                        java.lang.String opts,
                        MProgressMonitor pm,
                        java.lang.String[] warn)
Clean all cells.

Parameters:
dim - dimension, 2 or 3
opts - cleaning options or null
pm - progress monitor to use or null
warn - 1-element array to store the warning message, or null
Returns:
true if the document is changed, false otherwise
Since:
Marvin 5.0, 09/09/2007

clean

public boolean clean(int k,
                     java.lang.String key,
                     int dim,
                     java.lang.String opts,
                     MProgressMonitor pm,
                     java.lang.String[] warn)
Clean the specified cell.

Parameters:
k - the record index
key - the molecule field name, null for the main document (molecule)
dim - dimension, 2 or 3
opts - cleaning options or null
pm - progress monitor to use or null
warn - 1-element array to store the warning message, or null
Returns:
true if the document is changed, false otherwise
Since:
Marvin 5.0, 09/09/2007

getGlobalGUIProperties

public MPropertyContainer getGlobalGUIProperties()
Gets the Global GUI properties.

Returns:
the properties
Since:
Marvin 5.0, 10/16/2006