You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by ro...@apache.org on 2017/10/18 23:25:06 UTC
[sling-org-apache-sling-resource-inventory] 09/33: SLING-3198 :
JSON Tree Rendering should do tree depth first tree traversal
This is an automated email from the ASF dual-hosted git repository.
rombert pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-resource-inventory.git
commit 55da4920bc35945a88dbef5c873fd3f38f0dce90
Author: Carsten Ziegeler <cz...@apache.org>
AuthorDate: Tue Oct 22 10:17:15 2013 +0000
SLING-3198 : JSON Tree Rendering should do tree depth first tree traversal
git-svn-id: https://svn.apache.org/repos/asf/sling/trunk@1534589 13f79535-47bb-0310-9956-ffa450edef68
---
.../resource/inventory/impl/ResourceTraversor.java | 36 +++-------------------
1 file changed, 4 insertions(+), 32 deletions(-)
diff --git a/src/main/java/org/apache/sling/resource/inventory/impl/ResourceTraversor.java b/src/main/java/org/apache/sling/resource/inventory/impl/ResourceTraversor.java
index b984cd6..ed2f161 100644
--- a/src/main/java/org/apache/sling/resource/inventory/impl/ResourceTraversor.java
+++ b/src/main/java/org/apache/sling/resource/inventory/impl/ResourceTraversor.java
@@ -18,7 +18,6 @@
package org.apache.sling.resource.inventory.impl;
import java.util.Iterator;
-import java.util.LinkedList;
import org.apache.sling.api.resource.Resource;
import org.apache.sling.commons.json.JSONException;
@@ -26,29 +25,13 @@ import org.apache.sling.commons.json.JSONObject;
public class ResourceTraversor {
- public static final class Entry {
- public final Resource resource;
- public final JSONObject json;
-
- public Entry(final Resource r, final JSONObject o) {
- this.resource = r;
- this.json = o;
- }
- }
-
private final JSONObject startObject;
- private LinkedList<Entry> currentQueue;
-
- private LinkedList<Entry> nextQueue;
-
private final Resource startResource;
public ResourceTraversor(final Resource resource)
throws JSONException {
this.startResource = resource;
- this.currentQueue = new LinkedList<Entry>();
- this.nextQueue = new LinkedList<Entry>();
this.startObject = this.adapt(resource);
}
@@ -58,7 +41,7 @@ public class ResourceTraversor {
* @throws JSONException
*/
public void collectResources() throws JSONException {
- collectChildren(startResource, this.startObject, 0);
+ collectChildren(startResource, this.startObject);
}
/**
@@ -67,25 +50,14 @@ public class ResourceTraversor {
* @throws JSONException
*/
private void collectChildren(final Resource resource,
- final JSONObject jsonObj,
- int currentLevel)
+ final JSONObject jsonObj)
throws JSONException {
final Iterator<Resource> children = resource.listChildren();
while (children.hasNext()) {
final Resource res = children.next();
final JSONObject json = collectResource(res, jsonObj);
- nextQueue.addLast(new Entry(res, json));
- }
-
- while (!currentQueue.isEmpty() || !nextQueue.isEmpty()) {
- if (currentQueue.isEmpty()) {
- currentLevel++;
- currentQueue = nextQueue;
- nextQueue = new LinkedList<Entry>();
- }
- final Entry nextResource = currentQueue.removeFirst();
- collectChildren(nextResource.resource, nextResource.json, currentLevel);
+ collectChildren(res, json);
}
}
@@ -96,7 +68,7 @@ public class ResourceTraversor {
* @param level The level where this resource is located.
* @throws JSONException
*/
- private JSONObject collectResource(Resource resource, final JSONObject parent)
+ private JSONObject collectResource(final Resource resource, final JSONObject parent)
throws JSONException {
final JSONObject o = adapt(resource);
parent.put(resource.getName(), o);
--
To stop receiving notification emails like this one, please contact
"commits@sling.apache.org" <co...@sling.apache.org>.