Mercurial > hg > Database > Alice
view src/main/java/alice/topology/manager/ParentManager.java @ 491:7d67bc538549 dispose
bug fix
author | sugi |
---|---|
date | Wed, 10 Dec 2014 20:31:09 +0900 |
parents | 9a7dd7591ddc |
children | f82f259ea93b |
line wrap: on
line source
package alice.topology.manager; import java.util.LinkedList; public class ParentManager { private int BINARY_TREE = 2; private int position = 0; private LinkedList<Parent> list; public ParentManager(){ list = new LinkedList<Parent>(); } 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() < BINARY_TREE) break; } } public void register(String name) { Parent p = new Parent(name); list.add(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.size();i++) { if (list.get(i).getName().equals(name)) { found = true; break; } } if (found) { return list.get(i); } else { return null; } } public void show() { int counter = 0; System.out.print("| "); for (Parent p :list) { if (counter==position) System.out.print("P "); System.out.print(p.getName()+" "+p.children()+" | "); counter++; } } }