1 | "use strict";
|
2 | var __importDefault = (this && this.__importDefault) || function (mod) {
|
3 | return (mod && mod.__esModule) ? mod : { "default": mod };
|
4 | };
|
5 | Object.defineProperty(exports, "__esModule", { value: true });
|
6 |
|
7 | const ObjectUtils_1 = __importDefault(require("./java/ObjectUtils"));
|
8 | const ComposedModel_1 = __importDefault(require("./models/ComposedModel"));
|
9 | class InheritanceTreeSorter {
|
10 | constructor(__parent, definitions) {
|
11 | this.definitions = definitions;
|
12 | this.__parent = __parent;
|
13 | }
|
14 | compare(o1, o2) {
|
15 | const model1 = this.definitions.get(o1);
|
16 | const model2 = this.definitions.get(o2);
|
17 | const model1InheritanceDepth = this.getInheritanceDepth(model1);
|
18 | const model2InheritanceDepth = this.getInheritanceDepth(model2);
|
19 | if (model1InheritanceDepth === model2InheritanceDepth) {
|
20 | const cmp = ObjectUtils_1.default.compare(this.__parent.config.toModelName(o1), this.__parent.config.toModelName(o2));
|
21 | if (cmp === -1) {
|
22 | return -1;
|
23 | }
|
24 | if (cmp === 1) {
|
25 | return 1;
|
26 | }
|
27 | if (cmp === true) {
|
28 | return -1;
|
29 | }
|
30 | if (cmp === false) {
|
31 | return 1;
|
32 | }
|
33 | return cmp;
|
34 | }
|
35 | else if (model1InheritanceDepth > model2InheritanceDepth) {
|
36 | return 1;
|
37 | }
|
38 | else {
|
39 | return -1;
|
40 | }
|
41 | }
|
42 | getInheritanceDepth(model) {
|
43 | let inheritanceDepth = 0;
|
44 | let parent = this.getParent(model);
|
45 | while (parent != null) {
|
46 | inheritanceDepth++;
|
47 | parent = this.getParent(parent);
|
48 | }
|
49 | return inheritanceDepth;
|
50 | }
|
51 | getParent(model) {
|
52 | if (model != null && model instanceof ComposedModel_1.default) {
|
53 | const parent = model.getParent();
|
54 | if (parent != null) {
|
55 | return this.definitions.get(parent.getReference());
|
56 | }
|
57 | }
|
58 | return null;
|
59 | }
|
60 | }
|
61 | exports.InheritanceTreeSorter = InheritanceTreeSorter;
|
62 |
|
\ | No newline at end of file |