Lost Password?


Go Back   CodeCall Programming Forum > Software Development > Java Help

Java Help Java Help forum discussing all Java platforms - J2ME, J2SE and J2EE - as well as relevant standards, APIs and frameworks such as Swing, Servlets, JSPs, Applets, Struts, Spring, Hibernate, ANT, EJB, and other Java-related topics.

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 06-05-2007, 10:18 AM
Musashibo Musashibo is offline
Newbie
 
Join Date: Jun 2007
Location: Tsuchisaka
Posts: 1
Rep Power: 0
Musashibo is on a distinguished road
Smile [Query]TreeMap and TreeSet objects. How to use?

HI there.
My 1st post here, and already i've got a deal of questions to ask.

I believe all of u know how a typical index looks like in large or reference books. For eg. :

Acetone, 381
Acid rain, 95
Base-pairs, 1197
Dacron, 4, 856, 1245
Electron donors, 676
Elimination, 191, 215-217,227, 267

The index keys are sorted alphabetically and each key is followed by a list of page numbers.

Now I'm in the middle of making a program that will process a raw index file and generate an index.
The program will get arguments as two file names.
The first argument will stand for the name of an input raw index file and the second argument for the output index file.

The input raw index file will contain index entities in the following format:

Dacron ; 4
Acid rain ; 95
Elimination ; 191
Elimination ; 215
Elimination ; 216
Elimination ; 217
Elimination ; 227
Elimination ; 267
Acetone ; 381
Electron donors ; 676
Dacron ; 856
Base-pairs ; 1197
Dacron ; 1245

The program will process the raw index file and write to the output file the generated index as described above. For eg :
Elimination, 191, 215-217,227, 267

I'm using java.io package :

Code:
import java.io.*;
/**
* The program reads a raw index file and prints it to another file, 
* using a different format.
*/
public class IndexExample {
final static char DELIMITER = ';';
public static void main(String[] args) {
if (args.length != 2) {
System.out.println("Please supply two file names");
return;
}
try {
BufferedReader in = new BufferedReader(new
FileReader(args[0]));
PrintWriter out = new PrintWriter(new FileWriter(args[1]));
String line;
while ((line = in.readLine()) != null) {
int delimiterIndex = line.indexOf(DELIMITER);
if (delimiterIndex < 0) {
continue;
}
String argument1 = line.substring(0,delimiterIndex-1);
String argument2 = line.substring(delimiterIndex+1, line.length());
String key = (argument1).trim();
Integer pageNumber = new Integer(argument2.trim());
System.out.println("keyword = " + key + " ; page no. = " + pageNumber);
}
in.close();
out.close();
} catch (IOException e) {
/* dont bother the exception */
}
}
}
Now my question is : I'd like to try using TreeMap and TreeSet objects to represent the collection of index entries and page sets respectively. Is this achievable ?
I'm open to critics and suggestions. Feel free to give any input.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

Sponsored Links
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT -5. The time now is 11:41 PM.

Contest Stats

WingedPanther ........ 2753.6
Xav ........ 2704
Brandon W ........ 1702.32
John ........ 1207.73
marwex89 ........ 1175.24
morefood2001 ........ 966.05
dcs ........ 655.75
Steve.L ........ 475.59
orjan ........ 418.58
Aereshaa ........ 383.54

Contest Rules

CodeCall Goal

Goal: 100,000 Posts
Complete: 100%


Complete - Celebrate!

Ads