473,387 Members | 1,897 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

How to create tree from jar file contents stored as an array of strings

I want to create a hierarchical tree from the array of strings
obtained by extracting a jar file.I want to do this using Javascript.

For ex,
I am having the entries in the array as
com/asd/many/a.class
com/asd/many/b.class
com/asd/xyz/c.class
com/asd/d.class
com/asd/man/you/e.class

These are obtained by extracting any jar file.
I want to create the tree using this information.
Please send me the required algorithm or the source code as soon as
possible.

Thank You.
Mriganka.
Jul 23 '05 #1
2 1736
In article <82**************************@posting.google.com >,
mr*********@yahoo.co.in enlightened us with...

These are obtained by extracting any jar file.
I want to create the tree using this information.
Please send me the required algorithm or the source code as soon as
possible.


Please learn the difference between Java and Javascript.

Please pay me to do your work for you.
--
--
~kaeli~
Is it possible to be totally partial?
http://www.ipwebdesign.net/wildAtHeart
http://www.ipwebdesign.net/kaelisSpace

Jul 23 '05 #2
mr*********@yahoo.co.in (Mriganka) writes:
I want to create a hierarchical tree from the array of strings
obtained by extracting a jar file.I want to do this using Javascript. For ex,
I am having the entries in the array as
com/asd/many/a.class
com/asd/many/b.class
com/asd/xyz/c.class
com/asd/d.class
com/asd/man/you/e.class
Ok, format is simple. Do you expect to have only one root, or several?
If only "com" exists at the top level, you will get just a tree,
otherwise you get a forest.
These are obtained by extracting any jar file.
Whatever :)
I want to create the tree using this information.
Please send me the required algorithm or the source code as soon as
possible.


The algorithm is easy. Split each string at the slashes, and build
a tree structure dynamically. Each node is an array, where the integer
indexed elements are the leaves and non-integer indexed elements are
branches to other tree nodes.
---
function plant(seed) { // seed is an array of strings
var forest = new Array();
for (var i=0; i<seed.length;i++) {
var path = seed[i].split("/");
var node = forest;
for(var j=0; j<path.length-1;j++) { // follow path, ot build it
var branchName = path[j];
var childNode = node[branchName];
if (!childNode) {
childNode = node[branchName] = new Array();
}
node = childNode;
}
node[node.length] = path[path.length-1];
}
return forest;
}
---

Your example strings would generate a structure similar to this
object literal (except it uses arrays, not objects):
---
{com: {asd: { many: { "0": "a.class",
"1": "b.class" },
xyz: { "0" : "c.class" },
"0": "d.class",
man: { you: { "0" : "e.class" }}}}}
---

/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html>
'Faith without judgement merely degrades the spirit divine.'
Jul 23 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Joseph | last post by:
Hi, I'm having bit of questions on recursive pointer. I have following code that supports upto 8K files but when i do a file like 12K i get a segment fault. I Know it is in this line of code. ...
8
by: Eric Lilja | last post by:
Hello, I had what I thought was normal text-file and I needed to locate a string matching a certain pattern in that file and, if found, replace that string. I thought this would be simple but I had...
7
by: dog | last post by:
I've seen plenty of articles on this topic but none of them have been able to solve my problem. I am working with an Access 97 database on an NT4.0 machine, which has many Access reports. I...
29
by: yourmycaffiene | last post by:
Okay, this if my first post so go easy on me plus I've only been using C for a couple of weeks. I'm working on a program currently that requires me to read data from a .dat file into a 2d array and...
5
by: Michael Sperlle | last post by:
Is it possible? Bestcrypt can supposedly be set up on linux, but it seems to need changes to the kernel before it can be installed, and I have no intention of going through whatever hell that would...
23
by: sandy | last post by:
I need (okay, I want) to make a dynamic array of my class 'Directory', within my class Directory (Can you already smell disaster?) Each Directory can have subdirectories so I thought to put these...
7
by: theballz | last post by:
Hi, I am learning c programming and come across a problem i cant seem to solve. I have a file which i wish to parse and put certain lines (which do not contain a hash character) into an array...
9
by: loudking | last post by:
Dear all, I am writing a client-server application and the client should upload a file to the server, then the server should display the content of the file in stdout. Because I have to deal...
2
by: Bart Kastermans | last post by:
Summary: can't verify big O claim, how to properly time this? On Jun 15, 2:34 pm, "Terry Reedy" <tjre...@udel.eduwrote: Thanks for the idea. I would expect the separation to lead to somewhat...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.