rosteritem.java
来自「基于Jabber协议的即时消息服务器」· Java 代码 · 共 525 行 · 第 1/2 页
JAVA
525 行
/**
* <p>Obtain the current recv status of the item.</p>
*
* @return The recv status of the item
*/
public RecvType getRecvStatus() {
return recvStatus;
}
/**
* <p>Set the current recv status of the item.</p>
*
* @param recvStatus The recv status of the item
*/
public void setRecvStatus(RecvType recvStatus) {
this.recvStatus = recvStatus;
}
/**
* <p>Obtain the address of the item.</p>
*
* @return The address of the item
*/
public JID getJid() {
return jid;
}
/**
* <p>Obtain the current nickname for the item.</p>
*
* @return The subscription status of the item
*/
public String getNickname() {
return nickname;
}
/**
* <p>Set the current nickname for the item.</p>
*
* @param nickname The subscription status of the item
*/
public void setNickname(String nickname) {
this.nickname = nickname;
}
/**
* Returns the groups for the item. Shared groups won't be included in the answer.
*
* @return The groups for the item.
*/
public List<String> getGroups() {
return groups;
}
/**
* <p>Set the current groups for the item.</p>
*
* @param groups The new lists of groups the item belongs to.
*/
public void setGroups(List<String> groups) throws SharedGroupException {
if (groups == null) {
this.groups = new LinkedList<String>();
}
else {
// Raise an error if the user is trying to remove the item from a shared group
for (Group group: getSharedGroups()) {
// Get the display name of the group
String groupName = group.getProperties().get("sharedRoster.displayName");
// Check if the group has been removed from the new groups list
if (!groups.contains(groupName)) {
throw new SharedGroupException("Cannot remove item from shared group");
}
}
// Remove shared groups from the param
Collection<Group> existingGroups = GroupManager.getInstance().getSharedGroups();
for (Iterator<String> it=groups.iterator(); it.hasNext();) {
String groupName = it.next();
try {
// Optimistic approach for performance reasons. Assume first that the shared
// group name is the same as the display name for the shared roster
// Check if exists a shared group with this name
Group group = GroupManager.getInstance().getGroup(groupName);
// Get the display name of the group
String displayName = group.getProperties().get("sharedRoster.displayName");
if (displayName != null && displayName.equals(groupName)) {
// Remove the shared group from the list (since it exists)
try {
it.remove();
}
catch (IllegalStateException e) {
// Do nothing
}
}
}
catch (GroupNotFoundException e) {
// Check now if there is a group whose display name matches the requested group
for (Group group : existingGroups) {
// Get the display name of the group
String displayName = group.getProperties().get("sharedRoster.displayName");
if (displayName != null && displayName.equals(groupName)) {
// Remove the shared group from the list (since it exists)
try {
it.remove();
}
catch (IllegalStateException ise) {
// Do nothing
}
}
}
}
}
this.groups = groups;
}
}
/**
* Returns the shared groups for the item.
*
* @return The shared groups this item belongs to.
*/
public Collection<Group> getSharedGroups() {
Collection<Group> groups = new ArrayList<Group>(sharedGroups.size());
for (String groupName : sharedGroups) {
try {
groups.add(GroupManager.getInstance().getGroup(groupName));
}
catch (GroupNotFoundException e) {
// Do nothing
}
}
return groups;
}
/**
* Returns the invisible shared groups for the item. These groups are for internal use
* and help track the reason why a roster item has a presence subscription of type FROM
* when using shared groups.
*
* @return The shared groups this item belongs to.
*/
public Collection<Group> getInvisibleSharedGroups() {
Collection<Group> groups = new ArrayList<Group>(invisibleSharedGroups.size());
for (String groupName : invisibleSharedGroups) {
try {
groups.add(GroupManager.getInstance().getGroup(groupName));
}
catch (GroupNotFoundException e) {
// Do nothing
}
}
return groups;
}
Set<String> getInvisibleSharedGroupsNames() {
return invisibleSharedGroups;
}
void setInvisibleSharedGroupsNames(Set<String> groupsNames) {
invisibleSharedGroups = groupsNames;
}
/**
* Adds a new group to the shared groups list.
*
* @param sharedGroup The shared group to add to the list of shared groups.
*/
public void addSharedGroup(Group sharedGroup) {
sharedGroups.add(sharedGroup.getName());
invisibleSharedGroups.remove(sharedGroup.getName());
}
/**
* Adds a new group to the list shared groups that won't be sent to the user. These groups
* are for internal use and help track the reason why a roster item has a presence
* subscription of type FROM when using shared groups.
*
* @param sharedGroup The shared group to add to the list of shared groups.
*/
public void addInvisibleSharedGroup(Group sharedGroup) {
invisibleSharedGroups.add(sharedGroup.getName());
}
/**
* Removes a group from the shared groups list.
*
* @param sharedGroup The shared group to remove from the list of shared groups.
*/
public void removeSharedGroup(Group sharedGroup) {
sharedGroups.remove(sharedGroup.getName());
invisibleSharedGroups.remove(sharedGroup.getName());
}
/**
* Returns true if this item belongs to a shared group. Return true even if the item belongs
* to a personal group and a shared group.
*
* @return true if this item belongs to a shared group.
*/
public boolean isShared() {
return !sharedGroups.isEmpty() || !invisibleSharedGroups.isEmpty();
}
/**
* Returns true if this item belongs ONLY to shared groups. This means that the the item is
* considered to be "only shared" if it doesn't belong to a personal group but only to shared
* groups.
*
* @return true if this item belongs ONLY to shared groups.
*/
public boolean isOnlyShared() {
return isShared() && groups.isEmpty();
}
/**
* Returns the roster ID associated with this particular roster item. A value of zero
* means that the roster item is not being persisted in the backend store.<p>
*
* Databases can use the roster ID as the key in locating roster items.
*
* @return The roster ID
*/
public long getID() {
return rosterID;
}
/**
* Sets the roster ID associated with this particular roster item. A value of zero
* means that the roster item is not being persisted in the backend store.<p>
*
* Databases can use the roster ID as the key in locating roster items.
*
* @param rosterID The roster ID.
*/
public void setID(long rosterID) {
this.rosterID = rosterID;
}
/**
* <p>Update the cached item as a copy of the given item.</p>
* <p/>
* <p>A convenience for getting the item and setting each attribute.</p>
*
* @param item The item who's settings will be copied into the cached copy
*/
public void setAsCopyOf(org.xmpp.packet.Roster.Item item) throws SharedGroupException {
setGroups(new LinkedList<String>(item.getGroups()));
setNickname(item.getName());
}
public int getCachedSize() {
int size = jid.toBareJID().length();
size += CacheSizes.sizeOfString(nickname);
size += CacheSizes.sizeOfCollection(groups);
size += CacheSizes.sizeOfInt(); // subStatus
size += CacheSizes.sizeOfInt(); // askStatus
size += CacheSizes.sizeOfLong(); // id
return size;
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?