edu.indiana.iucbrf.casebase
Class AbstractCaseBase

java.lang.Object
  extended by edu.indiana.iucbrf.casebase.AbstractCaseBase
All Implemented Interfaces:
CaseBase, SwingRepresentableWithDomain, SwingRepresentable, java.io.Serializable
Direct Known Subclasses:
AbstractKeyableCaseBase, PartitionedCaseBase

public abstract class AbstractCaseBase
extends java.lang.Object
implements CaseBase, java.io.Serializable

This abstract base component class contains the outline for the implementation of a case base, as well as implementations of some common functions.

See Also:
Serialized Form

Field Summary
protected  java.lang.Class caseClass
           
protected  boolean debugMode
           
static int DEFAULT_INITIAL_CAPACITY
           
protected  Domain domain
           
protected  java.util.ArrayList listeners
          interested third parties
protected  Case prototype
           
 
Fields inherited from interface edu.indiana.util.swing.SwingRepresentable
TITLE_FONT
 
Constructor Summary
AbstractCaseBase()
          Creates new CaseBase
AbstractCaseBase(CaseGenerator caseGenerator, int numToGenerate)
          Construct a case base generated randomly according to a CaseGenerator.
AbstractCaseBase(java.lang.Class caseClass, int initialCapacity)
           
 
Method Summary
 long addCase(Case acase)
          Add a case to the case base.
 void addCaseBaseListener(CaseBaseListener cll)
          Add a CaseBaseListener to listen for CaseBaseEvents.
protected abstract  long addCaseImpl(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 addCases(CaseBase cases)
          Add a case base containing cases to this case base, using addCase().
 void addCases(CaseGenerator caseGenerator, int numToAdd)
          Generate numToAdd cases with the given caseGenerator.
 void addCases(java.util.Collection cases)
          Add a Collection of cases to the case base, using addCase().
protected  CaseJList buildCaseJList()
           
protected  void checkCaseType(Case c)
          Makes sure that a case is of an appropriate class for this case base.
 java.util.Iterator classMemberIterator()
           
 void clearAllEstimates()
          Remove all estimated features from the cases in the case base.
 void close()
          Perform any maintenance needed during finalization of this CaseBase, such closing of open files.
abstract  void ensureCapacity(int minCapacity)
          Prepare the case base to be able to hold at least minCapacity cases.
protected  void fireCaseAdded(Case addedCase)
          Notify all CaseBaseListeners added to this CaseBase that a case has been added to this case base.
protected  void fireCaseClassChanged()
          Notify all CaseBaseListeners added to this CaseBase that the case class associated with the case base had been changed.
protected  void fireCaseRemoved(Case removedCase)
          Notify all CaseBaseListeners added to this CaseBase that a case has been removed.
protected  void fireCaseReplaced(Case oldCase, Case newCase)
          Notify all CaseBaseListeners added to this CaseBase that a case has been replaced.
protected  void fireCasesCleared()
          Notify all CaseBaseListeners added to this CaseBase that all cases have been cleared from the CaseBase.
 java.lang.Class getCaseClass()
          Get the class of cases used in this case base.
 FlatCaseBase getCasesMatching(java.lang.Class case_class)
          Get the cases in this case base that are of a given class.
 Domain getDomain()
           
 java.lang.Object getPrototype()
           
protected abstract  void initializeCB(int initialCapacity)
           
 boolean isEmpty()
          Returns true if this case base is empty, false otherwise.
abstract  java.util.Iterator iterator()
          Create an iterator on the case base.
 boolean removeCase(Case c)
          Remove a single case from the case base.
 void removeCaseBaseListener(CaseBaseListener cll)
          Remove a previously added CaseBaseListener.
protected abstract  boolean removeCaseImpl(Case c)
           
 void setBaseFileName(java.lang.String baseFilename)
          Set the base filename that will be used for saving this case base.
 void setCaseClass(java.lang.Class case_class)
          Set the class of cases used in this case base.
 void setDebugMode(boolean debugMode)
           
 void setDomain(Domain domain)
          Set the transient domain attribute for this case base.
 java.lang.String toString()
          Convert this case base to a string representation.
 javax.swing.JComponent toSwing(Domain domain)
           
 javax.swing.JComponent toSwing(int detailLevel)
          Detail level may be ignored by implementations.
 java.lang.String toVerboseString()
          Can be overridden to provide more details than toString().
 
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
getCaseCount
 

Field Detail

DEFAULT_INITIAL_CAPACITY

public static final int DEFAULT_INITIAL_CAPACITY
See Also:
Constant Field Values

caseClass

protected java.lang.Class caseClass

listeners

protected java.util.ArrayList listeners
interested third parties


debugMode

protected boolean debugMode

domain

protected transient Domain domain

prototype

protected Case prototype
Constructor Detail

AbstractCaseBase

public AbstractCaseBase()
Creates new CaseBase


AbstractCaseBase

public AbstractCaseBase(java.lang.Class caseClass,
                        int initialCapacity)

AbstractCaseBase

public AbstractCaseBase(CaseGenerator caseGenerator,
                        int numToGenerate)
Construct a case base generated randomly according to a CaseGenerator.

Method Detail

initializeCB

protected abstract void initializeCB(int initialCapacity)

ensureCapacity

public abstract 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

iterator

public abstract java.util.Iterator iterator()
Create an iterator on the case base. This method simply throws an UnsupportedOperationException, and must be overridden if needed in case base implementations.

Specified by:
iterator in interface CaseBase

toString

public java.lang.String toString()
Convert this case base to a string representation. Warning: naturally, the String representation will be quite large if there are many cases and/or the cases themselves have a large String representation.

Specified by:
toString in interface CaseBase
Overrides:
toString in class java.lang.Object

toVerboseString

public java.lang.String toVerboseString()
                                 throws java.lang.UnsupportedOperationException
Can be overridden to provide more details than toString().

Specified by:
toVerboseString in interface CaseBase
Throws:
java.lang.UnsupportedOperationException

addCases

public void addCases(java.util.Collection cases)
Add a Collection of cases to the case base, using addCase().

Specified by:
addCases in interface CaseBase
Parameters:
cases - The Collection of cases to add.

addCases

public void addCases(CaseBase cases)
Add a case base containing cases to this case base, using addCase().

Specified by:
addCases in interface CaseBase
Parameters:
cases - The CaseBase of cases to add.

addCases

public void addCases(CaseGenerator caseGenerator,
                     int numToAdd)
Description copied from interface: CaseBase
Generate numToAdd cases with the given caseGenerator.

Specified by:
addCases in interface CaseBase

getCaseClass

public java.lang.Class getCaseClass()
Get the class of cases used in this case base.

Specified by:
getCaseClass in interface CaseBase

getCasesMatching

public FlatCaseBase getCasesMatching(java.lang.Class case_class)
Get the cases in this case base that are of a given class.

Specified by:
getCasesMatching in interface CaseBase
Returns:
A FlatCaseBase containing the desired cases.

setCaseClass

public void setCaseClass(java.lang.Class case_class)
Set the class of cases used in this case base.

Specified by:
setCaseClass in interface CaseBase

checkCaseType

protected void checkCaseType(Case c)
Makes sure that a case is of an appropriate class for this case base. Throws an IllegalArgumentException if the case is of an unappropriate class.

Parameters:
c - The case in question.

close

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

Specified by:
close in interface CaseBase

addCase

public long addCase(Case acase)
Add a case to the case base. Note that addCaseImpl() must be defined for the case base subclass in use.

Specified by:
addCase in interface CaseBase
Parameters:
acase - The case to add.
Returns:
-1 (a meaningless value), unless the non-abstract class in use extends KeyableCaseBase.

addCaseImpl

protected abstract long addCaseImpl(Case caseToAdd)
Implement this method to add a case to the case base, assuming that class and event issues are already handled by addCase().

Returns:
-1 (a meaningless value), unless the non-abstract class in use extends KeyableCaseBase.

removeCaseImpl

protected abstract boolean removeCaseImpl(Case c)

removeCase

public boolean removeCase(Case c)
Remove a single case from the case base.

Specified by:
removeCase in interface CaseBase
Parameters:
acase - The case to remove.
Returns:
True if the case was found and removed, false otherwise.

toSwing

public javax.swing.JComponent toSwing(int detailLevel)
Description copied from interface: SwingRepresentable
Detail level may be ignored by implementations. If used, the standard is for detailLevel 0 to be least detail, with higher values growing more detailed. 0 is least detail, higher numbers are more

Specified by:
toSwing in interface SwingRepresentable

toSwing

public javax.swing.JComponent toSwing(Domain domain)
Specified by:
toSwing in interface SwingRepresentableWithDomain

buildCaseJList

protected CaseJList buildCaseJList()

isEmpty

public boolean isEmpty()
Description copied from interface: CaseBase
Returns true if this case base is empty, false otherwise.

Specified by:
isEmpty in interface CaseBase

addCaseBaseListener

public void addCaseBaseListener(CaseBaseListener cll)
Add a CaseBaseListener to listen for CaseBaseEvents.

Specified by:
addCaseBaseListener in interface CaseBase

removeCaseBaseListener

public void removeCaseBaseListener(CaseBaseListener cll)
Remove a previously added CaseBaseListener.

Specified by:
removeCaseBaseListener in interface CaseBase

fireCaseReplaced

protected void fireCaseReplaced(Case oldCase,
                                Case newCase)
Notify all CaseBaseListeners added to this CaseBase that a case has been replaced.

Parameters:
index - The index of the case that was replaced.

fireCaseClassChanged

protected void fireCaseClassChanged()
Notify all CaseBaseListeners added to this CaseBase that the case class associated with the case base had been changed.


fireCasesCleared

protected void fireCasesCleared()
Notify all CaseBaseListeners added to this CaseBase that all cases have been cleared from the CaseBase.


fireCaseRemoved

protected void fireCaseRemoved(Case removedCase)
Notify all CaseBaseListeners added to this CaseBase that a case has been removed.

Parameters:
index - The index of the case that was removed.

fireCaseAdded

protected void fireCaseAdded(Case addedCase)
Notify all CaseBaseListeners added to this CaseBase that a case has been added to this case base.

Parameters:
index - The index of the case that was added.

setBaseFileName

public void setBaseFileName(java.lang.String baseFilename)
Set the base filename that will be used for saving this case base. This implementation does nothing, since most case base implementations are not spread across multiple files.

Specified by:
setBaseFileName in interface CaseBase

setDebugMode

public void setDebugMode(boolean debugMode)

setDomain

public void setDomain(Domain domain)
Description copied from interface: CaseBase
Set the transient domain attribute for this case base. This is called upon deserialization of a CBRSystem.

Specified by:
setDomain in interface CaseBase

getDomain

public Domain getDomain()
Specified by:
getDomain in interface CaseBase

clearAllEstimates

public void clearAllEstimates()
Remove all estimated features from the cases in the case base.

Specified by:
clearAllEstimates in interface CaseBase

getPrototype

public java.lang.Object getPrototype()

classMemberIterator

public java.util.Iterator classMemberIterator()