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

📄 remarkutils.java

📁 类似于MSN
💻 JAVA
字号:
/*
* LumaQQ - Java QQ Client
*
* Copyright (C) 2004 luma <stubma@163.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
package edu.tsinghua.lumaqq.utils;

import java.io.File;
import java.io.IOException;
import java.util.Hashtable;
import java.util.Iterator;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import edu.tsinghua.lumaqq.xml.remarks.Remark;
import edu.tsinghua.lumaqq.xml.remarks.Remarks;
import edu.tsinghua.lumaqq.xml.remarks.RemarksImpl;

/**
 * 管理用户备注的工具类
 * 
 * @author 马若劼
 */
public class RemarkUtils {
	// 备注hash表
	private Hashtable hash;
	// 保存备注信息的文件名
	private String fileName;
    // Log对象
    private static Log log = LogFactory.getLog(RemarkUtils.class);
    
	// singleton模式
	private static RemarkUtils instance = new RemarkUtils();
	
	/**
	 * 私有构造函数
	 */
	private RemarkUtils() {
		hash = new Hashtable();
	}
	
	/**
	 * @return 单一实例
	 */
	public static RemarkUtils getInstance() {
		return instance;
	}
	
	/**
	 * 设置备注信息文件的根元素对象
	 * @param remarks
	 */
	public void setRemarksModel(Remarks remarks) {
		if(remarks == null) return;
		hash.clear();
		Iterator iter = remarks.getRemarkList().iterator();
		while(iter.hasNext()) {
			Remark remark = (Remark)iter.next();
			String qqStr = remark.getQqNum();
			Integer qqNum = new Integer(qqStr);
			hash.put(qqNum, remark);
		}
	}
	
	/**
	 * 保存备注到文件
	 */
	public void save() {
		// 新建一个Remarks对象,把哈希表中的remark都加入到其中
		Remarks remarks = new RemarksImpl();
		Iterator iter = hash.values().iterator();
		while(iter.hasNext()) {
			remarks.addRemark((Remark)iter.next());
		}
		// 创建文件对象,保存
		File file = new File(fileName);
		try {
			remarks.marshal(file);
		} catch (IOException e) {
			log.error("无法保存备注信息文件,所作的改变将丢弃");
		}
	}

	/**
	 * @param string
	 */
	public void setFileName(String string) {
		this.fileName = string;
	}
	
	/**
	 * 根据QQ号得到备注信息
	 * @param qqNum
	 * @return
	 */
	public Remark getRemark(int qqNum) {
		return getRemark(new Integer(qqNum));
	}
	
	/**
	 * 根据QQ号得到备注信息
	 * @param qqStr
	 * @return
	 */
	public Remark getRemark(String qqStr) {
		return getRemark(new Integer(qqStr));
	}

	/**
	 * 根据QQ号得到备注信息
	 * @param qqNum
	 * @return
	 */
	public Remark getRemark(Integer qqNum) {
		return (Remark)hash.get(qqNum);
	}
	
	/**
	 * 添加一个备注信息
	 * @param remark
	 */
	public void addRemark(Remark remark) {
		String qqStr = remark.getQqNum();
		Integer qqNum = new Integer(qqStr);
		hash.put(qqNum, remark);
	}
}

⌨️ 快捷键说明

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