org.micropsi.comp.console
Class QuestionCache

java.lang.Object
  extended byorg.micropsi.comp.console.QuestionCache

public class QuestionCache
extends java.lang.Object

A class for caching @see CachedQuestion.


Field Summary
static int INITIAL_SIZE
           
static int MAX_SIZE
          The maximal size of the cache.
 
Constructor Summary
protected QuestionCache()
           
 
Method Summary
 void addQuestion(CachedQuestion q, CachedAnswer a)
          Method addQuestion.
 AnswerIF findAnswer(CachedQuestion q)
          Method findAnswer.
static QuestionCache getInstance()
          Method getInstance.
 int getSize()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

MAX_SIZE

public static int MAX_SIZE
The maximal size of the cache.


INITIAL_SIZE

public static int INITIAL_SIZE
Constructor Detail

QuestionCache

protected QuestionCache()
Method Detail

getInstance

public static QuestionCache getInstance()
Method getInstance. Creates the QuestionCache if it is inexistant. Returns it.

Returns:
QuestionCache - The instance.

getSize

public int getSize()

findAnswer

public AnswerIF findAnswer(CachedQuestion q)
Method findAnswer. Returns a previously cached answer.

Parameters:
q - - The question to be answered.
Returns:
AnswerIF - The answer, if it is cached, null otherwise.

addQuestion

public void addQuestion(CachedQuestion q,
                        CachedAnswer a)
Method addQuestion. Adds a question (and its answer) to the cache. If the size of the cache is larger than @see #MAX_SIZE, the eldest question is deleted. If an answer to the same question exists, it is (hopefully) deleted, so we always keep the newest information.

Parameters:
q - - The Question.
a - - Its answer.

(c) by Micropsi Project: http://www.cognitive-agents.org

.