Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Add Hash Methods where isEqual called #167

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions mParticle-Apple-SDK/Custom Modules/MPCustomModule.m
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@ - (BOOL)isEqual:(id)object {
return [[self dictionaryRepresentation] isEqualToDictionary:[(MPCustomModule *)object dictionaryRepresentation]];
}

- (NSUInteger)hash {
return [[self dictionaryRepresentation] hash];
}

#pragma mark NSCopying
- (id)copyWithZone:(NSZone *)zone {
MPCustomModule *copyObject = [[[self class] alloc] init];
Expand Down
4 changes: 4 additions & 0 deletions mParticle-Apple-SDK/Data Model/MPBreadcrumb.m
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ - (BOOL)isEqual:(MPBreadcrumb *)object {
return isEqual;
}

- (NSUInteger)hash {
return (NSUInteger)self.breadcrumbId ^ (NSUInteger)self.timestamp ^ [self.uuid hash] ^ [self.sessionUUID hash] ^ [self.breadcrumbData hash];
}

#pragma mark NSCopying
- (id)copyWithZone:(NSZone *)zone {
MPBreadcrumb *copyObject = [[MPBreadcrumb alloc] initWithSessionUUID:[_sessionUUID copy]
Expand Down
4 changes: 4 additions & 0 deletions mParticle-Apple-SDK/Data Model/MPConsumerInfo.mm
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ - (BOOL)isEqual:(MPCookie *)object {
return isEqual;
}

- (NSUInteger)hash {
return [self.name hash];
}

#pragma mark NSSecureCoding
- (void)encodeWithCoder:(NSCoder *)coder {
[coder encodeObject:_name forKey:@"name"];
Expand Down
4 changes: 4 additions & 0 deletions mParticle-Apple-SDK/Data Model/MPForwardRecord.mm
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,10 @@ - (BOOL)isEqual:(id)object {
return isEqual;
}

- (NSUInteger)hash {
return [self.dataDictionary hash] ^ self.forwardRecordId ^ [self.mpid hash];
}

#pragma mark Public methods
- (NSData *)dataRepresentation {
if (MPIsNull(_dataDictionary) || ![_dataDictionary isKindOfClass:[NSDictionary class]]) {
Expand Down
4 changes: 4 additions & 0 deletions mParticle-Apple-SDK/Data Model/MPMessage.m
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,10 @@ - (BOOL)isEqual:(MPMessage *)object {
return isEqual;
}

- (NSUInteger)hash {
return [self.sessionId hash] ^ [self.dataPlanId hash] ^ [self.dataPlanVersion hash] ^ self.messageId ^ (NSUInteger)self.timestamp ^ [self.messageType hash] ^ [self.messageData hash] ^ (NSUInteger)self.shouldUploadEvent;
}

#pragma mark NSCopying
- (id)copyWithZone:(NSZone *)zone {
MPMessage *copyObject = [[MPMessage alloc] initWithSessionId:[_sessionId copy]
Expand Down
4 changes: 4 additions & 0 deletions mParticle-Apple-SDK/Data Model/MPSegment.m
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,10 @@ - (BOOL)isEqual:(MPSegment *)object {
return isEqual;
}

- (NSUInteger)hash {
return [self.segmentId hash] ^ [self.name hash] ^ [self.memberships hash];
}

#pragma mark KVO
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context {
if ([keyPath isEqualToString:@"memberships"]) {
Expand Down
4 changes: 4 additions & 0 deletions mParticle-Apple-SDK/Data Model/MPSegmentMembership.m
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@ - (BOOL)isEqual:(MPSegmentMembership *)object {
return isEqual;
}

- (NSUInteger)hash {
return self.segmentMembershipId ^ (NSUInteger)self.timestamp ^ self.action;
}

#pragma mark NSCopying
- (id)copyWithZone:(NSZone *)zone {
MPSegmentMembership *copyObject = [[MPSegmentMembership alloc] initWithSegmentId:_segmentId
Expand Down
4 changes: 4 additions & 0 deletions mParticle-Apple-SDK/Data Model/MPSession.m
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,10 @@ - (BOOL)isEqual:(MPSession *)object {
return isEqual;
}

- (NSUInteger)hash {
return self.sessionId ^ self.eventCounter ^ [self.uuid hash];
}

#pragma mark NSCopying
- (id)copyWithZone:(NSZone *)zone {
MPSession *copyObject = [[MPSession alloc] initWithSessionId:_sessionId
Expand Down
4 changes: 4 additions & 0 deletions mParticle-Apple-SDK/Data Model/MPUpload.m
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@ - (BOOL)isEqual:(MPUpload *)object {
return isEqual;
}

- (NSUInteger)hash {
return [self.sessionId hash] ^ [self.dataPlanId hash] ^ [self.dataPlanVersion hash] ^ self.uploadId ^ (NSUInteger)self.timestamp;
}

#pragma mark NSCopying
- (id)copyWithZone:(NSZone *)zone {
MPUpload *copyObject = [[MPUpload alloc] initWithSessionId:[_sessionId copy]
Expand Down
4 changes: 4 additions & 0 deletions mParticle-Apple-SDK/Data Model/MParticleUserNotification.m
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,10 @@ - (BOOL)isEqual:(MParticleUserNotification *)object {
return isEqual;
}

- (NSUInteger)hash {
return (NSUInteger)self.userNotificationId;
}

#pragma mark Private methods
- (NSString *)redactUserNotification:(NSDictionary *)notificationDictionary {
NSString * (^dictionaryToString)(NSDictionary *) = ^(NSDictionary *dictionary) {
Expand Down
4 changes: 4 additions & 0 deletions mParticle-Apple-SDK/Ecommerce/MPCommerceEvent.mm
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,10 @@ - (BOOL)isEqual:(MPCommerceEvent *)object {
return isEqual;
}

- (NSUInteger)hash {
return [self.productActionAttributes hash] ^ [self.beautifiedAttributes hash] ^ [self.productsList hash] ^ [self.productImpressions hash] ^ [self.promotionContainer hash] ^ [self.transactionAttributes hash] ^ commerceEventKind ^ [self.currency hash];
}

#pragma mark NSCopying
- (id)copyWithZone:(NSZone *)zone {
MPCommerceEvent *copyObject = [super copyWithZone:zone];
Expand Down
4 changes: 4 additions & 0 deletions mParticle-Apple-SDK/Ecommerce/MPProduct.mm
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,10 @@ - (BOOL)isEqual:(id)object {
return [_objectDictionary isEqualToDictionary:((MPProduct *)object)->_objectDictionary];
}

- (NSUInteger)hash {
return [self.objectDictionary hash];
}

#pragma mark Private accessors
- (NSMutableDictionary<NSString *, id> *)beautifiedAttributes {
if (_beautifiedAttributes) {
Expand Down
8 changes: 8 additions & 0 deletions mParticle-Apple-SDK/Ecommerce/MPPromotion.mm
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,10 @@ - (BOOL)isEqual:(id)object {
}
}

- (NSUInteger)hash {
return [self.attributes hash];
}

#pragma mark Private accessors
- (NSMutableDictionary<NSString *, NSString *> *)attributes {
if (_attributes) {
Expand Down Expand Up @@ -249,6 +253,10 @@ - (BOOL)isEqual:(id)object {
return isEqual;
}

- (NSUInteger)hash {
return self.action ^ [self.promotionsArray hash];
}

#pragma mark Private accessors
- (NSMutableArray *)promotionsArray {
if (_promotionsArray) {
Expand Down
4 changes: 4 additions & 0 deletions mParticle-Apple-SDK/Ecommerce/MPTransactionAttributes.m
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ - (BOOL)isEqual:(id)object {
return [_attributes isEqualToDictionary:((MPTransactionAttributes *)object)->_attributes];
}

- (NSUInteger)hash {
return [self.attributes hash];
}

#pragma mark Private accessors
- (NSMutableDictionary *)attributes {
if (_attributes) {
Expand Down
4 changes: 4 additions & 0 deletions mParticle-Apple-SDK/Event/MPBaseEvent.m
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,10 @@ - (BOOL)isEqual:(MPEvent *)object {
return (self.type == object.type) && [self.customAttributes isEqualToDictionary:object.customAttributes];
}

- (NSUInteger)hash {
return self.type ^ [self.customAttributes hash];
}

#pragma mark NSCopying
- (id)copyWithZone:(NSZone *)zone {
MPBaseEvent *copyObject = [[[self class] allocWithZone:zone] init];
Expand Down
4 changes: 4 additions & 0 deletions mParticle-Apple-SDK/Event/MPEvent.m
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,10 @@ - (BOOL)isEqual:(MPEvent *)object {
return isEqual;
}

- (NSUInteger)hash {
return [self.name hash] ^ [self.duration hash] ^ [self.category hash];
}

#pragma mark NSCopying
- (id)copyWithZone:(NSZone *)zone {
MPEvent *copyObject = [super copyWithZone:zone];
Expand Down
4 changes: 4 additions & 0 deletions mParticle-Apple-SDK/Kits/MPAttributeProjection.m
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ - (BOOL)isEqual:(id)object {
return isEqual;
}

- (NSUInteger)hash {
return self.dataType ^ self.required;
}

#pragma mark NSSecureCoding
- (void)encodeWithCoder:(NSCoder *)coder {
[super encodeWithCoder:coder];
Expand Down
4 changes: 4 additions & 0 deletions mParticle-Apple-SDK/Kits/MPBaseProjection.m
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,10 @@ - (BOOL)isEqual:(id)object {
return isEqual;
}

- (NSUInteger)hash {
return [self.name hash] ^ [self.projectedName hash] ^ self.matchType ^ self.projectionType;
}

- (NSString *)description {
NSMutableString *description = [[NSMutableString alloc] init];

Expand Down
8 changes: 8 additions & 0 deletions mParticle-Apple-SDK/Kits/MPEventProjection.mm
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ - (BOOL)isEqual:(id)object {
return isEqual;
}

- (NSUInteger)hash {
return [self.attributeKey hash] ^ [self.attributeValues hash];
}

#pragma mark NSSecureCoding
- (void)encodeWithCoder:(NSCoder *)coder {
if (self.attributeKey) {
Expand Down Expand Up @@ -178,6 +182,10 @@ - (BOOL)isEqual:(id)object {
return isEqual;
}

- (NSUInteger)hash {
return [self.projectionMatches hash] ^ self.messageType ^ self.maxCustomParameters ^ self.appendAsIs ^ self.isDefault ^ [self.attributeProjections hash];
}

#pragma mark NSSecureCoding
- (void)encodeWithCoder:(NSCoder *)coder {
[super encodeWithCoder:coder];
Expand Down
4 changes: 4 additions & 0 deletions mParticle-Apple-SDK/Kits/MPKitConfiguration.mm
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,10 @@ - (BOOL)isEqual:(MPKitConfiguration *)object {
return [_configurationHash isEqualToNumber:object.configurationHash];
}

- (NSUInteger)hash {
return [self.configurationHash hash];
}

#pragma mark NSSecureCoding
- (void)encodeWithCoder:(NSCoder *)coder {
[coder encodeObject:self.configurationDictionary forKey:@"configurationDictionary"];
Expand Down