Mercurial > hg > Database > Alice
view src/main/java/alice/topology/manager/ParentManager.java @ 655:1c93e82e05c6 default tip
fix timestamp
author | suruga |
---|---|
date | Sat, 17 Feb 2018 00:33:00 +0900 |
parents | 6732d03d0174 |
children |
line wrap: on
line source
package alice.topology.manager; import java.util.LinkedList; 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.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 Parent getLastNode(){ return list.getLast(); } 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++; } } public LinkedList<Parent> getList() { return list; } }