annotate topology/manager/ParentManager.cs @ 59:c4f8630b7822

topology manager fix
author KaitoMaeshiro <aosskaito@cr.ie.u-ryukyu.ac.jp>
date Thu, 27 Jan 2022 01:19:51 +0900
parents 0d2c956060d8
children 1a42115e51bb
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
58
0d2c956060d8 add topology manager
KaitoMaeshiro <aosskaito@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1 using System;
0d2c956060d8 add topology manager
KaitoMaeshiro <aosskaito@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
2 using System.Collections.Generic;
0d2c956060d8 add topology manager
KaitoMaeshiro <aosskaito@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
3 using Christie_net.annotation;
0d2c956060d8 add topology manager
KaitoMaeshiro <aosskaito@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
4 using Christie_net.codegear;
59
c4f8630b7822 topology manager fix
KaitoMaeshiro <aosskaito@cr.ie.u-ryukyu.ac.jp>
parents: 58
diff changeset
5 using Christie_net.topology.manager;
58
0d2c956060d8 add topology manager
KaitoMaeshiro <aosskaito@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
6
59
c4f8630b7822 topology manager fix
KaitoMaeshiro <aosskaito@cr.ie.u-ryukyu.ac.jp>
parents: 58
diff changeset
7 namespace Christie_net.topology.manager
58
0d2c956060d8 add topology manager
KaitoMaeshiro <aosskaito@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
8 {
0d2c956060d8 add topology manager
KaitoMaeshiro <aosskaito@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
9 public class ParentManager
0d2c956060d8 add topology manager
KaitoMaeshiro <aosskaito@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
10 {
0d2c956060d8 add topology manager
KaitoMaeshiro <aosskaito@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
11 private int maxChildren;
0d2c956060d8 add topology manager
KaitoMaeshiro <aosskaito@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
12 private int position = 0;
59
c4f8630b7822 topology manager fix
KaitoMaeshiro <aosskaito@cr.ie.u-ryukyu.ac.jp>
parents: 58
diff changeset
13 private LinkedList<Parent> list;
58
0d2c956060d8 add topology manager
KaitoMaeshiro <aosskaito@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
14 public ParentManager(int hasChildren){
59
c4f8630b7822 topology manager fix
KaitoMaeshiro <aosskaito@cr.ie.u-ryukyu.ac.jp>
parents: 58
diff changeset
15 list = new LinkedList<Parent>();
58
0d2c956060d8 add topology manager
KaitoMaeshiro <aosskaito@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
16 maxChildren = hasChildren;
0d2c956060d8 add topology manager
KaitoMaeshiro <aosskaito@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
17 }
0d2c956060d8 add topology manager
KaitoMaeshiro <aosskaito@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
18
0d2c956060d8 add topology manager
KaitoMaeshiro <aosskaito@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
19 public String getMyParent() {
0d2c956060d8 add topology manager
KaitoMaeshiro <aosskaito@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
20 checkChildNumber();
0d2c956060d8 add topology manager
KaitoMaeshiro <aosskaito@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
21 return list.get(position).getName();
0d2c956060d8 add topology manager
KaitoMaeshiro <aosskaito@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
22 }
0d2c956060d8 add topology manager
KaitoMaeshiro <aosskaito@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
23
0d2c956060d8 add topology manager
KaitoMaeshiro <aosskaito@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
24 public int getMyNumber() {
0d2c956060d8 add topology manager
KaitoMaeshiro <aosskaito@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
25 checkChildNumber();
0d2c956060d8 add topology manager
KaitoMaeshiro <aosskaito@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
26 int num = list.get(position).children();
0d2c956060d8 add topology manager
KaitoMaeshiro <aosskaito@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
27 list.get(position).increment();
0d2c956060d8 add topology manager
KaitoMaeshiro <aosskaito@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
28 return num;
0d2c956060d8 add topology manager
KaitoMaeshiro <aosskaito@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
29 }
0d2c956060d8 add topology manager
KaitoMaeshiro <aosskaito@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
30
0d2c956060d8 add topology manager
KaitoMaeshiro <aosskaito@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
31 private void checkChildNumber() {
0d2c956060d8 add topology manager
KaitoMaeshiro <aosskaito@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
32 for (;;next()) {
0d2c956060d8 add topology manager
KaitoMaeshiro <aosskaito@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
33 if (list.get(position).children() < maxChildren)
0d2c956060d8 add topology manager
KaitoMaeshiro <aosskaito@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
34 break;
0d2c956060d8 add topology manager
KaitoMaeshiro <aosskaito@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
35 }
0d2c956060d8 add topology manager
KaitoMaeshiro <aosskaito@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
36 }
0d2c956060d8 add topology manager
KaitoMaeshiro <aosskaito@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
37
0d2c956060d8 add topology manager
KaitoMaeshiro <aosskaito@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
38 public void register(String name) {
59
c4f8630b7822 topology manager fix
KaitoMaeshiro <aosskaito@cr.ie.u-ryukyu.ac.jp>
parents: 58
diff changeset
39 Parent p = new Parent(name);
58
0d2c956060d8 add topology manager
KaitoMaeshiro <aosskaito@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
40 list.AddLast(p);
0d2c956060d8 add topology manager
KaitoMaeshiro <aosskaito@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
41 }
0d2c956060d8 add topology manager
KaitoMaeshiro <aosskaito@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
42
0d2c956060d8 add topology manager
KaitoMaeshiro <aosskaito@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
43 public void next() {
0d2c956060d8 add topology manager
KaitoMaeshiro <aosskaito@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
44 position++;
0d2c956060d8 add topology manager
KaitoMaeshiro <aosskaito@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
45 }
0d2c956060d8 add topology manager
KaitoMaeshiro <aosskaito@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
46
0d2c956060d8 add topology manager
KaitoMaeshiro <aosskaito@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
47 public void previous() {
0d2c956060d8 add topology manager
KaitoMaeshiro <aosskaito@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
48 position--;
0d2c956060d8 add topology manager
KaitoMaeshiro <aosskaito@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
49 }
0d2c956060d8 add topology manager
KaitoMaeshiro <aosskaito@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
50
0d2c956060d8 add topology manager
KaitoMaeshiro <aosskaito@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
51 public void replaceAndRemove(String remove, String replace) {
59
c4f8630b7822 topology manager fix
KaitoMaeshiro <aosskaito@cr.ie.u-ryukyu.ac.jp>
parents: 58
diff changeset
52 Parent removeNode = find(remove);
58
0d2c956060d8 add topology manager
KaitoMaeshiro <aosskaito@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
53 Remove(replace);
0d2c956060d8 add topology manager
KaitoMaeshiro <aosskaito@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
54 removeNode.setName(replace);
0d2c956060d8 add topology manager
KaitoMaeshiro <aosskaito@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
55 }
0d2c956060d8 add topology manager
KaitoMaeshiro <aosskaito@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
56
0d2c956060d8 add topology manager
KaitoMaeshiro <aosskaito@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
57 public void remove(String remove) {
59
c4f8630b7822 topology manager fix
KaitoMaeshiro <aosskaito@cr.ie.u-ryukyu.ac.jp>
parents: 58
diff changeset
58 Parent removeNode = find(remove);
58
0d2c956060d8 add topology manager
KaitoMaeshiro <aosskaito@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
59 list.Remove(removeNode);
0d2c956060d8 add topology manager
KaitoMaeshiro <aosskaito@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
60 }
0d2c956060d8 add topology manager
KaitoMaeshiro <aosskaito@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
61
59
c4f8630b7822 topology manager fix
KaitoMaeshiro <aosskaito@cr.ie.u-ryukyu.ac.jp>
parents: 58
diff changeset
62 public Parent find(String name) {
58
0d2c956060d8 add topology manager
KaitoMaeshiro <aosskaito@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
63 Boolean found = false;
0d2c956060d8 add topology manager
KaitoMaeshiro <aosskaito@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
64 int i = 0;
0d2c956060d8 add topology manager
KaitoMaeshiro <aosskaito@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
65 for (;i<list.Count;i++) {
0d2c956060d8 add topology manager
KaitoMaeshiro <aosskaito@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
66 if (list.get(i).getName().equals(name)) {
0d2c956060d8 add topology manager
KaitoMaeshiro <aosskaito@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
67 found = true;
0d2c956060d8 add topology manager
KaitoMaeshiro <aosskaito@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
68 break;
0d2c956060d8 add topology manager
KaitoMaeshiro <aosskaito@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
69 }
0d2c956060d8 add topology manager
KaitoMaeshiro <aosskaito@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
70 }
0d2c956060d8 add topology manager
KaitoMaeshiro <aosskaito@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
71 if (found) {
0d2c956060d8 add topology manager
KaitoMaeshiro <aosskaito@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
72 return list.get(i);
0d2c956060d8 add topology manager
KaitoMaeshiro <aosskaito@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
73 } else {
0d2c956060d8 add topology manager
KaitoMaeshiro <aosskaito@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
74 return null;
0d2c956060d8 add topology manager
KaitoMaeshiro <aosskaito@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
75 }
0d2c956060d8 add topology manager
KaitoMaeshiro <aosskaito@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
76 }
0d2c956060d8 add topology manager
KaitoMaeshiro <aosskaito@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
77
59
c4f8630b7822 topology manager fix
KaitoMaeshiro <aosskaito@cr.ie.u-ryukyu.ac.jp>
parents: 58
diff changeset
78 public Parent getLastNode(){
58
0d2c956060d8 add topology manager
KaitoMaeshiro <aosskaito@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
79 return list.get();
0d2c956060d8 add topology manager
KaitoMaeshiro <aosskaito@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
80 }
0d2c956060d8 add topology manager
KaitoMaeshiro <aosskaito@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
81
0d2c956060d8 add topology manager
KaitoMaeshiro <aosskaito@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
82 public void show() {
0d2c956060d8 add topology manager
KaitoMaeshiro <aosskaito@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
83 int counter = 0;
0d2c956060d8 add topology manager
KaitoMaeshiro <aosskaito@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
84 Console.WriteLine("| ");
59
c4f8630b7822 topology manager fix
KaitoMaeshiro <aosskaito@cr.ie.u-ryukyu.ac.jp>
parents: 58
diff changeset
85 foreach (Parent p in list) {
58
0d2c956060d8 add topology manager
KaitoMaeshiro <aosskaito@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
86 if (counter==position)
0d2c956060d8 add topology manager
KaitoMaeshiro <aosskaito@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
87 Console.WriteLine("P ");
0d2c956060d8 add topology manager
KaitoMaeshiro <aosskaito@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
88 Console.WriteLine(p.getName()+" "+p.children()+" | ");
0d2c956060d8 add topology manager
KaitoMaeshiro <aosskaito@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
89 counter++;
0d2c956060d8 add topology manager
KaitoMaeshiro <aosskaito@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
90 }
0d2c956060d8 add topology manager
KaitoMaeshiro <aosskaito@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
91 }
0d2c956060d8 add topology manager
KaitoMaeshiro <aosskaito@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
92
59
c4f8630b7822 topology manager fix
KaitoMaeshiro <aosskaito@cr.ie.u-ryukyu.ac.jp>
parents: 58
diff changeset
93 public LinkedList<Parent> getList() {
58
0d2c956060d8 add topology manager
KaitoMaeshiro <aosskaito@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
94 return list;
0d2c956060d8 add topology manager
KaitoMaeshiro <aosskaito@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
95 }
0d2c956060d8 add topology manager
KaitoMaeshiro <aosskaito@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
96 }
0d2c956060d8 add topology manager
KaitoMaeshiro <aosskaito@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
97 }