473,651 Members | 2,765 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 1758
In article <82************ **************@ posting.google. com>,
mr*********@yah oo.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*********@yah oo.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/rasterTriangleD OM.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
3529
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. How do i make the last pointer in the indirect sector that has another level of indirect pointer, and be defined recursively to support infinite large files? -code-
8
4031
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 problems getting my algorithm to work and in order to help me find the solution I decided to print each line to screen as I read them. Then, to my surprise, I noticed that there was a space between every character as I outputted the lines to the...
7
8849
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 want my users to be able to select a report, click on a command button on a form, which will then automatically create the report as a pdf file and save it to the user's machine. I am using Adobe Acrobat (5.0 I think) and have Adobe Distiller as a
29
10405
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 then print out the contents of the 2d array to the screen. I wil also need to append data to the .dat file but mostly right now I'm worrying about getting the info into the 2d array. My .dat file looks like this 1 20000 2 30000 3 40000
5
6765
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 cause. If I could create a large file that could be encrypted, and maybe add files to it by appending them and putting in some kind of delimiter between files, maybe a homemade version of truecrypt could be constructed. Any idea what it...
23
7395
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 in an array. The application compiles but aborts without giving me any useful information. What I suspect is happening is infinite recursion. Each Directory object creates an array of Subdirectories each of which has an array of...
7
3586
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 and then output the contents of this array. The file seems to be parsed properly and the array gets populated but when I output the array the last line of my text file has filled the array. Text file and code as follows, Text File
9
4211
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 with binary files, I cannot use character strings, so I chose integer array instead. But the problem is that how can I display them in stdout? I tried "%c"
2
2241
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 more code, but all the "checking the root" code would be separated out in the tree class. The node class would be very smooth. I'll try this when I have
0
8357
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8277
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8803
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8700
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8581
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6158
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5612
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
1910
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1588
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.