IOSAD-92 primitive PEPMessage.hash and isEqual IOSAD-92
authorDirk Zimmermann <dirk@pep-project.org>
Tue, 24 Apr 2018 13:29:14 +0200
branchIOSAD-92
changeset 589addf605406d0
parent 588 096d99f1d6ec
child 590 5cf796a94b87
IOSAD-92 primitive PEPMessage.hash and isEqual
pEpObjCAdapter/PEPMessage.m
     1.1 --- a/pEpObjCAdapter/PEPMessage.m	Tue Apr 24 10:25:46 2018 +0200
     1.2 +++ b/pEpObjCAdapter/PEPMessage.m	Tue Apr 24 13:29:14 2018 +0200
     1.3 @@ -7,6 +7,7 @@
     1.4  //
     1.5  
     1.6  #import "PEPMessage.h"
     1.7 +#import "PEPIdentity.h"
     1.8  
     1.9  @implementation PEPMessage
    1.10  
    1.11 @@ -235,4 +236,67 @@
    1.12      return newMessage;
    1.13  }
    1.14  
    1.15 +// MARK: - Equality
    1.16 +
    1.17 +- (BOOL)isEqualToPEPMessage:(PEPMessage * _Nonnull)message
    1.18 +{
    1.19 +    return [self.attachments isEqualToArray:message.attachments] &&
    1.20 +    [self.bcc isEqualToArray:message.bcc] &&
    1.21 +    [self.cc isEqualToArray:message.cc] &&
    1.22 +    self.direction == message.direction &&
    1.23 +    [self.from isEqual:message.from] &&
    1.24 +    [self.inReplyTo isEqualToArray:message.inReplyTo] &&
    1.25 +    [self.keywords isEqualToArray:message.keywords] &&
    1.26 +    [self.longMessage isEqualToString:message.longMessage] &&
    1.27 +    [self.longMessageFormatted isEqualToString:message.longMessageFormatted] &&
    1.28 +    [self.messageID isEqualToString:message.messageID] &&
    1.29 +    [self.optionalFields isEqualToArray:message.optionalFields] &&
    1.30 +    [self.receivedBy isEqual:message.receivedBy] &&
    1.31 +    [self.receivedDate isEqual:message.receivedDate] &&
    1.32 +    [self.references isEqualToArray:message.references] &&
    1.33 +    [self.replyTo isEqualToArray:message.replyTo] &&
    1.34 +    [self.sentDate isEqual:message.sentDate] &&
    1.35 +    [self.shortMessage isEqualToString:message.shortMessage] &&
    1.36 +    [self.to isEqual:message.to];
    1.37 +}
    1.38 +
    1.39 +- (NSUInteger)hash
    1.40 +{
    1.41 +    NSUInteger prime = 31;
    1.42 +    NSUInteger result = 1;
    1.43 +
    1.44 +    result = prime * result + self.direction;
    1.45 +
    1.46 +    result = prime * result + self.attachments.hash;
    1.47 +    result = prime * result + self.bcc.hash;
    1.48 +    result = prime * result + self.cc.hash;
    1.49 +    result = prime * result + self.from.hash;
    1.50 +    result = prime * result + self.inReplyTo.hash;
    1.51 +    result = prime * result + self.keywords.hash;
    1.52 +    result = prime * result + self.longMessage.hash;
    1.53 +    result = prime * result + self.longMessageFormatted.hash;
    1.54 +    result = prime * result + self.messageID.hash;
    1.55 +    result = prime * result + self.optionalFields.hash;
    1.56 +    result = prime * result + self.receivedBy.hash;
    1.57 +    result = prime * result + self.receivedDate.hash;
    1.58 +    result = prime * result + self.references.hash;
    1.59 +    result = prime * result + self.replyTo.hash;
    1.60 +    result = prime * result + self.shortMessage.hash;
    1.61 +    result = prime * result + self.to.hash;
    1.62 +
    1.63 +    return result;
    1.64 +}
    1.65 +
    1.66 +- (BOOL)isEqual:(id)object
    1.67 +{
    1.68 +    if (object == self) {
    1.69 +        return YES;
    1.70 +    }
    1.71 +    if (!object || ![object isKindOfClass:[self class]]) {
    1.72 +        return NO;
    1.73 +    }
    1.74 +
    1.75 +    return [self isEqualToPEPMessage:object];
    1.76 +}
    1.77 +
    1.78  @end