FusionAtlas`Java` package

Version 0, January 26 2009, Scott Morrison, Emily Peters, Noah Snyder

Implementation

BeginPackage["FusionAtlas`Java`",{"FusionAtlas`","JLink`","FusionAtlas`Bigraphs`","FusionAtlas`GraphPairs`"}]

FusionAtlasJavaDirectory::usage="";FusionAtlasScalaDirectory::usage="";

GraphToScalaObject;AsScalaSet;AsScalaList;UnpackJavaLists;UnpackJavaObjects;

RestartJava;

Begin["`Private`"];

FusionAtlasJavaDirectory[]:=ToFileName[FusionAtlasDirectory[],"java"]

FusionAtlasScalaDirectory[]:=ToFileName[FusionAtlasDirectory[],"scala"]

RestartJava[]:=
Module[{},
If[!IntegerQ[Global`$JVMHeap]∨Global`$JVMHeap<256,Global`$JVMHeap=256];
ReinstallJava[CommandLine->"java",JVMArguments->"-Xmx"<>ToString[Global`$JVMHeap]<>"m"];
AllowRaggedArrays[True];
LoadJavaClass["org.fusionatlas.v1.odometer.GradedBigraph"];
LoadJavaClass["org.fusionatlas.v1.odometer.Proxy"];
]

AddToClassPath[ToFileName[FusionAtlasJavaDirectory[],"target"],ToFileName[FusionAtlasJavaDirectory[],"jars"],ToFileName[FusionAtlasScalaDirectory[],"target"],ToFileName[FusionAtlasScalaDirectory[],"jars"],ToFileName[FusionAtlasScalaDirectory[],"lib"]];

AllowRaggedArrays[True];

LoadJavaClass["org.fusionatlas.v1.odometer.GradedBigraph"];
LoadJavaClass["org.fusionatlas.v1.odometer.Proxy"];
LoadJavaClass["org.fusionatlas.enumerators.QueueEnumerator"];

LoadJavaClass["org.fusionatlas.graphs.PairOfBigraphsWithDuals","AllowShortContext"->False];
LoadJavaClass["org.fusionatlas.graphs.Bigraph$","AllowShortContext"->False];
LoadJavaClass["org.fusionatlas.graphs.BigraphWithDuals","AllowShortContext"->False];
LoadJavaClass["scala.collection.immutable.List$","AllowShortContext"->False];LoadJavaClass["scala.collection.immutable.Set$","AllowShortContext"->False];
LoadJavaClass["java.util.Arrays","AllowShortContext"->False];
LoadJavaClass["scala.collection.JavaConversions","AllowShortContext"->False];

GraphToScalaObject[g_GradedBigraph]:=org`fusionatlas`graphs`Bigraph$`MODULE$@apply[GraphToString[g]]

GraphToScalaObject[g_BigraphWithDuals]:=org`fusionatlas`graphs`BigraphWithDuals`apply[GraphToString[g]]

GraphToScalaObject[{g1_BigraphWithDuals,g2_BigraphWithDuals}]:=org`fusionatlas`graphs`PairOfBigraphsWithDuals`apply[GraphToString[g1],GraphToString[g2]]

AsScalaSet[list_]:=scala`collection`JavaConversions`asSet[JavaNew["java.util.HashSet",java`util`Arrays`asList[MakeJavaObject[list]]]]
AsScalaSet[{}]:=scala`collection`immutable`Set$`MODULE$@empty[]

AsScalaList[list_]:=scala`collection`JavaConversions`asBuffer[java`util`Arrays`asList[MakeJavaObject[list]]]@toList[]
AsScalaList[{}]:=scala`collection`immutable`List$`MODULE$@empty[]

UnpackJavaLists[X_]:=X//.{Y_/;InstanceOf[Y,"scala.collection.immutable.List"]:>JavaConversions`asList[Y],Y_/;InstanceOf[Y,"scala.Tuple2"]->Y@productIterator[]@toList[],Y_/;InstanceOf[Y,"java.util.List"]:>Y@toArray[]}

UnpackJavaObjects[X_]:=UnpackJavaLists[X]//.{Y_/;InstanceOf[Y,"net.tqft.toolkit.MathematicaExpression"]:>ToExpression[Y@toMathematicaInputString[]]}

End[];

EndPackage[];