• 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
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

return DataInfo[]

 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I have a problem in returning the DataInfo[] from criteriaFind. My question is how do I know the size of the DataInfo[] in order to declare a variable to get the return values from this:
DataInfo[] criteriaFind(String criteria)
Thx for any advice.
 
Brandon W
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
testing...
 
Ranch Hand
Posts: 273
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
how do I know the size of the DataInfo[]
You pass a parameter criteria String in criteriaFind method. It looks into database all the matching records according to your criteria. You count how many they matched OR you save them in a DataInfo[] array. You dump them out whenever you need them.
-Bal
 
Ranch Hand
Posts: 200
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Bill,
Your answer seems to suggest that you are caching the search results in the Data object for furture searches. Is this correct?
I search the datafile each time criteria find is called and add each record that matches the criteria to an ArrayList. Just before I return I copy the ArrayList into a DataInfo[]. I tried using the Object[] toArray() method of the ArrayList class but couldn't get the Object[] to convert to a DataInfo[].
On the subject of criteriaFind(), has anyone else implemented an OR mechanism for instance, the string "Destination airport=DEN,Destination airport=SFO" would match all records that have a destination of DEN or SFO? Its not a specific requirement but its an obvious improvement.
Cheers,
Steve
 
Bal Sharma
Ranch Hand
Posts: 273
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Steve
Your answer seems to suggest that you are caching the search results in the Data object for furture searches. Is this correct?
Nop, my criteriaFind method returns matched array of DataInfo whenever it is needed.
I search the datafile each time criteria find is called and add each record that matches the criteria to an ArrayList. Just before I return I copy the ArrayList into a DataInfo[]. I tried using the Object[] toArray() method of the ArrayList class but couldn't get the Object[] to convert to a DataInfo[].
My implementation is also same as yours. When criteria find is called and it adds each record that matches the criteria to an ArrayList into a DataInfo[].
On the subject of criteriaFind(), has anyone else implemented an OR mechanism for instance, the string "Destination airport=DEN,Destination airport=SFO" would match all records that have a destination of DEN or SFO? Its not a specific requirement but its an obvious improvement.
Why extra work than needed? If there is any hidden bug, I bet you we get panalized. If extra functionality is excellent no extra bonus point. Even we do not know examiner gonna smile or not watching cool added functionality. It is not a code compition. When time comes I will try to demonstrate my ability at work. If I am being rude I am extermly sorry for that.
I am trying to make as simple as possible just to meet their requirements. I have two combo box on for carrier and one for origin airport. Comboboxes are loaded from database values. I have added 'All' at begining of each combo box for wildcard. If user selects carrier and origin airport combo box value and PRESS Search button. criteriaFind method is called. Matched records will be displayed in the table Else No matching records will be the message. If both 'All' is selected and Search button is clicked then all the records will be in the table.
I do not have to worry about what user gonna type as criteria. I just concate two combo box value as my creteria. That is it.
Believe me Steve. I am lazy too. Hope this helps.
-Bal
 
Steve Granton
Ranch Hand
Posts: 200
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I've decided that implementing the extra functionality is not worth all the trouble. I'm just going to stick to the requirements.
I'm getting lazy like you :-)
.. no offence taken,
Cheers,
Steve
 
Ranch Hand
Posts: 240
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What you can do is Create an array list and dump the data to it and then finally create an array.
For example:
ArrayList list = new ArrayList();
list.add(DataInfo1);
list.add(DataInfo2);
....
DataInfo[] d = (DataInfo[])list.asArray(new DataInfo[0]);
 
Steve Granton
Ranch Hand
Posts: 200
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
Thanks. I got that working with:
return (DataInfo[]) resultList.toArray(new DataInfo[resultList.size()]);
Cheers,
Steve
 
Brandon W
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I can return a DataInfo[] from criteriaFind(). However, how to catch the returned result is a question to me as I don't know what's the size of the return array. Actually, I may pass an array into the criteriaFind() but if I do so, I will actually change the parameters of the criteriaFind and that's doesn't match what shown in the downloaded assignment:
public DataInfo[] criteriaFind(String criteria)
can I actually change the declaration by adding more parameters?
Brandon
 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Brandon W:
Hi,
I can return a DataInfo[] from criteriaFind(). However, how to catch the returned result is a question to me as I don't know what's the size of the return array. Actually, I may pass an array into the criteriaFind() but if I do so, I will actually change the parameters of the criteriaFind and that's doesn't match what shown in the downloaded assignment:
public DataInfo[] criteriaFind(String criteria)
can I actually change the declaration by adding more parameters?
Brandon


I don't see the your problem. you can get the size of an array with its length attribut:

I would strongly discourage you from changing the API...
cheers
Hansjoerg
 
please buy this thing and then I get a fat cut of the action:
New web page for Paul's Rocket Mass Heaters movies
https://coderanch.com/t/785239/web-page-Paul-Rocket-Mass
reply
    Bookmark Topic Watch Topic
  • New Topic