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

📄 msnfriend.java

📁 J2me实现的MSN Messeger客户端程序。聊天、添加好友、删除好友、阻止好友
💻 JAVA
字号:
/*
 * @(#)MsnFriend.java
 *
 * Copyright (c) 2001-2002, JangHo Hwang
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 *
 * 	1. Redistributions of source code must retain the above copyright
 * notice, this list of conditions and the following disclaimer.
 *
 * 	2. Redistributions in binary form must reproduce the above copyright
 * notice, this list of conditions and the following disclaimer in the
 * documentation and/or other materials provided with the distribution.
 *
 * 	3. Neither the name of the JangHo Hwang nor the names of its contributors
 * may be used to endorse or promote products derived from this software
 * without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
 * A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR
 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 *
 *    $Id: MsnFriend.java,v 2.0 2004/12/21 16:15:08 chenzs Exp $
 */
package vitular.msnp.entity;

import java.io.UnsupportedEncodingException;

import vitular.msnp.UserStatus;
import vitular.msnp.msg.MimeUtility;

/**
 *
 * <p>Title: MSNP Lib 类MsnFriend用户</p>
 * <p>Description: Unija 版Msn协议</p>
 * <p>Copyright: Copyright (c) 2004</p>
 * <p>Company: Vitular</p>
 * @author ceze
 * @version 1.0
 */
public class MsnFriend
    implements UserStatus {
  private Integer groupIndex = new Integer(0);//所属组序号
  private String status = null;//当前状态
  private String oldStatus = null;//当前前一状态
  private String loginName = null;//登陆id(帐号)
  private String friendlyName = null;//用户昵称
  private String formatFriendlyName = null;//格式化的昵称(解析掉url传输中的编码字符)

  /**
   * 构造函数
   * @param loginName String 帐号
   */
  public MsnFriend(String loginName) {
    this(loginName, null);
  }

  /**
   * 构造函数
   * @param loginName String 帐号
   * @param friendlyName String 昵称
   */
  public MsnFriend(String loginName, String friendlyName) {
    this.loginName = loginName;
    this.friendlyName = friendlyName;
    setStatus(UserStatus.OFFLINE);
  }

  /**
   * 设置所属好友分组序号
   * @param index int
   */
  public void setGroupIndex(int index) {
    this.groupIndex = new Integer(index);
  }

  /**
   * 设置所属好友分组序号
   * @param index Integer
   */
  public void setGroupIndex(Integer index) {
    this.groupIndex = index;
  }

  /**
   * 获取分组序号
   * @return Integer
   */
  public Integer getGroupIndex() {
    return this.groupIndex;
  }

  /**
   * 指定帐号
   * @param loginName String
   */
  public void setLoginName(String loginName) {
    this.loginName = loginName;
  }

  /**
   * 获取帐号
   * @return String
   */
  public String getLoginName() {
    return this.loginName;
  }

  /**
   * 指定昵称
   * @param frName String
   */
  public void setFriendlyName(String frName) {
    this.friendlyName = frName;
    this.formatFriendlyName = null;
  }

  /**
   * 获取昵称
   * @return String
   */
  public String getFriendlyName() {
    return this.friendlyName;
  }

  /**
   * 获取格式化(如将%20还原成空格" ")昵称
   * @return String
   */
  public String getFormattedFriendlyName() {
    if (formatFriendlyName != null)
      return formatFriendlyName;
    if (this.friendlyName == null)
      return loginName;

    try {
      this.formatFriendlyName = MimeUtility.getURLDecodedString(
          this.friendlyName, "UTF-8");
    }
    catch (UnsupportedEncodingException e) {
      this.formatFriendlyName = formatFriendlyName;
    }
    return formatFriendlyName;
  }

  /**
   * 设置状态
   * @param st String
   */
  public void setStatus(String st) {
    if (st == null)
      st = UserStatus.OFFLINE;

    oldStatus = this.status;
    this.status = st;
  }

  /**
   * 获取之前状态
   */
  public String getOldStatus() {
    return this.oldStatus;
  }

  /**
   * 获取当前状态
   * @return String
   */
  public String getStatus() {
    return this.status;
  }

  /**
   * 完整用户描述: 帐号+加昵称+状态
   * @return String
   */
  public String toFullString() {
    return loginName + ":" + friendlyName + " (" + status + ")";
  }

  /**
   * 用户描述: 加昵称+状态
   * @return String
   */
  public String toString(){
    if(friendlyName == null)
      return loginName + "(" + status + ")";
    else
      return friendlyName + "(" + status + ")";
  }

  /**
     * 完整的格式化描述
     * @return String
     */
    public String toFormattedFullString() {
      return loginName + ": " + getFormattedFriendlyName() + "(" + getStatus() +
          ")";
    }

    /**
     * 格式化描述
     * @return String
     */
    public String toFormattedString(){
      if(friendlyName == null)
        return loginName +  "(" + getStatus() + ")";
      else
        return getFormattedFriendlyName() + "(" + getStatus() +")";
    }

  /**
   * 判断帐户是否相同
   * @param o Object
   * @return boolean
   */
  public boolean equals(Object o) {
    if (this == o)
      return true;
    if (o != null && o instanceof MsnFriend)
      return loginName.equals( ( (MsnFriend) o).loginName);
    return false;
  }

  /**
   * 帐号的hashcode
   * @return int
   */
  public int hashCode() {
    return loginName.hashCode();
  }


}

⌨️ 快捷键说明

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