org.egothor.core.memory
Class MemoryBarrel

java.lang.Object
  extended by org.egothor.core.memory.MemoryBarrel
All Implemented Interfaces:
Barrel, BarrelReader, BarrelWriter

public class MemoryBarrel
extends java.lang.Object
implements Barrel, BarrelReader, BarrelWriter

This is a basic implementation of all three types of Barrels in memory. DO NOT USE this implementation for more than few dozens of documents; it is quite memory intensive. This class is not synchronized.

Document's metadata are stored in a Vector. Inverted list's metadata are stored in a TreeMap.

Author:
Leo Galambos

Constructor Summary
MemoryBarrel()
          Constructor for the MemBarrel object.
MemoryBarrel(BarrelReader old)
          Use the given Barrel to construct a new one.
 
Method Summary
 void append(BarrelReader old)
          Append the given Barrel to this one.
protected  void appendIList(IListReader il, long remap)
          Append a new inverted list.
 void clear()
          Description of the Method
 void close()
          Not implemented but required by Barrel.
 void commit()
          Not implemented but required by Barrel.
 long deleted()
          Return the number of deleted documents.
 void destroy()
          Destroy this Barrel.
 Sequence<? extends IListMetadata> expand(java.lang.String expr)
          Return an Enumeration which will contain inverted list metadata for any inverted list constructed for a term containing the given regular expression.
 Bitmap getBitmap(java.lang.String label)
          Return the Bitmap of a given label.
 SequenceWithClose<DocumentData> getDocuments()
          Return the documents making up this Barrel.
 IListMetadata getIListMeta(java.lang.String term)
          Return the metadata of the inverted list constructed for the given term.
 SequenceWithClose<IListReader> getILists()
          Return the inverted lists in this Barrel.
 DocumentData getMeta(long uid)
          Return the metadata of the document with the given unique ID.
 long length()
          Return the number of active (not deleted) documents.
 BarrelReader open()
          Return this object.
 IListReader openIList(java.lang.String term, boolean clean)
          Return an IListReader that can read the inverted list constructed for the given term.
 void query(Query q, ResultList result)
          Not implemented.
 boolean removeDoc(long id)
          Remove the document with the given unique ID.
 void rewind()
          Restart this BarrelReader so that the documents can be read again.
 void setBitmap(java.lang.String label, Bitmap bitmap)
          Try to set the Bitmap of a given label.
 long size()
          Return the size of this Barrel.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MemoryBarrel

public MemoryBarrel()
Constructor for the MemBarrel object. Calling this constructor merely creates an instance of the superclass.


MemoryBarrel

public MemoryBarrel(BarrelReader old)
Use the given Barrel to construct a new one.

Parameters:
old - the Barrel to copy
Method Detail

getBitmap

public Bitmap getBitmap(java.lang.String label)
Description copied from interface: Barrel
Return the Bitmap of a given label.

Specified by:
getBitmap in interface Barrel
Parameters:
label - the label of the requested Bitmap
Returns:
Bitmap of removed documents when label is null

getDocuments

public SequenceWithClose<DocumentData> getDocuments()
Return the documents making up this Barrel.

Specified by:
getDocuments in interface BarrelReader
Returns:
the documents

getIListMeta

public IListMetadata getIListMeta(java.lang.String term)
Return the metadata of the inverted list constructed for the given term.

Specified by:
getIListMeta in interface Barrel
Parameters:
term - the term for which the desired inverted list was constructed
Returns:
an IListMetadata

getILists

public SequenceWithClose<IListReader> getILists()
Return the inverted lists in this Barrel.

Specified by:
getILists in interface BarrelReader
Returns:
an Enumeration of ILists

getMeta

public DocumentData getMeta(long uid)
Return the metadata of the document with the given unique ID.

Specified by:
getMeta in interface Barrel
Parameters:
uid - the ID of the desired document
Returns:
a DocMetadDocumentData

expand

public Sequence<? extends IListMetadata> expand(java.lang.String expr)
Return an Enumeration which will contain inverted list metadata for any inverted list constructed for a term containing the given regular expression.

Specified by:
expand in interface Barrel
Parameters:
expr - the regular expression to be contained in the term(s)
Returns:
an Enumeration of inverted lists, or null if there are no matches

open

public BarrelReader open()
Return this object. Since this class implements BarrelReader this method can return a BarrelReader.

Specified by:
open in interface Barrel
Returns:
this

destroy

public void destroy()
Destroy this Barrel.

Specified by:
destroy in interface Barrel

clear

public void clear()
Description of the Method


removeDoc

public boolean removeDoc(long id)
Remove the document with the given unique ID.

Specified by:
removeDoc in interface Barrel
Parameters:
id - the document to remove
Returns:
true if successful, or already removed, false otherwise

length

public long length()
Return the number of active (not deleted) documents.

Specified by:
length in interface BarrelReader
Returns:
the number of active documents

size

public long size()
Return the size of this Barrel.

Specified by:
size in interface Barrel
Returns:
the size

deleted

public long deleted()
Return the number of deleted documents.

Specified by:
deleted in interface Barrel
Returns:
the number of deleted documents

close

public void close()
Not implemented but required by Barrel.

Specified by:
close in interface Barrel
Specified by:
close in interface BarrelReader
Specified by:
close in interface BarrelWriter

rewind

public void rewind()
Restart this BarrelReader so that the documents can be read again. The operation does not need any action in this implementation.

Specified by:
rewind in interface BarrelReader

commit

public void commit()
Not implemented but required by Barrel.

Specified by:
commit in interface Barrel

openIList

public IListReader openIList(java.lang.String term,
                             boolean clean)
Return an IListReader that can read the inverted list constructed for the given term.

Specified by:
openIList in interface Barrel
Parameters:
term - the term for which the desired inverted list was constructed
clean - whether to remove all the items denoted as deleted
Returns:
a reader capable of reading an inverted list

append

public void append(BarrelReader old)
Append the given Barrel to this one.

Note: Calls to this method must be synchronized.

Specified by:
append in interface BarrelWriter
Parameters:
old - the Barrel to append

appendIList

protected void appendIList(IListReader il,
                           long remap)
                    throws java.io.IOException
Append a new inverted list. The document identifications are increased by the remap value.

Parameters:
il - the inverted list to append
remap - the factor by which document IDs should be increased
Throws:
java.io.IOException

query

public void query(Query q,
                  ResultList result)
Not implemented.

Specified by:
query in interface Barrel
Parameters:
q - the query
result - the list of results

setBitmap

public void setBitmap(java.lang.String label,
                      Bitmap bitmap)
Description copied from interface: Barrel
Try to set the Bitmap of a given label.

Specified by:
setBitmap in interface Barrel
Parameters:
label - the label of the requested Bitmap
bitmap - Bitmap of removed documents when label is null