KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > de > qfs > apps > qflog > logview > NodeData


1 // {{{ copyright
2

3 /********************************************************************
4  *
5  * $Id: NodeData.java,v 1.8 2000/07/05 14:07:45 gs Exp $
6  *
7  * The contents of this file are subject to the Mozilla Public
8  * License Version 1.1 (the "License"); you may not use this file
9  * except in compliance with the License. You may obtain a copy of
10  * the License at http://www.mozilla.org/MPL/
11  *
12  * Software distributed under the License is distributed on an "AS
13  * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
14  * implied. See the License for the specific language governing
15  * rights and limitations under the License.
16  *
17  * The Original Code is qfs.de code.
18  *
19  * The Initial Developer of the Original Code is Gregor Schmid.
20  * Portions created by Gregor Schmid are
21  * Copyright (C) 1999 Quality First Software, Gregor Schmid.
22  * All Rights Reserved.
23  *
24  * Contributor(s):
25  *
26  *******************************************************************/

27
28 // }}}
29

30 package de.qfs.apps.qflog.logview;
31
32 // {{{ imports
33

34 import java.io.Serializable JavaDoc;
35
36 import java.text.Collator JavaDoc;
37
38 // }}}
39

40 /**
41  * Data structure that holds the class/package and method data for a {@link
42  * FilterNode FilterNode} as well as the node's level. <p>
43  */

44 public class NodeData implements Serializable JavaDoc
45 {
46     // {{{ variables
47

48     /**
49      * The UID used for serialization.
50      */

51     static final long serialVersionUID = -2093208988174456189L;
52
53     /**
54      * The class/package of the node.
55      */

56     private String JavaDoc clazz;
57
58     /**
59      * The method of the node (may be null).
60      */

61     private String JavaDoc method;
62
63     /**
64      * The level of the node (may be null).
65      */

66     private Integer JavaDoc level;
67
68     /**
69      * Collator used for string comparisons.
70      */

71     private static Collator JavaDoc coll = Collator.getInstance();
72
73     // }}}
74

75     // {{{ constructor
76

77     /**
78      * Create a new NodeData.
79      *
80      * @param clazz The class/package of the node.
81      * @param method The method of the node (may be null).
82      * @param level The level of the node (may be null).
83      */

84     public NodeData (String JavaDoc clazz, String JavaDoc method, Integer JavaDoc level)
85     {
86         this.clazz = clazz;
87         this.method = method;
88         this.level = level;
89     }
90
91     // }}}
92

93     // {{{ getClazz
94

95     /**
96      * Get the node's class/package.
97      *
98      * @return The class/package of the node.
99      */

100     public String JavaDoc getClazz ()
101     {
102         return clazz;
103     }
104
105     // }}}
106
// {{{ setClazz
107

108     /**
109      * Set the node's class/package.
110      *
111      * @return The class/package to set.
112      */

113     public void setClazz (String JavaDoc clazz)
114     {
115         this.clazz = clazz;
116     }
117
118     // }}}
119
// {{{ getMethod
120

121     /**
122      * Get the node's method.
123      *
124      * @return The method of the node.
125      */

126     public String JavaDoc getMethod ()
127     {
128         return method;
129     }
130
131     // }}}
132
// {{{ setMethod
133

134     /**
135      * Set the node's method.
136      *
137      * @return The method to set.
138      */

139     public void setMethod (String JavaDoc method)
140     {
141         this.method = method;
142     }
143
144     // }}}
145
// {{{ getLevel
146

147     /**
148      * Get the node's level.
149      *
150      * @return The level of the node.
151      */

152     public Integer JavaDoc getLevel ()
153     {
154         return level;
155     }
156
157     // }}}
158
// {{{ setLevel
159

160     /**
161      * Set the node's level.
162      *
163      * @return The level to set.
164      */

165     public void setLevel (Integer JavaDoc level)
166     {
167         this.level = level;
168     }
169
170     // }}}
171
// {{{ hashCode
172

173     /**
174      * Generate a hash code for the NodeData.
175      *
176      * @return The hash code.
177      */

178     public int hashCode()
179     {
180         return (clazz == null ? 0 : clazz.hashCode()) +
181             (method == null ? 0 : method.hashCode());
182     }
183
184     // }}}
185
// {{{ equals
186

187     /**
188      * Check whether the NodeData is equal to some object.
189      *
190      * @param o The object to compare to.
191      *
192      * @return True if the object is a NodeData and has equal clazz and method
193      * members.
194      */

195     public boolean equals(Object JavaDoc o)
196     {
197         if (! (o instanceof NodeData)) {
198             return false;
199         }
200         NodeData node = (NodeData) o;
201         return ((clazz == null && node.clazz == null)
202                 || (clazz != null && clazz.equals(node.clazz)))
203             && ((method == null && node.method == null)
204                 || (method != null && method.equals(node.method)));
205     }
206
207     // }}}
208
// {{{ compareTo
209

210    /**
211      * Compare the data to some other object.
212      *
213      * @param o The Object to compare to. Must be a NodeData.
214      *
215      * @return -1, 0 or 1 if the NodeData row is less than, equal to or
216      * greater than the object.
217      */

218     public int compareTo (Object JavaDoc o)
219     {
220         NodeData data = (NodeData) o;
221
222         // class nodes without package come after package nodes
223
boolean pkg1 = clazz.indexOf(".") >= 0;
224         boolean pkg2 = data.getClazz().indexOf(".") >= 0;
225         if (pkg1 != pkg2) {
226             return pkg1 ? -1 : 1;
227         }
228
229         int cl = coll.compare(clazz, data.getClazz());
230         if (cl != 0) {
231             return cl;
232         }
233         if (method == null) {
234             return data.getMethod() == null ? 0 : -1;
235         } else if (data.getMethod() == null) {
236             return 1;
237         }
238         return coll.compare(method, data.getMethod());
239     }
240
241     // }}}
242
}
243
Popular Tags