-
Notifications
You must be signed in to change notification settings - Fork 89
/
Copy pathHWItem.m
60 lines (46 loc) · 1.5 KB
/
HWItem.m
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
//
// HWItem.m
// vmx
//
// Created by Boris Remizov on 24/08/16.
// Copyright © 2016 Veertu Labs Ltd. All rights reserved.
//
#import "HWItem.h"
@interface HWItem()
/// \brief Limit of connection capability of the the item.
/// It's assumed all items are organized into tree hierarchy, when certain
/// item could have some connected (clients) items, also the item could be
/// connected to provider by itself. Root item is not connected to any providers.
@property (nonatomic, strong, readonly) NSNumber* maxClients;
@end
@implementation HWItem
static NSUInteger sId = 0;
- (instancetype)initFromDictionary:(NSDictionary *)dict {
self = [super initFromDictionary:dict];
if (!self)
return nil;
// import mode
if (nil == self.id) {
self.id = @(sId++);
}
// NSAssert(self.id, @"Serialized HWItem instance should have id assigned");
if (nil == self.id) {
// bad bad bad - serialized item should have identifier assigned
self.id = @0;
}
return self;
}
- (NSUInteger)hash {
return [self.id hash];
}
- (BOOL)isEqual:(id)object {
// equal could be only objects of same type
if (![[object className] isEqual: [self className]])
return FALSE;
NSAssert(self.id && [(HWItem*)object id], @"All HWItem objects must have non-empty identifiers");
return [self.id isEqual: [(HWItem*)object id]];
}
- (NSUInteger)clientsLimit {
return self.maxClients ? [self.maxClients unsignedIntegerValue] : NSUIntegerMax;
}
@end