1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.log4j.lf5.viewer.categoryexplorer;
18
19 import java.util.LinkedList;
20 import java.util.StringTokenizer;
21
22 /***
23 * CategoryPath is a collection of CategoryItems which represent a
24 * path of categories.
25 *
26 * @author Michael J. Sikorsky
27 * @author Robert Shaw
28 */
29
30
31
32 public class CategoryPath {
33
34
35
36
37
38
39
40 protected LinkedList _categoryElements = new LinkedList();
41
42
43
44
45
46
47
48
49
50 public CategoryPath() {
51 super();
52 }
53
54 /***
55 * Construct a CategoryPath. If the category is null, it defaults to "Debug".
56 */
57 public CategoryPath(String category) {
58 String processedCategory = category;
59
60 if (processedCategory == null) {
61 processedCategory = "Debug";
62 }
63
64 processedCategory.replace('/', '.');
65 processedCategory = processedCategory.replace('//', '.');
66
67 StringTokenizer st = new StringTokenizer(processedCategory, ".");
68 while (st.hasMoreTokens()) {
69 String element = st.nextToken();
70 addCategoryElement(new CategoryElement(element));
71 }
72 }
73
74
75
76
77
78 /***
79 * returns the number of CategoryElements.
80 */
81 public int size() {
82 int count = _categoryElements.size();
83
84 return (count);
85 }
86
87 public boolean isEmpty() {
88 boolean empty = false;
89
90 if (_categoryElements.size() == 0) {
91 empty = true;
92 }
93
94 return (empty);
95 }
96
97
98 /***
99 * Removes all categoryElements.
100 */
101 public void removeAllCategoryElements() {
102 _categoryElements.clear();
103 }
104
105 /***
106 * Adds the specified categoryElement to the end of the categoryElement set.
107 */
108 public void addCategoryElement(CategoryElement categoryElement) {
109 _categoryElements.addLast(categoryElement);
110 }
111
112 /***
113 * Returns the CategoryElement at the specified index.
114 */
115 public CategoryElement categoryElementAt(int index) {
116 return ((CategoryElement) _categoryElements.get(index));
117 }
118
119
120 public String toString() {
121 StringBuffer out = new StringBuffer(100);
122
123 out.append("\n");
124 out.append("===========================\n");
125 out.append("CategoryPath: \n");
126 out.append("---------------------------\n");
127
128 out.append("\nCategoryPath:\n\t");
129
130 if (this.size() > 0) {
131 for (int i = 0; i < this.size(); i++) {
132 out.append(this.categoryElementAt(i).toString());
133 out.append("\n\t");
134 }
135 } else {
136 out.append("<<NONE>>");
137 }
138
139 out.append("\n");
140 out.append("===========================\n");
141
142 return (out.toString());
143 }
144
145
146
147
148
149
150
151
152
153
154
155
156
157 }