Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

NX: how to fill long[] results in findByCriteria()

 
Theo van Loon
Ranch Hand
Posts: 71
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello all,
just a question how you can best fill the long[] results in findByCriteria(String[] criteria).
I know how to search through the records looking for a match. But then i don't know how many records will be the result and what size the long[] results should be.
Could someone tell me how they've solved this problem?!
Thanx a lot!!
 
Mike Southgate
Ranch Hand
Posts: 183
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I used an ArrayList to hold the values and then copied into the [] at the end.
ms
 
Theo van Loon
Ranch Hand
Posts: 71
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
But if you find a recordNumber based on the first criterium you add it to your arrayList, you can only add Objects so how can you remove it if it doesn't match the second criterium?
 
Satish Avadhanam
Ranch Hand
Posts: 697
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I did this in a different way. Here's the approach. I find the matching for each field individually in seperate methods. In the findByCriteria method I did an intersection of all the records and returned.
Good Luck.
 
Theo van Loon
Ranch Hand
Posts: 71
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How do you do the intersection of all records then?
 
Satish Avadhanam
Ranch Hand
Posts: 697
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Theo van Loon:
How do you do the intersection of all records then?

Hi Theo, Each field find method returns an arraylist of record numbers. I send two arraylists at a time to a comapre method that returns the arraylist with the common record numbers in it. Here's an example:
nameList = findByName();
locList = findByLoc();
....
resultList = compareLists(nameList, locList);//returns common to both
resultList = compareLists(resultList, sizeList);//returns common to both
....
Finally resultList will have only the intersection of all the record numbers. It seeems that am using many methods here. But each method has only one line of code which again delegates to another method.
Hope this helps.
 
Theo van Loon
Ranch Hand
Posts: 71
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Satish,
i'm getting there... could you give me a clue how to compare Lists to eachother what methods to use?
Thanks a lot!!
 
Satish Avadhanam
Ranch Hand
Posts: 697
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Theo
Originally posted by Theo van Loon:
Hi Satish,
i'm getting there... could you give me a clue how to compare Lists to eachother what methods to use?
Thanks a lot!!


You can use "contains" if you want to test if a particular record is present in a list or not. Hope this helps.
 
Andrew Monkhouse
author and jackaroo
Marshal Commander
Pie
Posts: 12014
220
C++ Firefox Browser IntelliJ IDE Java Mac Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Theo,
Another alternative is to do your complete comparison before adding the record to any collection. That way you will only have one collection to convert into an array - no need for getting the combination of two arrays.
In psuedocode:

Of course there are good points and bad points about either way of doing this. You have to work out what they are and which one you want to use.
Oh yeah - after making a design decision: document it!
Regards, Andrew
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic