aspose file tools*
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes return DataInfo[] Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "return DataInfo[]" Watch "return DataInfo[]" New topic
Author

return DataInfo[]

Brandon W
Greenhorn

Joined: Jan 22, 2002
Posts: 10
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

Joined: Jan 22, 2002
Posts: 10
testing...
Bal Sharma
Ranch Hand

Joined: Sep 19, 2001
Posts: 273
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

Joined: Jan 13, 2002
Posts: 200
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

Joined: Sep 19, 2001
Posts: 273
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

Joined: Jan 13, 2002
Posts: 200
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

Joined: Jan 15, 2002
Posts: 240
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]);


Never be satisfied with anything less than the best and you will surely pass the test...
Steve Granton
Ranch Hand

Joined: Jan 13, 2002
Posts: 200
Hi,
Thanks. I got that working with:
return (DataInfo[]) resultList.toArray(new DataInfo[resultList.size()]);
Cheers,
Steve
Brandon W
Greenhorn

Joined: Jan 22, 2002
Posts: 10
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

Joined: Dec 19, 2001
Posts: 3
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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: return DataInfo[]