From 18677279f28792da1c23da6a0fb84d1dd0e46ea1 Mon Sep 17 00:00:00 2001 From: Gaston Dombiak Date: Tue, 24 Jan 2006 18:14:41 +0000 Subject: [PATCH] Removed #toLowecase() calls wherever possible. SMACK-109 git-svn-id: http://svn.igniterealtime.org/svn/repos/smack/trunk@3349 b35dd754-fafc-0310-a699-88a17e54d16e --- source/org/jivesoftware/smack/Roster.java | 25 +++++++------------ .../org/jivesoftware/smack/RosterEntry.java | 2 +- .../org/jivesoftware/smack/RosterGroup.java | 23 ++++------------- .../smack/packet/RosterPacket.java | 2 +- 4 files changed, 16 insertions(+), 36 deletions(-) diff --git a/source/org/jivesoftware/smack/Roster.java b/source/org/jivesoftware/smack/Roster.java index 7bf825a34..196a4c3ea 100644 --- a/source/org/jivesoftware/smack/Roster.java +++ b/source/org/jivesoftware/smack/Roster.java @@ -375,10 +375,11 @@ public class Roster { if (user == null) { return null; } + String userLowerCase = user.toLowerCase(); synchronized (entries) { for (Iterator i=entries.iterator(); i.hasNext(); ) { RosterEntry entry = (RosterEntry)i.next(); - if (entry.getUser().toLowerCase().equals(user.toLowerCase())) { + if (entry.getUser().equals(userLowerCase)) { return entry; } } @@ -394,18 +395,7 @@ public class Roster { * @return true if the XMPP address is an entry in the roster. */ public boolean contains(String user) { - if (user == null) { - return false; - } - synchronized (entries) { - for (Iterator i=entries.iterator(); i.hasNext(); ) { - RosterEntry entry = (RosterEntry)i.next(); - if (entry.getUser().toLowerCase().equals(user.toLowerCase())) { - return true; - } - } - } - return false; + return getEntry(user) != null; } /** @@ -541,11 +531,14 @@ public class Roster { * @return the key to use in the presenceMap for the fully qualified xmpp ID. */ private String getPresenceMapKey(String user) { + if (user == null) { + return null; + } String key = user; if (!contains(user)) { key = StringUtils.parseBareAddress(user); } - return key; + return key.toLowerCase(); } /** @@ -620,7 +613,7 @@ public class Roster { synchronized (entries) { for (Iterator i = entries.iterator(); i.hasNext();) { RosterEntry entry = (RosterEntry) i.next(); - if (entry.getUser().toLowerCase().equals(key.toLowerCase())) { + if (entry.getUser().equals(key)) { fireRosterPresenceEvent(from); } } @@ -641,7 +634,7 @@ public class Roster { synchronized (entries) { for (Iterator i=entries.iterator(); i.hasNext(); ) { RosterEntry entry = (RosterEntry)i.next(); - if (entry.getUser().toLowerCase().equals(key.toLowerCase())) { + if (entry.getUser().equals(key)) { fireRosterPresenceEvent(from); } } diff --git a/source/org/jivesoftware/smack/RosterEntry.java b/source/org/jivesoftware/smack/RosterEntry.java index d61ad3814..d972c2bf6 100644 --- a/source/org/jivesoftware/smack/RosterEntry.java +++ b/source/org/jivesoftware/smack/RosterEntry.java @@ -172,7 +172,7 @@ public class RosterEntry { return true; } if (object != null && object instanceof RosterEntry) { - return user.toLowerCase().equals(((RosterEntry)object).getUser().toLowerCase()); + return user.equals(((RosterEntry)object).getUser()); } else { return false; diff --git a/source/org/jivesoftware/smack/RosterGroup.java b/source/org/jivesoftware/smack/RosterGroup.java index 2d740e5ba..c84dd15c9 100644 --- a/source/org/jivesoftware/smack/RosterGroup.java +++ b/source/org/jivesoftware/smack/RosterGroup.java @@ -119,10 +119,11 @@ public class RosterGroup { // Roster entries never include a resource so remove the resource // if it's a part of the XMPP address. user = StringUtils.parseBareAddress(user); + String userLowerCase = user.toLowerCase(); synchronized (entries) { for (Iterator i=entries.iterator(); i.hasNext(); ) { RosterEntry entry = (RosterEntry)i.next(); - if (entry.getUser().toLowerCase().equals(user.toLowerCase())) { + if (entry.getUser().equals(userLowerCase)) { return entry; } } @@ -149,21 +150,7 @@ public class RosterGroup { * @return true if the XMPP address is an entry in this group. */ public boolean contains(String user) { - if (user == null) { - return false; - } - // Roster entries never include a resource so remove the resource - // if it's a part of the XMPP address. - user = StringUtils.parseBareAddress(user); - synchronized (entries) { - for (Iterator i=entries.iterator(); i.hasNext(); ) { - RosterEntry entry = (RosterEntry)i.next(); - if (entry.getUser().toLowerCase().equals(user.toLowerCase())) { - return true; - } - } - } - return false; + return getEntry(user) != null; } /** @@ -200,7 +187,7 @@ public class RosterGroup { throw new XMPPException(response.getError()); } // Add the new entry to the group since the server processed the request successfully - entries.add(entry); + addEntryLocal(entry); } } @@ -242,7 +229,7 @@ public class RosterGroup { throw new XMPPException(response.getError()); } // Remove the entry locally since the server processed the request successfully - entries.remove(entry); + removeEntryLocal(entry); } } diff --git a/source/org/jivesoftware/smack/packet/RosterPacket.java b/source/org/jivesoftware/smack/packet/RosterPacket.java index 0008428d0..30048b7c3 100644 --- a/source/org/jivesoftware/smack/packet/RosterPacket.java +++ b/source/org/jivesoftware/smack/packet/RosterPacket.java @@ -97,7 +97,7 @@ public class RosterPacket extends IQ { * @param name the user's name. */ public Item(String user, String name) { - this.user = user; + this.user = user.toLowerCase(); this.name = name; itemType = null; itemStatus = null;