File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

return DataInfo[]

 
Brandon W
Greenhorn
Posts: 10
  • 0
  • Mark post as helpful
  • send pies
  • 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
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
testing...
 
Bal Sharma
Ranch Hand
Posts: 273
  • 0
  • Mark post as helpful
  • send pies
  • 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
 
Steve Granton
Ranch Hand
Posts: 200
  • 0
  • Mark post as helpful
  • send pies
  • 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
  • 0
  • Mark post as helpful
  • send pies
  • 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
  • 0
  • Mark post as helpful
  • send pies
  • 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
 
Kalichar Rangantittu
Ranch Hand
Posts: 240
  • 0
  • Mark post as helpful
  • send pies
  • 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
  • 0
  • Mark post as helpful
  • send pies
  • 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
  • 0
  • Mark post as helpful
  • send pies
  • 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
 
Hansjoerg Wingeier
Greenhorn
Posts: 3
  • 0
  • Mark post as helpful
  • send pies
  • 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
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic