SunQuest
           Java Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming LanguagesJava Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
Generate data entry and reporting .NET Web apps in minutes, straight from your database. Read our FREE whitepaper “Build Web 2.0 Applications Without Hand-Coding” Download now!
  #1  
Old August 18th, 2002, 03:27 AM
huikuan huikuan is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2002
Posts: 1 huikuan User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Wink sorting of data from a file

Hi

I have an external text file with some data. I manage to extract the data out and each piece of data consist of many fields. Before displaying the data on a JSP page, I need to sort all the data by a particular field.
What I have done is actually put all the data into a 2D array and sort them.

But because there are too much data, the processing and computation take very long.
Does anybody have a better idea or solution to go around this?

Thanks....

Reply With Quote
  #2  
Old September 2nd, 2002, 02:55 AM
bricker42 bricker42 is offline
Moderator =(8^(|)
Dev Shed Intermediate (1500 - 1999 posts)
 
Join Date: Feb 2002
Location: Sacramento, CA
Posts: 1,710 bricker42 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 20 m 38 sec
Reputation Power: 8
Send a message via AIM to bricker42
Use a database? Maybe you could provide a text file that is pre-sorted? This doesn't sound like something you're going to be wanting to do every time you view the page.

Reply With Quote
  #3  
Old September 7th, 2002, 04:37 AM
jnicholas jnicholas is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2001
Posts: 5 jnicholas User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Since you're in java, another thing you can do is have a servlet that loads the text file, sorts it and keeps it in an object that your other page uses. Depending on how the data is updated the serlvet could reload the text file every hour, or check time of last change or whatever. Since servlets stay in memory they can have data that lasts between requests.

Reply With Quote
  #4  
Old September 14th, 2002, 09:42 PM
aegcp aegcp is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2002
Posts: 1 aegcp User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
hhmmm... what I do is the following:

1o.) I have a vector of objects (these objects are javaBeans). Every object has many fields (price,name, you name it).

2o.) now, you can put this vector in a session (in my case the vector is not too big, so I don't have performance issues).

3o. ) now, my javabeans implement the comparable interface, something like this:

public class Employee implements Comparable { public static final Comparator SOC_SEC_ORDER = new Comparator( ) { public int compare(Object o1, Object o2) { Employee emp1 = (Employee)o1; Employee emp2 = (Employee)o2; return emp1.getSocSecNum( ).compareTo(emp2. getSocSecNum( )Here; } }; public static final Comparator NAME_ORDER = new Comparator( ) { public int compare(Object o1, Object o2) { Employee emp1 = (Employee)o1; Employee emp2 = (Employee)o2; return emp1.getName( ).compareTo(emp2. getName( ) Here; } };}

4o.) now, the only thing you do to order is.

Collections.sort(myVector,SOC_SEC_ORDER)

and that's it. Remember, your beans must be serializable so you don't have memory problems..

hope it helps
andres

Reply With Quote
  #5  
Old September 14th, 2002, 09:44 PM
aegcp aegcp is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2002
Posts: 1 aegcp User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
ooppss.. screwed up my code. sorry.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesJava Help > sorting of data from a file


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway