Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > refined 2D design question

Reply
Thread Tools

refined 2D design question

 
 
Jeff
Guest
Posts: n/a
 
      12-21-2004
Last Friday, I posted a question about sorting two dimensional arrays which
evoked some great responses on the exact nature of two dimensional arrays in
Java. That discussion made me refine what I was trying to accomplish and
how. Now I'd like to get other opinions on my new approach.

Here's the problem. My input is data that has 4 fields: 1 String, 1 float,
2 ints. The input comes from various other classes - it's not in rows. The
String is the subject, the float and ints describe the subject. A separate
program eventually puts my output in a 2 dimensional Swing table. Up to 1000
rows can arrive as input, but I want to pass the presenting program only the
top 15 rows. The rows with the largest float values are selected for
presentation, thus the need to sort the input.

One other influence. I typically use Vectors of Vectors to implement my
Swing table model.

The best solution I can think of is to extend Vector to implement the
Comparable interface, creating a class called ComparableVector for each row.
In ComparableVector's compareTo() method, I'll compare the float value of
each row. Then I can use the Arrays.sort() method to perform the sort. A
Vector of ComparableVectors will provide the 2nd dimension.

Does someone see a better solution?

--
Jeff


 
Reply With Quote
 
 
 
 
Chris Smith
Guest
Posts: n/a
 
      12-27-2004
Jeff <> wrote:
> The best solution I can think of is to extend Vector to implement the
> Comparable interface, creating a class called ComparableVector for each row.
> In ComparableVector's compareTo() method, I'll compare the float value of
> each row. Then I can use the Arrays.sort() method to perform the sort. A
> Vector of ComparableVectors will provide the 2nd dimension.
>
> Does someone see a better solution?


Yes. You're entirely missing the concept of abstraction. You should
really have something like this:

public class MyDataRecord implements Comparable<MyDataRecord>
{
private String name;
private float value;
private int i1, i2;

...

public int compareTo(MyDataRecord other)
{
return Float.compare(value, other.value);
}
}

That use a Vector of those. You mentioned that the display of this data
in a Swing table is in another program, and there's nothing wrong with
using different data models for the same data in different programs.
However, if you would like to use a JTable to display the data in this
form, just define a subclass of AbstractTableModel to define a mapping
from a Vector<MyDataRecord> to the TableModel interface. You'll define
what field goes into what column by your implementation of getValueAt
(and probably getColumnName and getColumnClass as well).

--
www.designacourse.com
The Easiest Way To Train Anyone... Anywhere.

Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation
 
Reply With Quote
 
 
 
Reply

Thread Tools

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 Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Test plans and "refined test plans" DZantow Python 0 12-20-2011 06:24 PM
Still in while loop hell, Now with refined question! mmoski Java 7 09-18-2007 06:03 AM
Efficient creation of "refined" list<T>, from old list<T> janzon@gmail.com C++ 3 10-12-2006 06:36 PM
404 ripoff refined bonspiel@orcon.net.nz NZ Computing 12 03-02-2004 02:48 AM
LWP::Simple get() refined problem Hon Guin Lee - Web Producer - SMI Marketing Perl Misc 6 09-30-2003 03:40 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57