这段代码啥意思,大伙帮忙看看!# JobHunting - 待字闺中
z*s
1 楼
noname 这个class 应该起个什么名字才符合它的功能
class NoName
6 {
7 children = new Hashtable()
8 name = ""
9
10 boolean hasChild(child: string)
11 {
12 return this.children.hasKey(child)
13 }
14
15 NoName addChild(child: string)
16 {
17 var childnode = new NoName()
18 childnode.name = child
19 this.children[child] = childnode
20 return childnode
21 }
22
23 NoName getNode(child: string)
24 {
25 if this.hasChild(child)
26 return this.children[child]
27 else
28 return this.addChild(child)
29 }
30
31 void addList(input: string)
32 {
33 var currentNode = this.getNode(input[0])
34 input = input.SubString(1, input.Length − 1)
35 if (input.Length < 1)
36 currentNode.getNode("")
37 else
38 currentNode.addList(input)
39 }
40
41 string scan()
42 {
43 if (this.children.Values.Length == 0)
44 return this.name
45 if (this.children.Values.Length == 1)
46 return this.name + this.children.Values[0].scan()
47
48 var temp = new Array()
49 foreach(child in this.children.Values)
50 temp.Add(child.scan())
51
52 return this.name + "{" + temp.Sorted().JoinArray(",") + "}"
53 }
54 }
55
56 var x = new NoName()
57 x.addList(’/home/user/foo’)
58 x.addList(’/home/user/bar’)
59 x.addList(’/home/user/baz/one’)
60 x.addList(’/home/user/baz/two’)
61
62 print x.scan()
class NoName
6 {
7 children = new Hashtable()
8 name = ""
9
10 boolean hasChild(child: string)
11 {
12 return this.children.hasKey(child)
13 }
14
15 NoName addChild(child: string)
16 {
17 var childnode = new NoName()
18 childnode.name = child
19 this.children[child] = childnode
20 return childnode
21 }
22
23 NoName getNode(child: string)
24 {
25 if this.hasChild(child)
26 return this.children[child]
27 else
28 return this.addChild(child)
29 }
30
31 void addList(input: string)
32 {
33 var currentNode = this.getNode(input[0])
34 input = input.SubString(1, input.Length − 1)
35 if (input.Length < 1)
36 currentNode.getNode("")
37 else
38 currentNode.addList(input)
39 }
40
41 string scan()
42 {
43 if (this.children.Values.Length == 0)
44 return this.name
45 if (this.children.Values.Length == 1)
46 return this.name + this.children.Values[0].scan()
47
48 var temp = new Array()
49 foreach(child in this.children.Values)
50 temp.Add(child.scan())
51
52 return this.name + "{" + temp.Sorted().JoinArray(",") + "}"
53 }
54 }
55
56 var x = new NoName()
57 x.addList(’/home/user/foo’)
58 x.addList(’/home/user/bar’)
59 x.addList(’/home/user/baz/one’)
60 x.addList(’/home/user/baz/two’)
61
62 print x.scan()