Mercurial > hg > Database > Alice
view src/main/java/alice/topology/manager/ParentManager.java @ 482:8227a2fd5a55 dispose
bug fix
author | sugi |
---|---|
date | Fri, 05 Dec 2014 17:22:33 +0900 |
parents | f644dc9e0589 |
children | 9a7dd7591ddc |
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 void decrementChild(String name) { list.get(position).decrement(); } private 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; } } }