KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > log4j > lf5 > viewer > categoryexplorer > CategoryPath


1 /*
2  * Copyright 1999-2005 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16 package org.apache.log4j.lf5.viewer.categoryexplorer;
17
18 import java.util.LinkedList JavaDoc;
19 import java.util.StringTokenizer JavaDoc;
20
21 /**
22  * CategoryPath is a collection of CategoryItems which represent a
23  * path of categories.
24  *
25  * @author Michael J. Sikorsky
26  * @author Robert Shaw
27  */

28
29 // Contributed by ThoughtWorks Inc.
30

31 public class CategoryPath {
32   //--------------------------------------------------------------------------
33
// Constants:
34
//--------------------------------------------------------------------------
35

36   //--------------------------------------------------------------------------
37
// Protected Variables:
38
//--------------------------------------------------------------------------
39
protected LinkedList JavaDoc _categoryElements = new LinkedList JavaDoc();
40
41   //--------------------------------------------------------------------------
42
// Private Variables:
43
//--------------------------------------------------------------------------
44

45   //--------------------------------------------------------------------------
46
// Constructors:
47
//--------------------------------------------------------------------------
48

49   public CategoryPath() {
50     super();
51   }
52
53   /**
54    * Construct a CategoryPath. If the category is null, it defaults to "Debug".
55    */

56   public CategoryPath(String JavaDoc category) {
57     String JavaDoc processedCategory = category;
58
59     if (processedCategory == null) {
60       processedCategory = "Debug";
61     }
62
63     processedCategory.replace('/', '.');
64     processedCategory = processedCategory.replace('\\', '.');
65
66     StringTokenizer JavaDoc st = new StringTokenizer JavaDoc(processedCategory, ".");
67     while (st.hasMoreTokens()) {
68       String JavaDoc element = st.nextToken();
69       addCategoryElement(new CategoryElement(element));
70     }
71   }
72
73   //--------------------------------------------------------------------------
74
// Public Methods:
75
//--------------------------------------------------------------------------
76

77   /**
78    * returns the number of CategoryElements.
79    */

80   public int size() {
81     int count = _categoryElements.size();
82
83     return (count);
84   }
85
86   public boolean isEmpty() {
87     boolean empty = false;
88
89     if (_categoryElements.size() == 0) {
90       empty = true;
91     }
92
93     return (empty);
94   }
95
96
97   /**
98    * Removes all categoryElements.
99    */

100   public void removeAllCategoryElements() {
101     _categoryElements.clear();
102   }
103
104   /**
105    * Adds the specified categoryElement to the end of the categoryElement set.
106    */

107   public void addCategoryElement(CategoryElement categoryElement) {
108     _categoryElements.addLast(categoryElement);
109   }
110
111   /**
112    * Returns the CategoryElement at the specified index.
113    */

114   public CategoryElement categoryElementAt(int index) {
115     return ((CategoryElement) _categoryElements.get(index));
116   }
117
118
119   public String JavaDoc toString() {
120     StringBuffer JavaDoc out = new StringBuffer JavaDoc(100);
121
122     out.append("\n");
123     out.append("===========================\n");
124     out.append("CategoryPath: \n");
125     out.append("---------------------------\n");
126
127     out.append("\nCategoryPath:\n\t");
128
129     if (this.size() > 0) {
130       for (int i = 0; i < this.size(); i++) {
131         out.append(this.categoryElementAt(i).toString());
132         out.append("\n\t");
133       }
134     } else {
135       out.append("<<NONE>>");
136     }
137
138     out.append("\n");
139     out.append("===========================\n");
140
141     return (out.toString());
142   }
143
144   //--------------------------------------------------------------------------
145
// Protected Methods:
146
//--------------------------------------------------------------------------
147

148   //--------------------------------------------------------------------------
149
// Private Methods:
150
//--------------------------------------------------------------------------
151

152   //--------------------------------------------------------------------------
153
// Nested Top-Level Classes or Interfaces:
154
//--------------------------------------------------------------------------
155

156 }
157
Popular Tags