simpledictionary.java

来自「使用面向对象方法完成“快速拼写检查程序”的分析、设计和实现过程。快速拼写检查程序」· Java 代码 · 共 62 行

JAVA
62
字号
package tokenchecker;

import java.io.Serializable;
import java.util.TreeSet;
import java.io.*;
/**
 * class SimpleDictionary is a simple dictionary used to check
 * the word is correct or not 
 */
 
public class SimpleDictionary implements Serializable { 
	
	private String name;
	private String info;
	private boolean changed;
	private TreeSet treeset;
	
	public SimpleDictionary() {
		name = new String();
		info = new String();
		treeset = new TreeSet();		
	}
	public String getName() {
		return name;
	}
	public void setName(String name) {
		if(!this.name.equals(name)){
			this.name = name;
			changed = true;
		}
	}
	public String getInfo() {
		return info;
	}
	public void setInfo(String info) {
		if(!this.info.equals(info)){
			this.info = info;
			changed = true;
		}
	}
	public boolean isChanged() {
		return changed;
	}
	public void saveChanged() throws IOException {
		ObjectOutputStream objOut = new ObjectOutputStream(
							new FileOutputStream(this.getName()));
				objOut.writeObject(this);
	}
	public boolean containsWord(String word) {
		return treeset.contains(word);
	}
	public void addWord(String word) {
		System.out.println("here in add word .the word is " + word);
		treeset.add(word);
		changed = true;
	}
	public boolean removeWord(String word) {
		System.out.println("here in remove word .the word is " + word);
		changed = true;
		return treeset.remove(word);
	}	  
} 

⌨️ 快捷键说明

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