edu.indiana.iucbrf.casebase
Class FileCaseBase

java.lang.Object
  extended by edu.indiana.iucbrf.casebase.AbstractCaseBase
      extended by edu.indiana.iucbrf.casebase.AbstractKeyableCaseBase
          extended by edu.indiana.iucbrf.casebase.FileCaseBase
All Implemented Interfaces:
CaseBase, KeyableCaseBase, SwingRepresentableWithDomain, SwingRepresentable, java.io.Serializable

public class FileCaseBase
extends AbstractKeyableCaseBase

A FileCaseBase stores cases in a B-tree-backed file. The indices of the cases are stored in memory for fast similarity comparisons, and the full cases are stored in a iglu.util.FileBTree. To fully write the case base to a file (so the system may be shut down), serialize the FileCaseBase object. When the system is started up again, deserialize it. Note that edu.indiana.util.ObjectFileIO can be of great help in object serialization.

See Also:
Serialized Form

Field Summary
protected  java.lang.String baseFilename
           
protected  iglu.util.FileBTree fullCB
           
protected  CaseBase indexCB
           
protected static int LONG_KEY_SIZE
           
protected  int t
           
 
Fields inherited from class edu.indiana.iucbrf.casebase.AbstractKeyableCaseBase
markerList
 
Fields inherited from class edu.indiana.iucbrf.casebase.AbstractCaseBase
caseClass, debugMode, DEFAULT_INITIAL_CAPACITY, domain, listeners, prototype
 
Fields inherited from interface edu.indiana.util.swing.SwingRepresentable
TITLE_FONT
 
Constructor Summary
protected FileCaseBase()
           
  FileCaseBase(CaseBase indexCB, java.lang.String baseFilename, Domain domain)
          Creates a new instance of FileCaseBase
  FileCaseBase(CaseBase indexCB, java.lang.String baseFilename, Domain domain, java.lang.Class case_class)
           
  FileCaseBase(CaseBase indexCB, java.lang.String baseFilename, Domain domain, int t)
           
  FileCaseBase(CaseBase indexCB, java.lang.String baseFilename, Domain domain, int t, java.lang.Class case_class)
           
  FileCaseBase(java.lang.String baseFilename, Domain domain, java.lang.Class case_class)
           
 
Method Summary
 void addCaseWithKey(Case caseToAdd)
          Implement this method to add a case to the case base, assuming that class and event issues are already handled by addCase().
 void close()
          Perform any maintenance needed during finalization of this CaseBase, such closing of open files.
 void ensureCapacity(int minCapacity)
          Prepare the case base to be able to hold at least minCapacity cases.
 Case getCase(long key)
          Get the case at a given key.
 int getCaseCount()
          Get the size of the case base.
protected  void initializeCB(int initialCapacity)
           
 java.util.Iterator iterator()
          Create an iterator on the case base.
 boolean removeCase(long key)
          Remove the case with the given key.
protected  boolean removeCaseImpl(Case toRemove)
          Implement this method to remove a case from the case base, assuming that class and event issues are already handled by removeCase().
 void setBaseFileName(java.lang.String baseFilename)
          Set the base filename that will be used for saving this case base.
 java.lang.String toVerboseString()
          Can be overridden to provide more details than toString().
 
Methods inherited from class edu.indiana.iucbrf.casebase.AbstractKeyableCaseBase
addCaseImpl, getMarkerKeys, getNextCaseKey
 
Methods inherited from class edu.indiana.iucbrf.casebase.AbstractCaseBase
addCase, addCaseBaseListener, addCases, addCases, addCases, buildCaseJList, checkCaseType, classMemberIterator, clearAllEstimates, fireCaseAdded, fireCaseClassChanged, fireCaseRemoved, fireCaseReplaced, fireCasesCleared, getCaseClass, getCasesMatching, getDomain, getPrototype, isEmpty, removeCase, removeCaseBaseListener, setCaseClass, setDebugMode, setDomain, toString, toSwing, toSwing
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface edu.indiana.iucbrf.casebase.CaseBase
addCase, addCaseBaseListener, addCases, addCases, addCases, clearAllEstimates, getCaseClass, getCasesMatching, getDomain, isEmpty, removeCase, removeCaseBaseListener, setCaseClass, setDomain, toString
 
Methods inherited from interface edu.indiana.iucbrf.util.SwingRepresentableWithDomain
toSwing
 
Methods inherited from interface edu.indiana.util.swing.SwingRepresentable
toSwing
 

Field Detail

LONG_KEY_SIZE

protected static final int LONG_KEY_SIZE

t

protected int t

indexCB

protected CaseBase indexCB

fullCB

protected iglu.util.FileBTree fullCB

baseFilename

protected java.lang.String baseFilename
Constructor Detail

FileCaseBase

protected FileCaseBase()

FileCaseBase

public FileCaseBase(java.lang.String baseFilename,
                    Domain domain,
                    java.lang.Class case_class)

FileCaseBase

public FileCaseBase(CaseBase indexCB,
                    java.lang.String baseFilename,
                    Domain domain)
Creates a new instance of FileCaseBase


FileCaseBase

public FileCaseBase(CaseBase indexCB,
                    java.lang.String baseFilename,
                    Domain domain,
                    java.lang.Class case_class)

FileCaseBase

public FileCaseBase(CaseBase indexCB,
                    java.lang.String baseFilename,
                    Domain domain,
                    int t)

FileCaseBase

public FileCaseBase(CaseBase indexCB,
                    java.lang.String baseFilename,
                    Domain domain,
                    int t,
                    java.lang.Class case_class)
Method Detail

initializeCB

protected void initializeCB(int initialCapacity)
Specified by:
initializeCB in class AbstractCaseBase

iterator

public java.util.Iterator iterator()
Create an iterator on the case base.

Specified by:
iterator in interface CaseBase
Specified by:
iterator in class AbstractCaseBase

addCaseWithKey

public void addCaseWithKey(Case caseToAdd)
Implement this method to add a case to the case base, assuming that class and event issues are already handled by addCase().


getCase

public Case getCase(long key)
Get the case at a given key.

Parameters:
key - The key of the case to be retrieved.
Returns:
The retrieved case, or null if no such case is found.

removeCase

public boolean removeCase(long key)
Description copied from interface: KeyableCaseBase
Remove the case with the given key.

Parameters:
key - The key of the case to be removed.
Returns:
true if case was found and removed, false otherwise.

removeCaseImpl

protected boolean removeCaseImpl(Case toRemove)
Implement this method to remove a case from the case base, assuming that class and event issues are already handled by removeCase().

Overrides:
removeCaseImpl in class AbstractKeyableCaseBase
Parameters:
c - The case to be removed.

setBaseFileName

public void setBaseFileName(java.lang.String baseFilename)
Set the base filename that will be used for saving this case base. The case base will be saved partly in baseFilename+".cb" (the index) and partly in baseFilename+".bt" (the full cases).

Specified by:
setBaseFileName in interface CaseBase
Overrides:
setBaseFileName in class AbstractCaseBase

toVerboseString

public java.lang.String toVerboseString()
Description copied from class: AbstractCaseBase
Can be overridden to provide more details than toString().

Specified by:
toVerboseString in interface CaseBase
Overrides:
toVerboseString in class AbstractCaseBase

ensureCapacity

public void ensureCapacity(int minCapacity)
Prepare the case base to be able to hold at least minCapacity cases. Some CaseBase subclasses may not need to do anything in their implementations of this method. Used for efficiency reasons, analogous to java.util.ArrayList.ensureCapacity().

Specified by:
ensureCapacity in interface CaseBase
Specified by:
ensureCapacity in class AbstractCaseBase

getCaseCount

public int getCaseCount()
Get the size of the case base.

Returns:
The number of cases in the case base.

close

public void close()
Perform any maintenance needed during finalization of this CaseBase, such closing of open files.

Specified by:
close in interface CaseBase
Overrides:
close in class AbstractCaseBase