worddb.java

来自「简单的英汉词典 用三层结构(界面层、事务处理层、数据层)编辑」· Java 代码 · 共 72 行

JAVA
72
字号
import java.util.*;	// using class LinkedList

 /**
  * Data hierarchy: realize the word database basic function inherited from class LinkedList. The word element is stored in class WordItem.<br> 
  * This class stores the word database, can add a new word to the front of the words existed.<br>
  * It can also load words from a file to the database.<br>
  *
  *	Date: May. 28, 2007
  *
  * @author Bai Feng
  * @version 1.8
  */
 public class WordDB extends LinkedList {

	/**
	 * constructor for WordDB
	 *
	 */	 	
 	public WordDB() {
 		super();	// call parent class constructor	
 	}
 	 		
	/**
	 * judge if the word database is empty
	 *
	 * @return result(true, flase) 	 		
	 */
 	public boolean isEmpty() {
 		return ( size() == 0 );
 	}
 	
 	/**
 	 * add a new word to the front of the dictionary
 	 *
 	 * @param wi a word item
 	 */ 	
 	public boolean add( Object wi ) {
		addFirst( ( WordItem ) wi );
		//System.out.println( toString() );
		return true;
 	}	// end of method add()
 	
   /**
 	 * add a new word to the last position of the dictionary according to the sequence in the file.
 	 *
 	 * @param wi a word item
 	 */
 	public boolean loadWordDB( Object wi ) {
 		addLast( ( WordItem ) wi );
 		return true;
 	}
 	
	/**
	 * convert the class to a string.
	 *
	 * @return string converted
	 */	 	
 	public String toString() {
 		String result = "";
 		ListIterator iter = listIterator( 0 );

		if ( iter.hasNext() ) {
			result = (( WordItem ) iter.next() ).toString() + "\n";
		}

		while ( iter.hasNext() ) {
			result += (( WordItem ) iter.next()).toString() + "\n";
		} 		
 		return result;
 	}	// end of method toString()

}	// end of class WordDB

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?