Refactoring of WANavigation and i,plementation of Service Status
This commit is contained in:
parent
e201f9ce4c
commit
b115a9cb4f
14 changed files with 101 additions and 91 deletions
|
|
@ -27,46 +27,49 @@ import java.util.*;
|
|||
/**
|
||||
* Created by Ziver on 2015-04-02.
|
||||
*/
|
||||
public class WANavigation {
|
||||
private static int nextId;
|
||||
private static List<WANavigation> root_nav = new ArrayList<WANavigation>();
|
||||
private static HashMap<Integer, WANavigation> nav_map = new HashMap<Integer, WANavigation>();
|
||||
public class WANavigation implements Iterable{
|
||||
private static int nextId = 0;
|
||||
private static HashMap<Integer, WANavigation> navMap = new HashMap<Integer, WANavigation>();
|
||||
private static WANavigation rootNav = new WANavigation(null);
|
||||
|
||||
private int id;
|
||||
private String url;
|
||||
private String name;
|
||||
private ArrayList<WANavigation> sub_navs;
|
||||
private ArrayList<WANavigation> subNav;
|
||||
|
||||
private WANavigation parent_nav;
|
||||
private WANavigation parentNav;
|
||||
private Object resource;
|
||||
|
||||
|
||||
public WANavigation(String name) {
|
||||
private WANavigation(String name) {
|
||||
this.id = nextId++;
|
||||
this.nav_map.put(this.id, this);
|
||||
this.navMap.put(this.id, this);
|
||||
this.url = "?i="+this.id;
|
||||
this.name = name;
|
||||
this.sub_navs = new ArrayList<>();
|
||||
}
|
||||
public WANavigation(String name, Object resource) {
|
||||
this(name);
|
||||
this.setResource(resource);
|
||||
this.subNav = new ArrayList<>();
|
||||
}
|
||||
|
||||
|
||||
public void addSubNav(WANavigation subNav) {
|
||||
this.sub_navs.add(subNav);
|
||||
@Override
|
||||
public Iterator iterator() {
|
||||
return subNav.iterator();
|
||||
}
|
||||
public List<WANavigation> getSubNavs() {
|
||||
return subNav;
|
||||
}
|
||||
public WANavigation getSubNav(String name) {
|
||||
for(WANavigation nav : subNav) {
|
||||
if(nav.equals(name))
|
||||
return nav;
|
||||
}
|
||||
WANavigation nav = new WANavigation(name);
|
||||
this.addSubNav(nav);
|
||||
return nav;
|
||||
}
|
||||
private void addSubNav(WANavigation subNav) {
|
||||
this.subNav.add(subNav);
|
||||
subNav.setParentNav(this );
|
||||
}
|
||||
public List<WANavigation> getSubNav() {
|
||||
return sub_navs;
|
||||
}
|
||||
public Object getSubNav(String name) {
|
||||
int index = sub_navs.indexOf(name);
|
||||
if(index >= 0)
|
||||
return sub_navs.get(index);
|
||||
return null;
|
||||
}
|
||||
|
||||
public String getName(){
|
||||
return name;
|
||||
|
|
@ -79,9 +82,10 @@ public class WANavigation {
|
|||
}
|
||||
|
||||
private void setParentNav(WANavigation nav){
|
||||
this.parent_nav = nav;
|
||||
this.parentNav = nav;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o){
|
||||
if(o instanceof String)
|
||||
return this.name.equals(o);
|
||||
|
|
@ -90,27 +94,20 @@ public class WANavigation {
|
|||
}
|
||||
|
||||
|
||||
public static void addRootNav(WANavigation nav){
|
||||
getRootNav().add(nav);
|
||||
}
|
||||
public static List<WANavigation> getRootNav(){
|
||||
return root_nav;
|
||||
return rootNav.getSubNavs();
|
||||
}
|
||||
public static WANavigation getRootNav(String name){
|
||||
for(WANavigation nav : root_nav){
|
||||
if(nav.getName().equals(name))
|
||||
return nav;
|
||||
}
|
||||
return null;
|
||||
return rootNav.getSubNav(name);
|
||||
}
|
||||
|
||||
public static List<WANavigation> getNavResource(Map<String, String> request) {
|
||||
public static List<WANavigation> getNavBreadcrumb(Map<String, String> request) {
|
||||
LinkedList list = new LinkedList();
|
||||
if(request.containsKey("i")){
|
||||
WANavigation current = nav_map.get(Integer.parseInt(request.get("i")));
|
||||
while(current != null){
|
||||
WANavigation current = navMap.get(Integer.parseInt(request.get("i")));
|
||||
while(current != null && current != rootNav){
|
||||
list.addFirst(current);
|
||||
current = current.parent_nav;
|
||||
current = current.parentNav;
|
||||
}
|
||||
}
|
||||
return list;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue