1 23 package com.sun.enterprise.diagnostics.report.html; 24 25 import com.sun.enterprise.diagnostics.Data; 26 import java.util.ArrayList ; 27 import java.util.Map ; 28 import java.util.HashMap ; 29 import java.util.Iterator ; 30 34 public class DataTraverser { 35 36 private Data dataObj; 37 38 42 private Map typeToData; 43 44 45 public DataTraverser(Data dataObj) { 46 this.dataObj = dataObj; 47 } 48 49 53 public Data getSource() { 54 return dataObj; 55 } 56 61 public Iterator <Data> getData(String type) { 62 if(typeToData == null) 63 traverse(); 64 65 Object obj = typeToData.get(type); 66 if(obj != null) { 67 ArrayList list = (ArrayList )obj; 68 return list.iterator(); 69 } 70 return new ArrayList ().iterator(); 71 } 72 73 private void traverse() { 74 if(typeToData == null) 75 typeToData = new HashMap (5); 76 Iterator <Data> children = dataObj.getChildren(); 77 while(children.hasNext()) { 78 Data child = children.next(); 79 ArrayList list = (ArrayList )typeToData.get(child.getType()); 80 if (list == null) { 81 list = new ArrayList (5); 82 typeToData.put(child.getType(), list); 83 } 84 list.add(child); 85 } 86 } 87 } 88 | Popular Tags |