|
[Sponsors] |
November 14, 2012, 10:53 |
Collections in Java
|
#1 |
Member
Ryan Coe
Join Date: Jun 2010
Location: Albuquerque, NM
Posts: 98
Rep Power: 16 |
I'd like to use a Collection (or something else) to do the following:
My sticking point is that to use the Collection.contains(Object o) method, the Object you input must be of the same class as those in the Collection you're dealing with. Thanks, Ryan
__________________
Ryan |
|
November 14, 2012, 17:45 |
|
#2 |
Senior Member
Join Date: Oct 2009
Location: Germany
Posts: 636
Rep Power: 22 |
It should also work when the object you input is inherited from the objects in the collection, e.g. a MaximumReport is inherited from Report. So it should work when you put all reports in a collection containing report type objects.
__________________
We do three types of jobs here: GOOD, FAST AND CHEAP You may choose any two! |
|
November 15, 2012, 09:05 |
|
#3 |
Member
Ryan Coe
Join Date: Jun 2010
Location: Albuquerque, NM
Posts: 98
Rep Power: 16 |
Ah ok, thanks.
How would I create a Report object in my macro without creating a report in the simulation?
__________________
Ryan |
|
November 15, 2012, 19:39 |
|
#4 |
Senior Member
Join Date: Oct 2009
Location: Germany
Posts: 636
Rep Power: 22 |
Hm, it seems I didn't get the point when I first read your post.
Creating reports just in your macro isn't possible since the report constructor needs a ClientServerObject (which you don't have). You also can't compare with a number of pre-created reports (let's assume you've saved them from another simulation by serialization). The reason is, the old report will not point to the same object as the current one. That's like having a picture of your friend's Corvette. When you see one on the street, it looks the same - but it isn't your friend's one. It's not the same object. When you just want to to check if a number of needed reports is in the simulation, I would do a simple name comparison. This can be done by getting all reports in your simulation, creation of a collection (or array) of strings containing the report names. Then you just need to iterate through the reports collection and check if the report name matches the first field of your string collection. Then go to the second string in the collection, iterate over the reports collection... That's a lot of work for your machine, and for sure it's not the most elegant way. Maybe there's a better way, but for today it's too late. I need to check my little helper macro collection first You might shortcut it a little by using some try-catch statements. Just try to get a specific report in the try-block. When it fails, create it in the catch-block. With this you'll avoid to iterate through a collection for every object of a collection your're iterating through. (Can also be put in a single loop, so you don't have to write ton's of try-catch statements). This would be a nice solution when you write your own class, containing all necessary data like report name, report type, boundaries to put in... etc. Then you just need to loop over a collection with this own-class objects, get the name, try to get the corresponding report in CCM+ by name comparison, and if it fails, you have all information available to create the report in CCM+.
__________________
We do three types of jobs here: GOOD, FAST AND CHEAP You may choose any two! |
|
November 15, 2012, 22:03 |
|
#5 |
Member
Ryan Coe
Join Date: Jun 2010
Location: Albuquerque, NM
Posts: 98
Rep Power: 16 |
Abdul,
Thanks much for the detailed reply! You've confirmed my suspicions about needing to compare an string array containing the report names. While this may take a minute, that shouldn't be much of an issue since it only needs to happen once (at the beginning of a simulation which will take itself take hours to iterate). Your try-catch idea, with a self-defined class containing the reports' particulars, is a great idea. I'll give that a try and let you know how it goes. Thanks again, Ryan
__________________
Ryan |
|
Tags |
macros |
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Macro to access java files in sub-directory | abraum | STAR-CCM+ | 3 | July 11, 2012 03:46 |
Finite Volume Method in Java with GPU support | Don456 | Main CFD Forum | 0 | December 14, 2011 11:43 |
How to open the ICEM help with java? | windhair | CFX | 2 | May 18, 2007 07:05 |
Getting OpenFOAM to coexist with an existing JAVA VM | nik777 | OpenFOAM Installation | 5 | February 22, 2007 08:21 |
java vs c++ | zxaar | Main CFD Forum | 10 | December 3, 2004 03:05 |