/
Nodes.cs
executable file
·112 lines (98 loc) · 1.87 KB
/
Nodes.cs
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
using System;
using Microsoft.Ink;
using System.Collections;
using System.Drawing;
using System.Drawing.Drawing2D;
namespace GraphAnimator
{
public class Nodes
{
private ArrayList list;
public Nodes(){list = new ArrayList();}
public Nodes(int capacity) {list = new ArrayList(capacity);}
public Nodes(ArrayList list) {this.list = (ArrayList)list.Clone();}
public Node[] ToArray()
{
return (Node[])list.ToArray (typeof(Node));
}
public Nodes Clone()
{
return (Nodes) new Nodes(list);
}
public Node this[int index]
{
get
{
return (Node)list[index];
}
set
{
list[index] = value;
}
}
//Get the node corresponding to the given stroke in this collection
public Node getNode(Stroke s)
{
for(int i=0; i<list.Count; i++)
{
if(s.Id == ((Node)list[i]).Id)
return list[i] as Node;
}
return null;
}
//Get the nodes corresponding to the following strokes
public Nodes getNodes(Strokes strokes)
{
Nodes found = new Nodes();
for(int i=0; i<strokes.Count; i++)
{
Node a = getNode(strokes[i]);
if(a != null)
{
found.Add(a);
}
}
return found;
}
public void Add(Node n)
{
list.Add(n);
}
public void Clear()
{
list.Clear();
}
public void Remove(Node a)
{
list.Remove(a);
}
public void Remove(int id)
{
for(int i=0; i<list.Count; i++)
{
if(((Node)list[i]).Id == id)
{
list.Remove(list[i]);
}
}
}
public bool Contains(Node n)
{
for(int i=0; i<list.Count; i++)
{
if(((Node)list[i]).Equals(n))
return true;
}
return false;
}
public int Length()
{
return list.Count;
}
//Need to use "foreach" loop
public IEnumerator GetEnumerator()
{
return list.GetEnumerator();
}
}
}