⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 cnwordgroup.java~25~

📁 一個手機程序(電子詞典),一個不可多得的源碼程序,是學習J2ME的好東東.
💻 JAVA~25~
字号:
package org.zblog.zenghelper.dbtool;

import java.util.Hashtable;
import java.io.ByteArrayOutputStream;
import java.io.DataOutputStream;
import java.util.Enumeration;
import java.io.IOException;
import java.io.ByteArrayInputStream;
import java.io.DataInputStream;

/**
 * <p>Title: ZEngHelper</p>
 *
 * <p>Description: Z英汉词典</p>
 *
 * <p>Copyright: Zcw Copyright (c) 2004</p>
 *
 * <p>Company: www.zblog.org Z动力</p>
 *
 * @author 朱传伟-ZCW
 * @version 1.0
 */
public class CnWordGroup {
    private int baseNum=0;
    //记录中 文字符串->id 集合
    private Hashtable cnWords=null;
    private byte[]bytes=null;
    public CnWordGroup(String firstWord){
        cnWords=new Hashtable();
    }

    private void load(String fw){

    }

    /**
     * 返回英文或中文字符的int型数值
     * @param word String
     * @return int
     */
    public int getWordNum(String word){
        char c=word.charAt(0);
        if(c<123)
            return baseNum+c;
        String t=(c+0)+"";
        return baseNum+Integer.parseInt(t.substring(t.length()-3));
    }


    /**
     * 查询中文词语,如果找到,则返回该词语的RMS id,
     * 否则返回-1,表示没有找到
     * @param word String
     * @return int
     */
    public int searchWord(String word){
        String vi=(String)cnWords.get(word);
        if(vi!=null){
            return Integer.parseInt(vi);
        }
        return -1;
    }

    /**
     * 向词组中添加单词
     * @param word String
     * @param rid int
     */
    public void addWord(String word,int rid){

    }


    /**
     * 将Hashtable中的值转换为byte[],主要用于数据库存储
     * @return byte[] 返回该组别的byte[]格式
     */
    public byte[] getBytes() throws IOException {
        if(bytes==null&&cnWords.size()>0){
            ByteArrayOutputStream bos=new ByteArrayOutputStream();
            DataOutputStream dos=new DataOutputStream(bos);
            Enumeration enu=cnWords.keys();
            Object key,value=null;
            try{
                dos.write(cnWords.size());
                while (enu.hasMoreElements()) {
                    key = enu.nextElement();
                    value = cnWords.get(key);
                    dos.writeUTF((String) key);
                    dos.writeUTF((String) value);
                }
            }catch(Exception e){
                e.printStackTrace();
            }
            bytes=bos.toByteArray();
            dos.close();;
            bos.close();
        }
        return bytes;
    }
    /**
     * 从RMS中取出byte[],并恢复原格式
     * @param data byte[]
     */
    public void setByte(byte[]data){
        if(data==null||data.length==0){
            cnWords.clear();
            return;
        }
        try{
            ByteArrayInputStream bis = new ByteArrayInputStream(data);
            DataInputStream dis = new DataInputStream(bis);
            int count = dis.readInt();
            count=count/2;
            cnWords.clear();
            while(count>0){
                cnWords.put(dis.readUTF(),dis.readUTF());
                count--;
            }
            dis.close();
            bis.close();
        }
        catch(Exception e){
            e.printStackTrace();
        }
    }
}

⌨️ 快捷键说明

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