Interface Dictionary

All Known Implementing Classes:
FlatFileDictionary

interface Dictionary

This is the interface which every possible dictionary should implement to work with cornucopia. This implementation is based on the strategy design pattern. By using this pattern we are able to contain the possiblily changing component in one class preventing any ripple effect in rest of the application.

Follwoing is the sequence in which a dictionary's methods will be called.

  1. findWord will always be the first function to be called. Cornucopia will first determine weather the quried word is present in dictionaries database using the return value of this function.
  2. Next cornucopia calls "read" and "getMeaning" in strict alteration to get meaning(s) to the word. This continues till "read" returns a flase indicating that no more meaning(s) are there to display.

The above said protocol does not depend at which stage is actually the meaning is fetched from the database. It can either be in read or getMeaning method, All that is required is that they must returns correct values.


Method Summary
 boolean findWord(java.lang.String word)
          This function performs the initialisation required for the "read" and "getMeaning" functions to work properly.
 java.lang.String getDescription()
          The description returned by this function is used by cornucopia at the time of startup to display which dictionary is currently loaded.
 java.lang.String getMeaning()
          This method gives the next meaning string, as signaled by "read" method.
 boolean read()
          This function signals weather another meaning corresponding to the word set by "findWord" function.
 

Method Detail

findWord

boolean findWord(java.lang.String word)
This function performs the initialisation required for the "read" and "getMeaning" functions to work properly. Hence, this must be the first call in the sequence of finding meaning(s) to a word.

Returns:
  • A return value of true indicates that this word is present in the database and its meaning can be retrieved by subsequent calls to read function.
  • A value of false indicated that quried word is not present in database. Cornucopia displays "No match found." on this and suspends any further action.

  • read

    boolean read()
    This function signals weather another meaning corresponding to the word set by "findWord" function. The next meaning can be retrieved by calling the "getMeaning" function.

    Returns:
    It returns a boolean value indicating weather any more meaning(s) are available to be displayed next.

    getMeaning

    java.lang.String getMeaning()
    This method gives the next meaning string, as signaled by "read" method. If called in a proper sequence and at proper time this should never return null.

    Returns:
    String containing the current meaning.

    getDescription

    java.lang.String getDescription()
    The description returned by this function is used by cornucopia at the time of startup to display which dictionary is currently loaded.

    Returns:
    String describing the current dictionary implementation.