📄 addcharacter.java
字号:
package ECDictionaryUtil;
import java.io.IOException;
import java.io.ObjectOutputStream;
import java.util.HashMap;
public class AddCharacter {
/**
* 把字符串的汉字添加到词典中
*/
ObjectOutputStream os;
HashMap hm0=null;
static ObjectHead ohead;
public static void setObjectHead(ObjectHead oheads){
ohead=oheads;
}
public void setObjectStream(ObjectOutputStream os){
this.os=os;
}
/*
* 以下代码是添加字符串头汉字到词典中
*/
public void addHead(String headChara) throws Exception{ //headChara有且只有一个汉字
try{
HashMap hm=ohead.getHashMap();
if(hm.containsKey(new Integer(new CharaCode().getCharaCode(headChara)))){ //如果已经包含次头汉字,则取出此汉字的HashMap
CharacterObject charaOb=(CharacterObject)hm.get(new Integer(new CharaCode().getCharaCode(headChara)));
this.hm0=(HashMap)charaOb.getHashMap();
}else{ //不包含此头汉字,则新建一个汉字到词典中,并取出这个汉字的HashMap
CharacterObject charaOb=new CharacterObject();
charaOb.setChara(headChara);
hm.put(new Integer(new CharaCode().getCharaCode(headChara)),charaOb);
hm0=charaOb.getHashMap();
}
}catch(IOException ee){
ee.printStackTrace();
}
}
/*
* * 以下代码是添加字符串中间汉字到词典中
*/
public void addMiddleChara(String middleChara) throws Exception{
try{
if(this.hm0.containsKey(new Integer(new CharaCode().getCharaCode(middleChara)))){ //如果已经包含次头汉字,则取出此汉字的HashMap
CharacterObject charaOb=(CharacterObject)this.hm0.get(new Integer(new CharaCode().getCharaCode(middleChara)));
this.hm0=(HashMap)charaOb.getHashMap();
}else{ //不包含此头汉字,则新建一个汉字到词典中,并取出这个汉字的HashMap
CharacterObject charaOb=new CharacterObject();
charaOb.setChara(middleChara);
this.hm0.put(new Integer(new CharaCode().getCharaCode(middleChara)),charaOb);
this.hm0=charaOb.getHashMap();
}
}catch(Exception ee){
ee.printStackTrace();
}
}
public void addTail(String tailChara){
try{
if(this.hm0.containsKey(new Integer(new CharaCode().getCharaCode(tailChara)))){ //如果已经包含次头汉字,则取出此汉字的HashMap
CharacterObject charaOb=(CharacterObject)this.hm0.get(new Integer(new CharaCode().getCharaCode(tailChara)));
charaOb.setIsEnd(true);
}else{ //不包含此头汉字,则新建一个汉字到词典中,并取出这个汉字的HashMap
CharacterObject charaOb=new CharacterObject();
charaOb.setChara(tailChara);
charaOb.setIsEnd(true);
this.hm0.put(new Integer(new CharaCode().getCharaCode(tailChara)),charaOb);
}
}catch(Exception ee){
ee.printStackTrace();
}
}
public void saveCharacter() throws IOException{
try{
os.writeObject(ohead);
}catch(IOException ee){
ee.printStackTrace();
}
}
public static void main(String[] args) throws Exception {
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -