Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
AbstractTreeNode |
|
| 1.45;1,45 |
1 | package org.apache.maven.index.treeview; | |
2 | ||
3 | /* | |
4 | * Licensed to the Apache Software Foundation (ASF) under one | |
5 | * or more contributor license agreements. See the NOTICE file | |
6 | * distributed with this work for additional information | |
7 | * regarding copyright ownership. The ASF licenses this file | |
8 | * to you under the Apache License, Version 2.0 (the | |
9 | * "License"); you may not use this file except in compliance | |
10 | * with the License. You may obtain a copy of the License at | |
11 | * | |
12 | * http://www.apache.org/licenses/LICENSE-2.0 | |
13 | * | |
14 | * Unless required by applicable law or agreed to in writing, | |
15 | * software distributed under the License is distributed on an | |
16 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | |
17 | * KIND, either express or implied. See the License for the | |
18 | * specific language governing permissions and limitations | |
19 | * under the License. | |
20 | */ | |
21 | ||
22 | import java.io.IOException; | |
23 | import java.util.ArrayList; | |
24 | import java.util.List; | |
25 | ||
26 | /** | |
27 | * Base set of functionality for the TreeNode that all implementations will need. | |
28 | */ | |
29 | public abstract class AbstractTreeNode | |
30 | implements TreeNode | |
31 | { | |
32 | /** | |
33 | * The type of node. | |
34 | */ | |
35 | private String type; | |
36 | ||
37 | /** | |
38 | * Flag that determines if the node is a leaf. | |
39 | */ | |
40 | private boolean leaf; | |
41 | ||
42 | /** | |
43 | * The name of the node. | |
44 | */ | |
45 | private String nodeName; | |
46 | ||
47 | /** | |
48 | * The path of the node. | |
49 | */ | |
50 | private String path; | |
51 | ||
52 | /** | |
53 | * The children of this node. | |
54 | */ | |
55 | private List<TreeNode> children; | |
56 | ||
57 | /** | |
58 | * The group id of this node. | |
59 | */ | |
60 | private String groupId; | |
61 | ||
62 | /** | |
63 | * The artifact id of this node. | |
64 | */ | |
65 | private String artifactId; | |
66 | ||
67 | /** | |
68 | * The version of this node. | |
69 | */ | |
70 | private String version; | |
71 | ||
72 | /** | |
73 | * The repository id that this node is stored in. | |
74 | */ | |
75 | private String repositoryId; | |
76 | ||
77 | final private transient IndexTreeView treeView; | |
78 | ||
79 | final private transient TreeViewRequest request; | |
80 | ||
81 | /** | |
82 | * Constructor that takes an IndexTreeView implementation and a TreeNodeFactory implementation; | |
83 | * | |
84 | * @param tview | |
85 | * @param factory | |
86 | */ | |
87 | public AbstractTreeNode( IndexTreeView tview, TreeViewRequest request ) | |
88 | 259 | { |
89 | 259 | this.treeView = tview; |
90 | ||
91 | 259 | this.request = request; |
92 | 259 | } |
93 | ||
94 | /** | |
95 | * Get the type of node. | |
96 | * | |
97 | * @return Type | |
98 | */ | |
99 | public Type getType() | |
100 | { | |
101 | 0 | return Type.valueOf( type ); |
102 | } | |
103 | ||
104 | /** | |
105 | * Set the type of node. | |
106 | * | |
107 | * @param Type | |
108 | */ | |
109 | public void setType( Type type ) | |
110 | { | |
111 | 259 | this.type = type.name(); |
112 | 259 | } |
113 | ||
114 | /** | |
115 | * Get flag that determines if the node is a leaf. | |
116 | * | |
117 | * @return boolean | |
118 | */ | |
119 | public boolean isLeaf() | |
120 | { | |
121 | 774 | return leaf; |
122 | } | |
123 | ||
124 | /** | |
125 | * Set flag that determines if the node is a leaf. | |
126 | * | |
127 | * @param boolean | |
128 | */ | |
129 | public void setLeaf( boolean leaf ) | |
130 | { | |
131 | 259 | this.leaf = leaf; |
132 | 259 | } |
133 | ||
134 | /** | |
135 | * Get the name of the node. | |
136 | * | |
137 | * @return String | |
138 | */ | |
139 | public String getNodeName() | |
140 | { | |
141 | 5 | return nodeName; |
142 | } | |
143 | ||
144 | /** | |
145 | * Set the name of the node. | |
146 | * | |
147 | * @param String | |
148 | */ | |
149 | public void setNodeName( String nodeName ) | |
150 | { | |
151 | 259 | this.nodeName = nodeName; |
152 | 259 | } |
153 | ||
154 | /** | |
155 | * Get the path of the node. | |
156 | * | |
157 | * @return String | |
158 | */ | |
159 | public String getPath() | |
160 | { | |
161 | 285 | return path; |
162 | } | |
163 | ||
164 | /** | |
165 | * Set the path of the node. | |
166 | * | |
167 | * @param String | |
168 | */ | |
169 | public void setPath( String path ) | |
170 | { | |
171 | 259 | this.path = path; |
172 | 259 | } |
173 | ||
174 | /** | |
175 | * Get the group id of this node. | |
176 | * | |
177 | * @return String | |
178 | */ | |
179 | public String getGroupId() | |
180 | { | |
181 | 0 | return groupId; |
182 | } | |
183 | ||
184 | /** | |
185 | * Set the group id of this node. | |
186 | * | |
187 | * @param String | |
188 | */ | |
189 | public void setGroupId( String groupId ) | |
190 | { | |
191 | 170 | this.groupId = groupId; |
192 | 170 | } |
193 | ||
194 | /** | |
195 | * Get the artifact id of this node. | |
196 | * | |
197 | * @return String | |
198 | */ | |
199 | public String getArtifactId() | |
200 | { | |
201 | 0 | return artifactId; |
202 | } | |
203 | ||
204 | /** | |
205 | * Set the artifact id of this node. | |
206 | * | |
207 | * @param String | |
208 | */ | |
209 | public void setArtifactId( String artifactId ) | |
210 | { | |
211 | 170 | this.artifactId = artifactId; |
212 | 170 | } |
213 | ||
214 | /** | |
215 | * Get the version of this node. | |
216 | * | |
217 | * @return String | |
218 | */ | |
219 | public String getVersion() | |
220 | { | |
221 | 0 | return version; |
222 | } | |
223 | ||
224 | /** | |
225 | * Set the version of this node. | |
226 | * | |
227 | * @param String | |
228 | */ | |
229 | public void setVersion( String version ) | |
230 | { | |
231 | 134 | this.version = version; |
232 | 134 | } |
233 | ||
234 | /** | |
235 | * Get the repository id that this node is stored in. | |
236 | * | |
237 | * @return String | |
238 | */ | |
239 | public String getRepositoryId() | |
240 | { | |
241 | 0 | return repositoryId; |
242 | } | |
243 | ||
244 | /** | |
245 | * Set the repository id that this node is stored in. | |
246 | * | |
247 | * @param String | |
248 | */ | |
249 | public void setRepositoryId( String repositoryId ) | |
250 | { | |
251 | 259 | this.repositoryId = repositoryId; |
252 | 259 | } |
253 | ||
254 | /** | |
255 | * Get the children of this node. If this is a leaf node, null will be returned. This will NOT perform any actions | |
256 | * on the index to retrieve the children, will only return children that have already been loaded via the | |
257 | * listChildren method. | |
258 | * | |
259 | * @return List<TreeNode> | |
260 | */ | |
261 | public List<TreeNode> getChildren() | |
262 | { | |
263 | 417 | if ( children == null && !isLeaf() ) |
264 | { | |
265 | 170 | children = new ArrayList<TreeNode>(); |
266 | } | |
267 | ||
268 | 417 | return children; |
269 | } | |
270 | ||
271 | /** | |
272 | * Get the children of this node. If this is a leaf node, null will be returned. This will use the index to retrieve | |
273 | * the list of child nodes. | |
274 | * | |
275 | * @return List<TreeNode> | |
276 | */ | |
277 | public List<TreeNode> listChildren() | |
278 | throws IOException | |
279 | { | |
280 | 128 | if ( !isLeaf() && getChildren().isEmpty() && !isLeaf() ) |
281 | { | |
282 | 42 | children = |
283 | treeView.listNodes( | |
284 | new TreeViewRequest( request.getFactory(), getPath(), request.getFieldHints(), | |
285 | request.getArtifactInfoFilter(), request.getIndexingContext() ) ).getChildren(); | |
286 | } | |
287 | ||
288 | 128 | return children; |
289 | } | |
290 | ||
291 | /** | |
292 | * Find a TreeNode based upon a path and Type check. | |
293 | * | |
294 | * @return TreeNode | |
295 | */ | |
296 | public TreeNode findChildByPath( String path, Type type ) | |
297 | throws IOException | |
298 | { | |
299 | 30 | for ( TreeNode child : getChildren() ) |
300 | { | |
301 | 20 | if ( path.equals( child.getPath() ) && type.equals( child.getType() ) ) |
302 | { | |
303 | 0 | return child; |
304 | } | |
305 | } | |
306 | ||
307 | 30 | return null; |
308 | } | |
309 | } |