0

I am using the following script to select an object from a set of input objects using an index. It does not recognize that the input argument is a set of three values. I assume I am doing something wrong in the line:

if(setOfObjects  instanceof java.util.Collection)


if(setOfObjects != null)
{
   if(setOfObjects  instanceof java.util.Collection)
   {
      object = setOfObjects.get(index);
      if (object instanceof fUML.Semantics.Classes.Kernel.Object_)
      {
         fUML.Semantics.Classes.Kernel.Reference r = new fUML.Semantics.Classes.Kernel.Reference(object.getOwner());
         r.setReferent(object);
         object = r;
      }
   }
   Else print(index);
   if(index == 1)
   {
      print("ok");
      object = setOfObjects;
   }
   else
   {
      print("failed");
      object = null;
   }
}
else
{
   object = null;
}
  • I would first check what this tells you: `print("setOfObjects is : " + setOfObjects.getClass().getName());`. Also capital Else? Not correct, unless BeanShell tolerates it. – GaryMcM Mar 22 '13 at 15:50

1 Answers1

0

GaryMcM's approach is correct. The code worked correctly for me when I set setOfObjects as instance of java.util.HashSet in interpreter namespace, as below.

Set<String> setOfObjects = new HashSet<String>();
i.set("setOfObjects", setOfObjects );(i being beanshell interpreter's instance)

few observations :

  1. keyword Else should be else (beanshell doesn't tolerate it)
  2. setOfObjects.get(index); will throw error as there is no get(int) in Sets

Are you sure the setOfObjects which you are providing is not null, or with no typo error, as beanshell will assume a variable with typo error as new one. (in non strict java mode).

Shailesh Aswal
  • 6,632
  • 1
  • 20
  • 27