Mercurial > hg > Database > Christie-sharp
view 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 (2022-01-26) |
parents | 0d2c956060d8 |
children | 1a42115e51bb |
line wrap: on
line source
using System; using System.Collections.Generic; using Christie_net.annotation; using Christie_net.codegear; using Christie_net.topology.manager; namespace Christie_net.topology.manager { public class ParentManager { private int maxChildren; private int position = 0; private LinkedList<Parent> list; public ParentManager(int hasChildren){ list = new LinkedList<Parent>(); maxChildren = hasChildren; } public String getMyParent() { checkChildNumber(); return list.get(position).getName(); } public int getMyNumber() { checkChildNumber(); int num = list.get(position).children(); list.get(position).increment(); return num; } private void checkChildNumber() { for (;;next()) { if (list.get(position).children() < maxChildren) break; } } public void register(String name) { Parent p = new Parent(name); list.AddLast(p); } public void next() { position++; } public void previous() { position--; } public void replaceAndRemove(String remove, String replace) { Parent removeNode = find(remove); Remove(replace); removeNode.setName(replace); } public void remove(String remove) { Parent removeNode = find(remove); list.Remove(removeNode); } public Parent find(String name) { Boolean found = false; int i = 0; for (;i<list.Count;i++) { if (list.get(i).getName().equals(name)) { found = true; break; } } if (found) { return list.get(i); } else { return null; } } public Parent getLastNode(){ return list.get(); } public void show() { int counter = 0; Console.WriteLine("| "); foreach (Parent p in list) { if (counter==position) Console.WriteLine("P "); Console.WriteLine(p.getName()+" "+p.children()+" | "); counter++; } } public LinkedList<Parent> getList() { return list; } } }