Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #36776
| Newsgroups | comp.lang.java.programmer |
|---|---|
| Date | 2017-06-30 06:10 -0700 |
| References | (8 earlier) <oiumi8$6om$1@dont-email.me> <47fa7e7a-7757-46b0-a6bb-5084529a50e2@googlegroups.com> <oj0uti$4q3$1@dont-email.me> <63f1b363-ad45-498c-857c-dd0dd9165e04@googlegroups.com> <oj18lc$2eg$1@dont-email.me> |
| Message-ID | <d38e7c4b-0ace-4373-a918-03bdf259fb2c@googlegroups.com> (permalink) |
| Subject | Re: How to parse an array? |
| From | Eric Douglas <e.d.programmer@gmail.com> |
On Wednesday, June 28, 2017 at 6:00:02 PM UTC-4, Martin Gregorie wrote:
> OK, thats the information I was missing and explains why using a custom
> class instead of an ArrayList to hold the row is a bad idea.
>
> > So if I change that to a tree type (TreeMap? TreeSet?) so it can
> > automatically sort itself
> >
> Here's a restatement of what I was suggesting. You'd leave the ArrayList
> of ArrayLists alone, exactly as Lucene returned them and never modify or
> recreate them unless/until Lucene replaces its content with new data.
>
> Instead, the TableModel would be based on a Collection that was sorted as
> the TreeMap it is derived from was being built. The Treemap's key fields
> are the contents of whatever column you want to sort on and its values
> are references to the ArrayList containing the corresponding row. Setting
> up the TreeMap would be something like:
>
> for (int i = 0; i < rowList.size(); i++)
> {
> ArrayList row = rowList.get(i);
> treemap.put(row.get(keyIndex), row);
> }
>
> Collection<ArrayList> sortedList = treeMap.values();
>
> and you'd use the Collection as the basis of your TableModel subclass
> rather than the ArrayList you currently use and which I've referred to as
> rowList.
>
> The effect is that the TreeMap should act as a self-sorting list. I think
> it would be faster than whatever sort is currently being used since
> building a TreeMap only looks at a subset of the keys already in it when
> adding a new item: I'd certainly expect it to be get relatively faster as
> the number of rows in the table increases.
>
> > and the values link the MyCustomRowData objects, then it's automatically
> > rebuilt to filter and sort as fast as possible.
> >
> Yes.
>
> > Now, I have a TreeMap where the indices are MyCustomRowData objects and
> > the values are the model indices?
> >
> The treemap keys are the values from the column you're sorting on and the
> values are references to the ArrayLists that form the rows.
>
> > How do I write the row sorter methods convertRowIndexToView,
> > convertRowIndexToModel when the tree classes have
> > no indexOf method?
> >
> If those methods really need to use a row index, i.e. can't easily be
> made to work on each row as forEach() returns it, then calling
> Collection.toArray() will return the collection as a sorted ArrayList[].
> But if it comes down to that the game would appear to be somewhat lost,
> unless it runs significantly faster than your current code.
>
Nice, I'm not sure I did exactly everything you were suggesting but it seems I get barely a 1 second delay now on clicking a column header to sort the table. That is on a full table, tested 74,707 rows, 24 columns, totaling 1,792,968 cells.
That is with the full sort processing, I can click one column to be ascending or descending, then a second column with duplicate values which remain sorted on the first column as secondary.
That is with full search capability. I have 2 JTextComponent controls with key listeners that update the table search, each linked to list buttons where I can select to search on any specific column or all columns. All cells indexed, with wildcards.
That includes mixed cell styles. Some cells are just text, some are masked numbers, some are masked dates, some are list buttons.
Back to comp.lang.java.programmer | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
How to parse an array? Eric Douglas <e.d.programmer@gmail.com> - 2017-06-20 12:18 -0700
Re: How to parse an array? Knute Johnson <nospam@rabbitbrush.frazmtn.com> - 2017-06-20 14:49 -0500
Re: How to parse an array? Arne Vajhøj <arne@vajhoej.dk> - 2017-06-20 16:15 -0400
Re: How to parse an array? Eric Sosman <esosman@comcast-dot-net.invalid> - 2017-06-20 16:23 -0400
Re: How to parse an array? Robert Klemme <shortcutter@googlemail.com> - 2017-06-24 12:02 +0200
Re: How to parse an array? Eric Douglas <e.d.programmer@gmail.com> - 2017-06-26 05:10 -0700
Re: How to parse an array? Eric Sosman <esosman@comcast-dot-net.invalid> - 2017-06-26 09:36 -0400
Re: How to parse an array? Eric Douglas <e.d.programmer@gmail.com> - 2017-06-26 07:47 -0700
Re: How to parse an array? Martin Gregorie <martin@address-in-sig.invalid> - 2017-06-26 15:47 +0000
Re: How to parse an array? Arne Vajhøj <arne@vajhoej.dk> - 2017-06-26 20:37 -0400
Re: How to parse an array? lewbloch@gmail.com - 2017-06-27 12:29 -0700
Re: How to parse an array? Eric Douglas <e.d.programmer@gmail.com> - 2017-06-27 12:50 -0700
Re: How to parse an array? Martin Gregorie <martin@address-in-sig.invalid> - 2017-06-27 20:05 +0000
Re: How to parse an array? Eric Douglas <e.d.programmer@gmail.com> - 2017-06-27 14:01 -0700
Re: How to parse an array? Martin Gregorie <martin@address-in-sig.invalid> - 2017-06-27 22:34 +0000
Re: How to parse an array? Eric Douglas <e.d.programmer@gmail.com> - 2017-06-28 05:10 -0700
Re: How to parse an array? Martin Gregorie <martin@address-in-sig.invalid> - 2017-06-28 19:09 +0000
Re: How to parse an array? Eric Douglas <e.d.programmer@gmail.com> - 2017-06-28 13:02 -0700
Re: How to parse an array? Martin Gregorie <martin@address-in-sig.invalid> - 2017-06-28 21:55 +0000
Re: How to parse an array? Eric Douglas <e.d.programmer@gmail.com> - 2017-06-30 06:10 -0700
Re: How to parse an array? Martin Gregorie <martin@address-in-sig.invalid> - 2017-06-30 16:52 +0000
Re: How to parse an array? Jerry Stuckle <jstucklex@attglobal.net> - 2017-06-24 16:34 -0400
Re: How to parse an array? Martin Gregorie <martin@address-in-sig.invalid> - 2017-06-24 22:42 +0000
Re: How to parse an array? Jerry Stuckle <jstucklex@attglobal.net> - 2017-06-24 20:05 -0400
Re: How to parse an array? Robert Klemme <shortcutter@googlemail.com> - 2017-06-25 12:20 +0200
csiph-web