Linkable.Utility
Class CreationDatabase

java.lang.Object
  |
  +--Linkable.Utility.CreationDatabase

public class CreationDatabase
extends java.lang.Object


Field Summary
private static java.util.Hashtable creations
           
private static boolean DEBUG
           
private static java.util.Hashtable fileIndex
           
private static boolean isLoaded
           
private static java.lang.String ME
           
 
Constructor Summary
CreationDatabase()
           
 
Method Summary
static void dump()
          dump - Print out current contents of the Creation database
static void dump(java.lang.String fname)
          dump - Write current contents of the Creation database to file Unlike fileIndex, this will save the data even if the Surrogates don't get saved.
private static java.lang.String dumpAuthors(Author[] authors)
           
private static boolean existsSurrogate(java.lang.String doi)
           
static Creation fetchCreation(java.lang.String urn)
          looks up the Creation for the specified index and returns it
static java.lang.String getDOI(java.lang.String docURN)
          getDOI
private static boolean mergable(java.lang.String urnIncomplete, java.lang.String urnComplete, int authorLength)
           
static java.lang.String mergeCreation(java.lang.String urn, int authorLength)
          mergeCreation - check if the urn can be merged with any others in current CreationDatabase
static void reload()
          reload - initialize the hash table from storage (partially)
static void save()
          save - write the fileIndex hashtable to file As a side effect, this routine will make sure there actually is a Surrogate in storage before storing a record that involves it.
static void save(java.lang.String urn, java.lang.String doi)
          save - add a new element to the fileIndex hashtable, if it isn't there already.
static void stashCreation(Creation c)
          Adds specified creation to the hashtable.
static void update(java.lang.String _newUrn, java.lang.String _oldUrn)
          update - update the creationDatabase after merge urn happens including both creations and fileIndex hashtables
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, toString, wait, wait, wait
 

Field Detail

ME

private static final java.lang.String ME

DEBUG

private static final boolean DEBUG

isLoaded

private static boolean isLoaded

creations

private static java.util.Hashtable creations

fileIndex

private static java.util.Hashtable fileIndex
Constructor Detail

CreationDatabase

public CreationDatabase()
Method Detail

fetchCreation

public static Creation fetchCreation(java.lang.String urn)
looks up the Creation for the specified index and returns it
Parameters:
- - the index

stashCreation

public static void stashCreation(Creation c)
Adds specified creation to the hashtable. As a side-effect, if there is a hash conflict, but the values are consistent with each other, then fields get completed and the merged Creation stays at that key. If inconsistent, and the URN is a DOI, we have a bad problem. If inconsistent, but the URN is synthetic, then add title words until the URNs become distinct. It is the URN for the object being added that gets changed; it is important for the old key to stay as is, because it is likely contained in many other objects.
Parameters:
The - Creation object to be added to the table

dump

public static void dump()
dump - Print out current contents of the Creation database

dump

public static void dump(java.lang.String fname)
dump - Write current contents of the Creation database to file Unlike fileIndex, this will save the data even if the Surrogates don't get saved. On the other hand it will have to be de-parsed in order to re-construct the creations hashtable

save

public static void save(java.lang.String urn,
                        java.lang.String doi)
save - add a new element to the fileIndex hashtable, if it isn't there already. Called when a Surrogate is being saved to storage.
Parameters:
- - the URN of the creation being saved
- - the DOI of the Surrogate of which this Creation is part Note that we save only the last-encountered creation instance. Hopefully it is the most correct one. Assert that this routine is called only if a Surrogate really IS written to storage.

save

public static void save()
save - write the fileIndex hashtable to file As a side effect, this routine will make sure there actually is a Surrogate in storage before storing a record that involves it. For failsafe capture of data, use the dump() routine. This routine should be called by applications at the end of the whole run.

reload

public static void reload()
reload - initialize the hash table from storage (partially)
Parameters:
- - String which is the filename in storage of where the creation database has been stored format for the record in file is (urn, Surrogate DOI, ordinal) The ordinal is 0 for the Surrogate itself, 1... for a reference in that Surrogate. Load into fileIndex hashtable. Thus in principle information does not need to be stored in both places: the Surrogate object and the database.

mergeCreation

public static java.lang.String mergeCreation(java.lang.String urn,
                                             int authorLength)
mergeCreation - check if the urn can be merged with any others in current CreationDatabase
Parameters:
- - urn: the urn need to be merged authorLength: in order to find out the substring of urn in the case of missing author, missing date and missing title
Returns:
- the complete urn if merge happens, null if merge does not happen

update

public static void update(java.lang.String _newUrn,
                          java.lang.String _oldUrn)
update - update the creationDatabase after merge urn happens including both creations and fileIndex hashtables
Parameters:
- - _newUrn: the urn after merge _oldUrn: the old urn that's still in CreationDatabase

dumpAuthors

private static java.lang.String dumpAuthors(Author[] authors)

existsSurrogate

private static boolean existsSurrogate(java.lang.String doi)

getDOI

public static java.lang.String getDOI(java.lang.String docURN)
getDOI
Parameters:
docURN - - the URN of the creation
Returns:
DOI - the doi of the file

mergable

private static boolean mergable(java.lang.String urnIncomplete,
                                java.lang.String urnComplete,
                                int authorLength)