One, the idea
1, the Dictionary realization class Arraydictionary.java must implements the Dictionary interface Dictionaryinterface.java (reference: http://www.cnblogs.com/hapjin/p/4573826.html). Second, in order to serialize, but also to implements serializable interface
2, because each element in the dictionary is a key-value pair. Therefore, the lookup key and value need to be encapsulated in the same object, so Entry.java is defined to represent each element in the dictionary. Among them, the entry class is implemented as the inner class of the arraydictionary.
3, because each entry object represents a dictionary element, Arraydictionary.java requires an array of entry types to hold the dictionary elements. This is also the title of the article-the use of sequential tables to achieve the cause of the dictionary.
In further discussion, we know that Arraylist.java in the Java class Library is equivalent to a sequential table (array) that has been implemented for programmers, and we do not need to pay attention to the specifics of the implementation of the array and how to iterate over the array, but instead use the various methods in the Arraylist.java directly ( Add,remove ...) To complete the basic operation of the array, the iterator that iterates through the array is obtained through the iterator () method. You can also use the Arraylist.java method to assist in implementing the methods defined in the Dictionaryinterface interface.
However, in this case, a custom array is used to implement the dictionary, so the method in Arraydictionary.java needs to be done according to the methods in the Dictionaryinterface interface and the needs of the self.
Below, specifically to clarify the implementation of the idea of the iterator: in arraydictionary. Java, three private inner classes are defined to represent implementations of three iterators:
Class Entryiterator<entry> iterator that iterates through the Entry array
Class Keyiterator<k> iterator that implements the traversal lookup key
Class Valueiterator<v> iterator that implements the value
Where the latter two iterators use iterators that traverse the entry array, because the key (key) and values (value) are encapsulated in the entry.
At the same time, the Arraydictionary.java defines three corresponding methods of acquiring the ergodic device to obtain the above three ergodic.
To be Continued ...
Dictionary implementation (2)-Using sequential tables (arrays) to implement dictionaries