com.aliasi.dict
Class AbstractDictionary<C>

java.lang.Object
  extended by java.util.AbstractCollection<E>
      extended by java.util.AbstractSet<DictionaryEntry<C>>
          extended by com.aliasi.dict.AbstractDictionary<C>
Type Parameters:
C - the type of entries in the dictionary
All Implemented Interfaces:
Dictionary<C>, Compilable, Iterable<DictionaryEntry<C>>, Collection<DictionaryEntry<C>>, Set<DictionaryEntry<C>>
Direct Known Subclasses:
MapDictionary, TrieDictionary

public abstract class AbstractDictionary<C>
extends AbstractSet<DictionaryEntry<C>>
implements Dictionary<C>, Compilable

An AbstractDictionary is a dictionary with convenience implementations of most methods. Like the AbstractSet class it extends, the AbstractCollection.iterator() method must be defined by concrete implementations to return an iterator over dictionary entries. Unlike AbstractSet, even the size() method is implemented in terms of the iterator.

The implementation of the mutable methods in this class all throw unsupported operation exceptions. This includes the method addEntry(DictionaryEntry entry) in the dictionary interface, and the methods AbstractCollection.remove(Object) and AbstractCollection.add(Object) and their relatives in the set interface. Subclasses may override any or all of these methods.

Since:
LingPipe2.1
Version:
3.8
Author:
Bob Carpenter

Constructor Summary
protected AbstractDictionary()
          Construct an abstract dictionary.
 
Method Summary
 void addEntry(DictionaryEntry<C> entry)
          Adds the specified dictionary entry to the dictionary.
 DictionaryEntry<C>[] categoryEntries(C category)
          Deprecated. Use categoryEntryList(Object) instead.
 Iterator<DictionaryEntry<C>> categoryEntryIt(C category)
          Returns an iterator over the dictionary entries with the specified category.
 List<DictionaryEntry<C>> categoryEntryList(C category)
          Returns the dictionary entries with the specified category.
 void compileTo(ObjectOutput out)
          Compiles this dictionary to the specified object output.
 DictionaryEntry<C>[] entries()
          Deprecated. Use entryList() instead.
 List<DictionaryEntry<C>> entryList()
          Returns all of the dictionary entries for this dictionary.
 DictionaryEntry<C>[] phraseEntries(String phrase)
          Deprecated. Use phraseEntryList(String) instead.
 Iterator<DictionaryEntry<C>> phraseEntryIt(String phrase)
          Returns an iterator over the dictionary entries with the specified phrase.
 List<DictionaryEntry<C>> phraseEntryList(String phrase)
          Returns the dictionary entries with the specified phrase.
 int size()
          Returns the size of this dictionary as measured by number of dictionary entries.
 
Methods inherited from class java.util.AbstractSet
equals, hashCode, removeAll
 
Methods inherited from class java.util.AbstractCollection
add, addAll, clear, contains, containsAll, isEmpty, iterator, remove, retainAll, toArray, toArray, toString
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.util.Set
add, addAll, clear, contains, containsAll, equals, hashCode, isEmpty, iterator, remove, removeAll, retainAll, toArray, toArray
 

Constructor Detail

AbstractDictionary

protected AbstractDictionary()
Construct an abstract dictionary.

Method Detail

phraseEntryIt

public Iterator<DictionaryEntry<C>> phraseEntryIt(String phrase)
Returns an iterator over the dictionary entries with the specified phrase.

Implementation Note: This implementation filters the result of AbstractCollection.iterator() for entries with a matching phrase.

Specified by:
phraseEntryIt in interface Dictionary<C>
Parameters:
phrase - The phrase to look up.
Returns:
Iterator over the entries with the specified phrase.

phraseEntries

@Deprecated
public DictionaryEntry<C>[] phraseEntries(String phrase)
Deprecated. Use phraseEntryList(String) instead.

Returns the dictionary entries with the specified phrase.

Implementation Note: This implementation buffers the results of phraseEntryIt(String) in a collection and then converts it to an array.

Specified by:
phraseEntries in interface Dictionary<C>
Parameters:
phrase - The phrase to look up.
Returns:
The entries with the specified phrase.

phraseEntryList

public List<DictionaryEntry<C>> phraseEntryList(String phrase)
Returns the dictionary entries with the specified phrase.

Implementation Note: This implementation buffers the results of phraseEntryIt(String) in a list.

Specified by:
phraseEntryList in interface Dictionary<C>
Parameters:
phrase - The phrase to look up.
Returns:
The entries with the specified phrase.

categoryEntryIt

public Iterator<DictionaryEntry<C>> categoryEntryIt(C category)
Returns an iterator over the dictionary entries with the specified category.

Implementation Note: This implementation filters the result of AbstractCollection.iterator() for entries with a matching category.

Specified by:
categoryEntryIt in interface Dictionary<C>
Parameters:
category - Category of entries.
Returns:
Iterator over entries with specified category.

categoryEntries

@Deprecated
public DictionaryEntry<C>[] categoryEntries(C category)
Deprecated. Use categoryEntryList(Object) instead.

Returns the dictionary entries with the specified category.

Implementation Note: This implementation buffers the results of categoryEntryIt(Object) in a collection and then converts it to an array.

Specified by:
categoryEntries in interface Dictionary<C>
Parameters:
category - Category of entries.
Returns:
Entries with specified category.

categoryEntryList

public List<DictionaryEntry<C>> categoryEntryList(C category)
Returns the dictionary entries with the specified category.

Implementation Note: This implementation buffers the results of categoryEntryIt(Object) in a list.

Specified by:
categoryEntryList in interface Dictionary<C>
Parameters:
category - Category of entries.
Returns:
Entries with specified category.

size

public int size()
Returns the size of this dictionary as measured by number of dictionary entries.

Implementation Note: The implementation here just takes the length of entries(). Subclasses may override this method for greater efficiency.

Specified by:
size in interface Dictionary<C>
Specified by:
size in interface Collection<DictionaryEntry<C>>
Specified by:
size in interface Set<DictionaryEntry<C>>
Specified by:
size in class AbstractCollection<DictionaryEntry<C>>
Returns:
Size of this dictionary.

entries

@Deprecated
public DictionaryEntry<C>[] entries()
Deprecated. Use entryList() instead.

Returns all of the dictionary entries for this dictionary.

Implementation Note: This implementation buffers the results of categoryEntryIt(Object) in a collection and then converts it to an array.

Specified by:
entries in interface Dictionary<C>
Returns:
This dictionary's entries.

entryList

public List<DictionaryEntry<C>> entryList()
Returns all of the dictionary entries for this dictionary.

Implementation Note: This implementation buffers the results of categoryEntryIt(Object) in a list.

Specified by:
entryList in interface Dictionary<C>
Returns:
This dictionary's entries.

addEntry

public void addEntry(DictionaryEntry<C> entry)
Adds the specified dictionary entry to the dictionary. This method must be overridden by subclasses that allow the addition of dictionary entries.

Specified by:
addEntry in interface Dictionary<C>
Parameters:
entry - Dictionary entry to add.
Throws:
UnsupportedOperationException - If this operation is not supported by a subclass implementation.

compileTo

public void compileTo(ObjectOutput out)
               throws IOException
Compiles this dictionary to the specified object output. This method must be overriden by subclasses that allow the compilation of dictionaries; the implementation here throws an unsupported operation exception.

Specified by:
compileTo in interface Compilable
Parameters:
out - Object output to which this dictionary is compiled.
Throws:
UnsupportedOperationException - If this operation is not supported by a subclass implementation.
IOException - If there is an I/O error writing the object.