Java tutorial
/** * @(#)WebQQClinetContext.java 2013-1-23 * * Copyright (c) 2004-2013 Lakala, Inc. * zhongjiang Road, building 22, Lane 879, shanghai, china * All Rights Reserved. * * This software is the confidential and proprietary information of Lakala, Inc. * You shall not disclose such Confidential Information and shall use it only in * accordance with the terms of the license agreement you entered into * with Lakala. */ package org.okj.im.core; import java.io.Serializable; import java.util.ArrayList; import java.util.List; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; import org.apache.commons.lang.StringUtils; import org.okj.im.model.AuthToken; import org.okj.im.model.Group; import org.okj.im.model.Member; /** * WebQQ * @author Administrator * @version $Id: WebQQClinetContext.java, v 0.1 2013-1-23 ?10:43:51 Administrator Exp $ */ public class WebQQClinetContext implements Serializable { /** UID */ private static final long serialVersionUID = 5262709099737501091L; /* ? */ private static WebQQClinetContext instance = new WebQQClinetContext(); /* QQ */ private Member self; /* cookies */ private StringBuffer cookies = new StringBuffer(); /* ? */ private AuthToken token = new AuthToken(); /* ? */ private Map<String, Member> onlineFriends = new ConcurrentHashMap<String, Member>(); /* QQ */ private Map<Long, Group> groups = new ConcurrentHashMap<Long, Group>(); private boolean run = false; /** * ? */ protected WebQQClinetContext() { } /** * ? * @return */ public static WebQQClinetContext getInstance() { return instance; } /** * ? * @param member */ public void put(Member member) { this.self = member; } /** * ? * @return */ public Member get() { return this.self; } /** * cookie * @param cookie */ public void addCookie(String cookie) { cookies.append(cookie); } /** * cookies * @return */ public String getCookies() { return cookies.toString(); } /** * cookies */ public void removeCookies() { cookies.delete(0, cookies.length()); } /** * ?? * @param checkType * @param verifycode ?? * @param verifycodeHex ??16? */ public void resetToken(String checkType, String verifycode, String verifycodeHex) { token.setCheckType(checkType); token.setVerifycode(verifycode); token.setVerifycodeHex(verifycodeHex); } /** * ?? * @return */ public String getVerifyCode() { if (StringUtils.isNotBlank(token.getVerifycode())) { return StringUtils.upperCase(token.getVerifycode()); } return StringUtils.EMPTY; } /** * clientId * @return */ public String getClientId() { return String.valueOf(token.getClientid()); } /** * sessionID * @return */ public String getPSessionId() { return token.getPsessionid(); } /** * getVfwebqq * @return */ public String getVfwebqq() { return token.getVfwebqq(); } /** * ? * @return */ public AuthToken getToken() { return token; } /** * ??? * @return */ public boolean isLoadedFriends() { if (self == null) { return false; } if (self.getFriends() != null && !self.getFriends().isEmpty()) { return true; } return false; } /** * ?QQ??? * @param account * @return */ public Member findFriend(String account) { for (Member friend : this.self.getFriends()) { if (StringUtils.equals(account, friend.getAccount().getAccount())) { return friend; } } return null; } /** * ??(???) * @param uin * @return */ public Member findFriend(long uin) { for (Member friend : this.self.getFriends()) { if (friend.getUin() == uin) { return friend; } } return null; } /** * ? * @param friend */ public void addOnlineFriend(Member friend) { onlineFriends.put(String.valueOf(friend.getUin()), friend); } /** * QQ??? * @param account * @return */ public Member getOnlineFriend(String account) { return onlineFriends.get(account); } /** * ? * @param account */ public void removeOnlineFriend(String account) { onlineFriends.remove(account); } /** * ? */ public void removeOnlineFriends() { onlineFriends.clear(); } /** * ? * @return */ public List<Member> getOnlineFriends() { return new ArrayList<Member>(onlineFriends.values()); } /** * QQ * @param friend */ public void addGroup(Group group) { if (group != null) { groups.put(group.getNumber(), group); } } /** * QQ?? * @param account * @return */ public Group getGroup(long number) { return groups.get(number); } /** * QQ * @param account */ public void removeGroup(long number) { groups.remove(number); } /** * QQ */ public void removeGroups() { groups.clear(); } /** * QQ? * @return */ public List<Group> getGroups() { return new ArrayList<Group>(groups.values()); } /** * */ public void clear() { this.self = null; this.cookies = null; this.token = null; onlineFriends.clear(); groups.clear(); } public Member getSelf() { return self; } public void setSelf(Member self) { this.self = self; } public boolean isRun() { return run; } public void setRun(boolean run) { this.run = run; } }