Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 82 lines (71 sloc) 1.95 kb
d9ec7e3 Jacob Committing the new version!
authored
1 using System;
2 using System.Collections.Generic;
3 using System.Linq;
4 using System.Text;
5
6 namespace TaoEngine
7 {
8 public class Node
9 {
10 private string fragment;
11 private bool isDynamic;
12 private Node parent;
13 private Dictionary<String, Node> children = new Dictionary<string, Node>();
14
15 public Dictionary<String, Node> Children
16 {
17 get { return children; }
18 set { children = value; }
19 }
20
21 public Node(String fragment, Boolean isDynamic)
22 {
23 this.fragment = fragment;
24 this.isDynamic = isDynamic;
25 }
26
27 public void addChild(Node child)
28 {
29 children.Add(child.fragment, child);
30 }
31
32 public void addParent(Node parent)
33 {
34 this.parent = parent;
35 }
36
37 public Boolean hasChild(String fragment)
38 {
39 Node var;
40 if (children.TryGetValue(fragment, out var))
41 {
42 return true;
43 }
44 return false;
45 }
46
47 public String buildRoute()
48 {
49 String path = "/" + fragment;
50 Node p = parent;
51 while ((p != null) && (p.fragment != "/"))
52 {
53 path = "/" + p.fragment + path;
54 p = p.parent;
55 }
56 if (path == "//") { return null; }
57 return path;
58 }
59
60 public Boolean hasNoChildren()
61 {
62 return children.Count == 0;
63 }
64
65 public Boolean hasNoDynamicChildren()
66 {
67 return children.Values.Where(x => x.isDynamic == true).ToArray().Length == 0;
68 }
69
70 public IEnumerable<Node> iterDynamicChildren()
71 {
72 foreach (Node node in children.Values)
73 {
74 if (node.isDynamic)
75 {
76 yield return node;
77 }
78 }
79 }
80 }
81 }
Something went wrong with that request. Please try again.