📄 characterobject.java
字号:
package ECDictionaryUtil;
import java.io.Serializable;
import java.util.HashMap;
public class CharacterObject implements Serializable{
/**
* 这是一个汉字单元,包括汉字内码、汉字、HashMap、objectID、boolean 是否为词尾。
*/
int charaCode;
String chara;;
boolean isEnd=false;
HashMap hm=new HashMap(400);
//判断是不是为词尾
public void setIsEnd(boolean isEnd){
this.isEnd=isEnd;
}
public boolean getIsEnd(){
return this.isEnd;
}
//填充object实体
public void setChara(String chara) throws Exception{
try{this.chara=chara;
this.charaCode=this.getCharaCode();
}catch(Exception e){
System.out.println(e.getMessage());
}
}
public String getChara(){
return this.chara;
}
//汉字转换为汉字内码
public int getCharaCode()throws Exception
{ byte[] bytes = chara.getBytes("gbk");
if(bytes == null || bytes.length > 2 || bytes.length <= 0|| bytes.length == 1)
{ throw new Exception("不是一个有效的汉字!"); }
if(bytes.length == 2){ //汉字
int hByte,lByte;//汉字的高字节和低字节
if (bytes[0]<0)
{
hByte = 256 + bytes[0];
}
else{
//hByte = bytes[0];
throw new Exception("不是一个有效的汉字!");
}
if (bytes[1]<0)
{
lByte= 256 + bytes[1];
}
else{
//lByte = bytes[1];
throw new Exception("不是一个有效的汉字!");
}
int iHanzi = (256 * hByte + lByte);
return iHanzi;
}
throw new Exception("不是一个有效的汉字!");
}
public void addHashMap(int characode,CharacterObject charaObject){
this.hm.put(new Integer(characode),charaObject);
}
public HashMap getHashMap(){
return this.hm;
}
public static void main(String[] args) {
// TODO Auto-generated method stub
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -