CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
Home > Forums > STAR-CCM+

Collections in Java

Register Blogs Members List Search Today's Posts Mark Forums Read

Reply
 
LinkBack Thread Tools Display Modes
Old   November 14, 2012, 10:53
Default Collections in Java
  #1
Member
 
Ryan Coe
Join Date: Jun 2010
Location: Albuquerque, NM
Posts: 98
Rep Power: 7
ryancoe is on a distinguished road
I'd like to use a Collection (or something else) to do the following:
  1. Create Collection containing all of the reports in a simulation
  2. Check if the Collection contains all the necessary reports
  3. If it is missing a report, add it

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
ryancoe is offline   Reply With Quote

Old   November 14, 2012, 17:45
Default
  #2
Senior Member
 
Join Date: Oct 2009
Location: Germany
Posts: 637
Rep Power: 12
abdul099 is on a distinguished road
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!
abdul099 is offline   Reply With Quote

Old   November 15, 2012, 09:05
Default
  #3
Member
 
Ryan Coe
Join Date: Jun 2010
Location: Albuquerque, NM
Posts: 98
Rep Power: 7
ryancoe is on a distinguished road
Ah ok, thanks.

How would I create a Report object in my macro without creating a report in the simulation?
__________________
Ryan
ryancoe is offline   Reply With Quote

Old   November 15, 2012, 19:39
Default
  #4
Senior Member
 
Join Date: Oct 2009
Location: Germany
Posts: 637
Rep Power: 12
abdul099 is on a distinguished road
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!
abdul099 is offline   Reply With Quote

Old   November 15, 2012, 22:03
Default
  #5
Member
 
Ryan Coe
Join Date: Jun 2010
Location: Albuquerque, NM
Posts: 98
Rep Power: 7
ryancoe is on a distinguished road
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
ryancoe is offline   Reply With Quote

Reply

Tags
macros

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Macro to access java files in sub-directory abraum STAR-CCM+ 3 July 11, 2012 02: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 06: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


All times are GMT -4. The time now is 04:29.