• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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

 
Ranch Hand
Posts: 71
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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!!
 
Ranch Hand
Posts: 183
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Ranch Hand
Posts: 697
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
author and jackaroo
Posts: 12200
280
Mac IntelliJ IDE Firefox Browser Oracle C++ Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
reply
    Bookmark Topic Watch Topic
  • New Topic