-
Notifications
You must be signed in to change notification settings - Fork 5
/
PathHead.js
61 lines (47 loc) · 1.45 KB
/
PathHead.js
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
var Class = require('../ext/Class');
var Path = require('./Path');
var ObjectUtils = require('../util/ObjectUtils');
/**
* A path head combines a path with a direction it is facing.
* It is used to denote the set of outgoing or incoming facets.
*/
var PathHead = Class.create({
initialize: function(path, isInverse) {
this.path = path;
this._isInverse = !!isInverse; // ensure boolean
},
getPath: function() {
return this.path;
},
equals: function(that) {
var result =
this === that ||
(this._isInverse === that._isInverse && (
ObjectUtils.isEqual(this.path, that.path)));
return result;
},
hashCode: function() {
if(this.hash == null) {
this.hash = (this._isInverse ? 3 : 7) * this.path.hashCode();
}
return this.hash;
},
isInverse: function() {
return this._isInverse;
},
toString: function() {
return '' + this.path + (this._isInverse ? ' (inverse)' : '');
},
up: function(_isInverse) {
var newPath = this.path.slice(0, -1);
_isInverse = _isInverse == null ? this._isInverse : _isInverse;
var result = new PathHead(newPath, _isInverse);
return result;
}
});
PathHead.parse = function(pathStr, isInverse) {
var path = Path.parse(pathStr);
var result = new PathHead(path, !!isInverse);
return result;
};
module.exports = PathHead;