Permalink
Browse files

Adding isEqualToJID method to XMPPJID

  • Loading branch information...
1 parent ef1ff81 commit 1554ff4567e4268d27400e0909fc5f2923ed5deb @robbiehanson committed Aug 10, 2011
Showing with 34 additions and 24 deletions.
  1. +5 −0 Core/XMPPJID.h
  2. +29 −24 Core/XMPPJID.m
View
5 Core/XMPPJID.h
@@ -30,4 +30,9 @@
- (BOOL)isServer;
+/**
+ * When you know both objects are JIDs, this method is a faster way to check equality than isEqual:.
+**/
+- (BOOL)isEqualToJID:(XMPPJID *)aJID;
+
@end
View
53 Core/XMPPJID.m
@@ -355,34 +355,39 @@ - (BOOL)isEqual:(id)anObject
{
if ([anObject isMemberOfClass:[self class]])
{
- XMPPJID *aJID = (XMPPJID *)anObject;
-
- if (user) {
- if (![user isEqualToString:aJID->user]) return NO;
- }
- else {
- if (aJID->user) return NO;
- }
-
- if (domain) {
- if (![domain isEqualToString:aJID->domain]) return NO;
- }
- else {
- if (aJID->domain) return NO;
- }
-
- if (resource) {
- if (![resource isEqualToString:aJID->resource]) return NO;
- }
- else {
- if (aJID->resource) return NO;
- }
-
- return YES;
+ return [self isEqualToJID:(XMPPJID *)anObject];
}
return NO;
}
+- (BOOL)isEqualToJID:(XMPPJID *)aJID
+{
+ if (aJID == nil) return NO;
+
+ if (user) {
+ if (![user isEqualToString:aJID->user]) return NO;
+ }
+ else {
+ if (aJID->user) return NO;
+ }
+
+ if (domain) {
+ if (![domain isEqualToString:aJID->domain]) return NO;
+ }
+ else {
+ if (aJID->domain) return NO;
+ }
+
+ if (resource) {
+ if (![resource isEqualToString:aJID->resource]) return NO;
+ }
+ else {
+ if (aJID->resource) return NO;
+ }
+
+ return YES;
+}
+
- (NSString *)description
{
return [self full];

0 comments on commit 1554ff4

Please sign in to comment.