Remove website, now in yukkurigames.com repository.
[enjoyable.git] / Classes / NJInputPathElement.m
1 //
2 // NJInputPathElement.m
3 // Enjoyable
4 //
5 // Created by Joe Wreschnig on 3/13/13.
6 //
7 //
8
9 #include "NJInputPathElement.h"
10
11 @implementation NJInputPathElement {
12 NSString *_eid;
13 }
14
15 - (id)initWithName:(NSString *)name
16 eid:(NSString *)eid
17 parent:(NJInputPathElement *)parent {
18 if ((self = [super init])) {
19 self.name = name;
20 self.parent = parent;
21 _eid = eid;
22 }
23 return self;
24 }
25
26 - (BOOL)isEqual:(id)object {
27 return [object isKindOfClass:NJInputPathElement.class]
28 && [[object uid] isEqualToString:self.uid];
29 }
30
31 - (NSUInteger)hash {
32 return self.uid.hash;
33 }
34
35 - (NSString *)uid {
36 return [NSString stringWithFormat:@"%@~%@", _parent.uid, _eid];
37 }
38
39 - (NJInputPathElement *)elementForUID:(NSString *)uid {
40 if ([uid isEqualToString:self.uid])
41 return self;
42 else if (![uid hasPrefix:self.uid])
43 return nil;
44 else {
45 for (NJInputPathElement *elem in self.children) {
46 NJInputPathElement *ret = [elem elementForUID:uid];
47 if (ret)
48 return ret;
49 }
50 }
51 return nil;
52 }
53
54 @end