annotate topology/manager/ParentManager.cs @ 58:0d2c956060d8

add topology manager
author KaitoMaeshiro <aosskaito@cr.ie.u-ryukyu.ac.jp>
date Tue, 25 Jan 2022 22:35:25 +0900
parents
children c4f8630b7822
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;
0d2c956060d8 add topology manager
KaitoMaeshiro <aosskaito@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
5 using Christie_net.topology;
0d2c956060d8 add topology manager
KaitoMaeshiro <aosskaito@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
6
0d2c956060d8 add topology manager
KaitoMaeshiro <aosskaito@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
7 namespace Christie_net.topology.manager.ParentManager
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;
0d2c956060d8 add topology manager
KaitoMaeshiro <aosskaito@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
13 private LinkedList<Parent.Parent> list;
0d2c956060d8 add topology manager
KaitoMaeshiro <aosskaito@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
14 public ParentManager(int hasChildren){
0d2c956060d8 add topology manager
KaitoMaeshiro <aosskaito@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
15 list = new LinkedList<Parent.Parent>();
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) {
0d2c956060d8 add topology manager
KaitoMaeshiro <aosskaito@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
39 Parent.Parent p = new Parent.Parent(name);
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) {
0d2c956060d8 add topology manager
KaitoMaeshiro <aosskaito@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
52 Parent.Parent removeNode = find(remove);
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) {
0d2c956060d8 add topology manager
KaitoMaeshiro <aosskaito@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
58 Parent.Parent removeNode = find(remove);
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
0d2c956060d8 add topology manager
KaitoMaeshiro <aosskaito@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
62 public Parent.Parent find(String name) {
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
0d2c956060d8 add topology manager
KaitoMaeshiro <aosskaito@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
78 public Parent.Parent getLastNode(){
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("| ");
0d2c956060d8 add topology manager
KaitoMaeshiro <aosskaito@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
85 foreach (Parent.Parent p in list) {
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
0d2c956060d8 add topology manager
KaitoMaeshiro <aosskaito@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
93 public LinkedList<Parent.Parent> getList() {
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 }