Mercurial > hg > Database > Christie
comparison src/main/java/christie/topology/manager/ParentManager.java @ 83:2314c55534ef
add TreeTopology
author | akahori |
---|---|
date | Sat, 15 Sep 2018 09:24:36 +0900 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
82:a02f44b709c0 | 83:2314c55534ef |
---|---|
1 package christie.topology.manager; | |
2 | |
3 import java.util.LinkedList; | |
4 | |
5 public class ParentManager { | |
6 | |
7 private int maxChildren; | |
8 private int position = 0; | |
9 private LinkedList<Parent> list; | |
10 public ParentManager(int hasChildren){ | |
11 list = new LinkedList<Parent>(); | |
12 maxChildren = hasChildren; | |
13 } | |
14 | |
15 public String getMyParent() { | |
16 checkChildNumber(); | |
17 return list.get(position).getName(); | |
18 } | |
19 | |
20 public int getMyNumber() { | |
21 checkChildNumber(); | |
22 int num = list.get(position).children(); | |
23 list.get(position).increment(); | |
24 return num; | |
25 } | |
26 | |
27 private void checkChildNumber() { | |
28 for (;;next()) { | |
29 if (list.get(position).children() < maxChildren) | |
30 break; | |
31 } | |
32 } | |
33 | |
34 public void register(String name) { | |
35 Parent p = new Parent(name); | |
36 list.add(p); | |
37 } | |
38 | |
39 public void next() { | |
40 position++; | |
41 } | |
42 | |
43 public void previous() { | |
44 position--; | |
45 } | |
46 | |
47 public void replaceAndRemove(String remove, String replace) { | |
48 Parent removeNode = find(remove); | |
49 remove(replace); | |
50 removeNode.setName(replace); | |
51 } | |
52 | |
53 public void remove(String remove) { | |
54 Parent removeNode = find(remove); | |
55 list.remove(removeNode); | |
56 } | |
57 | |
58 public Parent find(String name) { | |
59 boolean found = false; | |
60 int i = 0; | |
61 for (;i<list.size();i++) { | |
62 if (list.get(i).getName().equals(name)) { | |
63 found = true; | |
64 break; | |
65 } | |
66 } | |
67 if (found) { | |
68 return list.get(i); | |
69 } else { | |
70 return null; | |
71 } | |
72 } | |
73 | |
74 public Parent getLastNode(){ | |
75 return list.getLast(); | |
76 } | |
77 | |
78 public void show() { | |
79 int counter = 0; | |
80 System.out.print("| "); | |
81 for (Parent p :list) { | |
82 if (counter==position) | |
83 System.out.print("P "); | |
84 System.out.print(p.getName()+" "+p.children()+" | "); | |
85 counter++; | |
86 } | |
87 } | |
88 | |
89 public LinkedList<Parent> getList() { | |
90 return list; | |
91 } | |
92 } |