-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathNNSectionsDiffChange.m
More file actions
82 lines (63 loc) · 1.95 KB
/
Copy pathNNSectionsDiffChange.m
File metadata and controls
82 lines (63 loc) · 1.95 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
//
// NNSectionsDiffChange.m
// ArrayDiff
//
// Created by Nick Tymchenko on 14/04/14.
// Copyright (c) 2014 Nick Tymchenko. All rights reserved.
//
#import "NNSectionsDiffChange.h"
@implementation NNSectionsDiffChange
#pragma mark - Init
- (instancetype)init {
return [self initWithBefore:nil after:nil type:0];
}
- (instancetype)initWithBefore:(NSIndexPath *)before after:(NSIndexPath *)after type:(NNDiffChangeType)type {
NSParameterAssert(before != nil);
NSParameterAssert(after != nil);
NSParameterAssert(type != 0);
self = [super init];
if (!self) return nil;
_before = before;
_after = after;
_type = type;
return self;
}
#pragma mark - NSObject
- (BOOL)isEqual:(id)other {
if (other == self) return YES;
if (!other || ![other isKindOfClass:[NNSectionsDiffChange class]]) return NO;
return [self isEqualToSectionsDiffChange:other];
}
- (BOOL)isEqualToSectionsDiffChange:(NNSectionsDiffChange *)other {
if (![self.before isEqual:other.before]) return NO;
if (![self.after isEqual:other.after]) return NO;
if (self.type != other.type) return NO;
return YES;
}
- (NSUInteger)hash {
NSUInteger prime = 31;
NSUInteger result = 1;
result = prime * result + [self.before hash];
result = prime * result + [self.after hash];
result = prime * result + self.type;
return result;
}
- (NSString *)description {
NSString *typeString;
if (self.type == NNDiffChangeUpdate) {
typeString = @"·>";
} else if (self.type == NNDiffChangeMove) {
typeString = @"->";
} else {
typeString = @"=>";
}
return [NSString stringWithFormat:@"%@.%@ %@ %@.%@",
@([self.before indexAtPosition:0]), @([self.before indexAtPosition:1]),
typeString,
@([self.after indexAtPosition:0]), @([self.after indexAtPosition:1])];
}
#pragma mark - NSCopying
- (id)copyWithZone:(NSZone *)zone {
return self;
}
@end