Return-Path: X-Original-To: apmail-sling-commits-archive@www.apache.org Delivered-To: apmail-sling-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 2053410CC6 for ; Tue, 22 Oct 2013 10:17:39 +0000 (UTC) Received: (qmail 25986 invoked by uid 500); 22 Oct 2013 10:17:38 -0000 Delivered-To: apmail-sling-commits-archive@sling.apache.org Received: (qmail 25939 invoked by uid 500); 22 Oct 2013 10:17:37 -0000 Mailing-List: contact commits-help@sling.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@sling.apache.org Delivered-To: mailing list commits@sling.apache.org Received: (qmail 25925 invoked by uid 99); 22 Oct 2013 10:17:37 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 22 Oct 2013 10:17:37 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 22 Oct 2013 10:17:36 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id AE55B2388831; Tue, 22 Oct 2013 10:17:15 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1534589 - /sling/trunk/contrib/extensions/resource-inventory/src/main/java/org/apache/sling/resource/inventory/impl/ResourceTraversor.java Date: Tue, 22 Oct 2013 10:17:15 -0000 To: commits@sling.apache.org From: cziegeler@apache.org X-Mailer: svnmailer-1.0.9 Message-Id: <20131022101715.AE55B2388831@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: cziegeler Date: Tue Oct 22 10:17:15 2013 New Revision: 1534589 URL: http://svn.apache.org/r1534589 Log: SLING-3198 : JSON Tree Rendering should do tree depth first tree traversal Modified: sling/trunk/contrib/extensions/resource-inventory/src/main/java/org/apache/sling/resource/inventory/impl/ResourceTraversor.java Modified: sling/trunk/contrib/extensions/resource-inventory/src/main/java/org/apache/sling/resource/inventory/impl/ResourceTraversor.java URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/resource-inventory/src/main/java/org/apache/sling/resource/inventory/impl/ResourceTraversor.java?rev=1534589&r1=1534588&r2=1534589&view=diff ============================================================================== --- sling/trunk/contrib/extensions/resource-inventory/src/main/java/org/apache/sling/resource/inventory/impl/ResourceTraversor.java (original) +++ sling/trunk/contrib/extensions/resource-inventory/src/main/java/org/apache/sling/resource/inventory/impl/ResourceTraversor.java Tue Oct 22 10:17:15 2013 @@ -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.JSO 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 currentQueue; - - private LinkedList nextQueue; - private final Resource startResource; public ResourceTraversor(final Resource resource) throws JSONException { this.startResource = resource; - this.currentQueue = new LinkedList(); - this.nextQueue = new LinkedList(); 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 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(); - } - 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);