Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.programmer > #36759

Re: How to parse an array?

From Martin Gregorie <martin@address-in-sig.invalid>
Newsgroups comp.lang.java.programmer
Subject Re: How to parse an array?
Date 2017-06-28 21:55 +0000
Organization A noiseless patient Spider
Message-ID <oj18lc$2eg$1@dont-email.me> (permalink)
References (7 earlier) <dc58b7e1-186b-472f-a088-f9b848481404@googlegroups.com> <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>

Show all headers | View raw


On Wed, 28 Jun 2017 13:02:38 -0700, Eric Douglas wrote:

> Now the problem is the fancy view.  I have a fancy sortable table which
> extends my simple table class, which adds search() methods which call
> lucene to check the cell values.  This currently puts the lucene row
> results into an ArrayList<Integer> where the keys are the view row
> indices and the values are the model row indices.
>
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.


-- 
martin@   | Martin Gregorie
gregorie. | Essex, UK
org       |

Back to comp.lang.java.programmer | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


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