Returning a set

Posted by Thomas Mercer-Hursh on 12-Jun-2015 16:20

I am working with Proparse, which was written in Java, but which has been converted to a .NET DLL using IKVM.  I have one method on one of the classes which the documentation says returns a java.util.Set and another which returns a java.util.ArrayList<Symbol> where Symbol is one of the classes in Proparse.  I am wondering what I assign this too in an OpenEdge context.

Do I define a variable of type java.util.Set or java.util.ArrayList and put that on the left side of the assignment?

All Replies

Posted by Matt Baker on 12-Jun-2015 16:47

Depends on the data.
 
In java Set and List are interfaces.  ArrayList is basic implementation of List.  ArrayList does NOT implement Set:

·         Lists are ordered, and allow duplicates, and allow nulls.

·         Sets are unordered, do not allow duplicates, and may or may not allow null.

 
So it depends on the data.
 
 
 
[collapse]
From: Thomas Mercer-Hursh [mailto:bounce-tamhas@community.progress.com]
Sent: Friday, June 12, 2015 5:21 PM
To: TU.OE.Development@community.progress.com
Subject: [Technical Users - OE Development] Returning a set
 
Thread created by Thomas Mercer-Hursh

I am working with Proparse, which was written in Java, but which has been converted to a .NET DLL using IKVM.  I have one method on one of the classes which the documentation says returns a java.util.Set and another which returns a java.util.ArrayList<Symbol> where Symbol is one of the classes in Proparse.  I am wondering what I assign this too in an OpenEdge context.

Do I define a variable of type java.util.Set or java.util.ArrayList and put that on the left side of the assignment?

Stop receiving emails on this subject.

Flag this post as spam/abuse.

[/collapse]

Posted by Thomas Mercer-Hursh on 12-Jun-2015 17:04

There is another method that returns java.util.Collection<Variable>

I *think* that all of them are returning classes of type org.prorefactor.core.JPNode

But, I haven't a clue as to how I would define an ABL class of the appropriate type to receive these, nor how I would iterate through them once I did.  I am finding it hard to get much of a clue from the .NET docs because these are Java types.

Posted by Laura Stern on 12-Jun-2015 18:20

I would only guess that if the package was converted to a .NET DLL that the classes returned from it are .NET (or at least .NET wrappers) even though the names suggest they are Java classes.  So yes, define a variable of whatever type it says the method returns and put it on the left side of the left side of the assignment.  For generic classes, with angle brackets in the name, make sure the type name is in quotes when you define it.

Of course make sure that this DLL is in your assemblies .xml file and that the DLL is in the same directory as the .xml file.

Posted by Marian Edu on 13-Jun-2015 01:50

Laura is right Thomas, you should forget about the Java classes there and just use the DLL... IKVM took care of 'translation' so just check out the methods available in the assembly by using the class browser inside PSDOE.

Ah, and check-out Mike's include files for doing for-each on .net collections ;)

Posted by Thomas Mercer-Hursh on 13-Jun-2015 09:46

Yes, it is clear that iKVM has provided .NET classes with the names of the Java collection classes so presumably I can define a variable of that type and use it for the result.  It is just figuring out how to iterate through it.  I will see if I can find something from Mike.

Posted by Mike Fechner on 13-Jun-2015 09:58

The source and instructions how to use foreach.i is in my slides of the attached PUG challenge Americas talk.
Von: Thomas Mercer-Hursh [mailto:bounce-tamhas@community.progress.com]
Gesendet: Samstag, 13. Juni 2015 16:47
An: TU.OE.Development@community.progress.com
Betreff: RE: [Technical Users - OE Development] Returning a set
 
Reply by Thomas Mercer-Hursh

Yes, it is clear that iKVM has provided .NET classes with the names of the Java collection classes so presumably I can define a variable of that type and use it for the result.  It is just figuring out how to iterate through it.  I will see if I can find something from Mike.

Stop receiving emails on this subject.

Flag this post as spam/abuse.

Posted by Thomas Mercer-Hursh on 13-Jun-2015 10:25

Thanks!!!!

Posted by Thomas Mercer-Hursh on 13-Jun-2015 10:42

Looks like this is going to take a bit more research since the class browser shows no internals for IKVM.OpenJDK.Core where I presume these classes live.

Posted by Thomas Mercer-Hursh on 13-Jun-2015 15:39

So, I have gotten to:

define variable molBufferList as class java.util.Set no-undo.
define variable mobIterator as class java.util.Iterator no-undo.
define variable mobTableBuffer as class TableBuffer no-undo.

molBufferList = ipobParseUnit:getRootScope():getBufferSet().
mobIterator = molBufferList:iterator().

do while mobIterator:hasNext():
  mobTableBuffer = cast( mobIterator:next(), TableBuffer ).

But, this is giving me:

Error: Invalid cast from java.util.HashMap+Entry to org.prorefactor.treeparser.TableBuffer
So, I seem to get the java.util.Set correctly, but presumably its contents are not supersets of TableBuffer.

So, it is not clear to me what those Set entries are.

Posted by Mike Fechner on 13-Jun-2015 22:48

How about:

mobTableBuffer = CAST( mobIterator:next():getValue(), TableBuffer ).

Posted by Thomas Mercer-Hursh on 14-Jun-2015 09:54

This works:

define variable molBufferList as class java.util.ArrayList no-undo.
define variable mobIterator as class java.util.Iterator no-undo.
define variable mobSymbol as class Symbol no-undo.
define variable mobTableBuffer as class TableBuffer no-undo.
define variable mobTable as class org.prorefactor.core.schema.Table no-undo.

molBufferList = ipobParseUnit:getRootScope():getAllSymbolsDeep( ).
mobIterator = molBufferList:iterator().

do while mobIterator:hasNext():
mobSymbol = cast( mobIterator:next(), Symbol ).

if NodeTypes:getTypeName(mobSymbol:getProgressType()) <> "BUFFER" then next.

mobTableBuffer = cast( mobSymbol, TableBuffer ).
mobTable = mobTableBuffer:getTable().


This works, but I can find no expression to use as an argument to getAllSymbolsDeep() that will return only buffers.

mobSymbol:fullName() is getting me the qualified name including the database or not qualified if a temp-table.
mobTable:getName() gets me the name, not qualified, of the actual table.

More on the Proparse discussion forum on OE Hive

http://www.oehive.org/node/2289

This thread is closed