Commit 1213aab0 authored by Gaston Dombiak's avatar Gaston Dombiak Committed by gaston

Minor refactoring work.


git-svn-id: http://svn.igniterealtime.org/svn/repos/messenger/trunk@747 b35dd754-fafc-0310-a699-88a17e54d16e
parent 7c3dcdc2
...@@ -176,9 +176,7 @@ public class PresenceUpdateHandler extends BasicModule implements ChannelHandler ...@@ -176,9 +176,7 @@ public class PresenceUpdateHandler extends BasicModule implements ChannelHandler
if (!"".equals(session.getAddress().getNode())) { if (!"".equals(session.getAddress().getNode())) {
String username = session.getAddress().getNode(); String username = session.getAddress().getNode();
Roster roster = rosterManager.getRoster(username); Roster roster = rosterManager.getRoster(username);
Iterator items = roster.getRosterItems(); for (RosterItem item : roster.getRosterItems()) {
while (items.hasNext()) {
RosterItem item = (RosterItem)items.next();
if (item.getRecvStatus() == RosterItem.RECV_SUBSCRIBE) { if (item.getRecvStatus() == RosterItem.RECV_SUBSCRIBE) {
session.getConnection().deliver(createSubscribePresence(item.getJid(), true)); session.getConnection().deliver(createSubscribePresence(item.getJid(), true));
} }
......
...@@ -77,12 +77,12 @@ public class Roster implements Cacheable { ...@@ -77,12 +77,12 @@ public class Roster implements Cacheable {
} }
/** /**
* Returns an iterator of users in this roster. * Returns a collection of users in this roster.
* *
* @return an iterator of users in this roster. * @return a collection of users in this roster.
*/ */
public Iterator<RosterItem> getRosterItems() { public Collection<RosterItem> getRosterItems() {
return Collections.unmodifiableMap(rosterItems).values().iterator(); return Collections.unmodifiableCollection(rosterItems.values());
} }
/** /**
...@@ -257,9 +257,7 @@ public class Roster implements Cacheable { ...@@ -257,9 +257,7 @@ public class Roster implements Cacheable {
*/ */
public org.xmpp.packet.Roster getReset() { public org.xmpp.packet.Roster getReset() {
org.xmpp.packet.Roster roster = new org.xmpp.packet.Roster(); org.xmpp.packet.Roster roster = new org.xmpp.packet.Roster();
Iterator items = getRosterItems(); for (RosterItem item : rosterItems.values()) {
while (items.hasNext()) {
RosterItem item = (RosterItem)items.next();
if (item.getSubStatus() != RosterItem.SUB_NONE || item.getAskStatus() != RosterItem.ASK_NONE) { if (item.getSubStatus() != RosterItem.SUB_NONE || item.getAskStatus() != RosterItem.ASK_NONE) {
roster.addItem(item.getJid(), item.getNickname(), roster.addItem(item.getJid(), item.getNickname(),
getAskStatus(item.getAskStatus()), getAskStatus(item.getAskStatus()),
...@@ -291,9 +289,7 @@ public class Roster implements Cacheable { ...@@ -291,9 +289,7 @@ public class Roster implements Cacheable {
if (routingTable == null) { if (routingTable == null) {
return; return;
} }
Iterator items = getRosterItems(); for (RosterItem item : rosterItems.values()) {
while (items.hasNext()) {
RosterItem item = (RosterItem)items.next();
if (item.getSubStatus() == RosterItem.SUB_BOTH if (item.getSubStatus() == RosterItem.SUB_BOTH
|| item.getSubStatus() == RosterItem.SUB_FROM) { || item.getSubStatus() == RosterItem.SUB_FROM) {
JID searchNode = new JID(item.getJid().getNode(), item.getJid().getDomain(), null); JID searchNode = new JID(item.getJid().getNode(), item.getJid().getDomain(), null);
...@@ -337,10 +333,6 @@ public class Roster implements Cacheable { ...@@ -337,10 +333,6 @@ public class Roster implements Cacheable {
size += CacheSizes.sizeOfObject(); // overhead of object size += CacheSizes.sizeOfObject(); // overhead of object
size += CacheSizes.sizeOfCollection(rosterItems.values()); // roster item cache size += CacheSizes.sizeOfCollection(rosterItems.values()); // roster item cache
size += CacheSizes.sizeOfString(username); // username size += CacheSizes.sizeOfString(username); // username
Iterator<RosterItem> itemIter = getRosterItems();
while (itemIter.hasNext()) {
size += itemIter.next().getCachedSize();
}
return size; return size;
} }
} }
\ No newline at end of file
...@@ -81,9 +81,8 @@ public class RosterManager extends BasicModule { ...@@ -81,9 +81,8 @@ public class RosterManager extends BasicModule {
roster = new Roster(username); roster = new Roster(username);
} }
// Remove each roster item from the user's roster // Remove each roster item from the user's roster
Iterator<RosterItem> items = roster.getRosterItems(); for (RosterItem item : roster.getRosterItems()) {
while (items.hasNext()) { roster.deleteRosterItem(item.getJid());
roster.deleteRosterItem(items.next().getJid());
} }
// Remove the cached roster from memory // Remove the cached roster from memory
CacheManager.getCache("username2roster").remove(username); CacheManager.getCache("username2roster").remove(username);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment