def _dict_to_properties_jpype(some_dict): from jpype import JPackage java_utils = JPackage('java.util') props = java_utils.Properties() for key in some_dict: props.setProperty(key, some_dict[key]) return props
def testProxyWithInst(self): itf2 = JPackage("jpype.proxy").ITestInterface3 Test3 = JPackage("jpype.proxy").Test3 c = C() proxy = JProxy(itf2, inst=c) Test3.testProxy(proxy)
def testProxyWithDict(self): d = { 'testMethod': _testMethod, 'testMethod2': _testMethod2, } itf2 = JPackage("jpype.proxy").ITestInterface3 Test3 = JPackage("jpype.proxy").Test3 proxy = JProxy(itf2, dictionary=d) Test3.testProxy(proxy)
def testPassingClassTypeSucceeds(self): h = JPackage("jpype.objectwrapper").Test1() # Select a convenient java.lang.Class object class_obj = h.getClass() # Check that funneling Class obj through java doesn't convert to null result = h.ReturnObject(class_obj) self.assertEqual(class_obj, result) self.assertNotEqual(result, None)
def testWriteArray(self) : t = JPackage("jpype").array.TestArray() self.assertNotIsInstance(t, JPackage) t.i[0] = 32 self.assertEqual(t.i[0], 32) t.i[1:3] = (33, 34) self.assertEqual(t.i[1], 33) self.assertEqual(t.i[2], 34) self.assertCountEqual(t.i[:5], (32, 33, 34 ,1324, 424) )
def testWriteArray(self): t = JPackage("jpype").array.TestArray() assert not isinstance(t, JPackage) t.i[0] = 32 assert t.i[0] == 32 t.i[1:3] = (33, 34) assert t.i[1] == 33 assert t.i[2] == 34 self.__arrayEquals(t.i[:5], (32, 33, 34, 1324, 424))
def do_shutdown(self, restart): if restart: if not jpype.isJVMStarted(): startJVM() self.VTLSession = JPackage('it').bancaditalia.oss.vtl.config.ConfigurationManager.getDefault().createSession() else: jpype.shutdownJVM()
def mapDomain(domain): import jpype.imports it = JPackage('it') from it.bancaditalia.oss.vtl.impl.types.domain import Domains if Domains.INTEGER.isAssignableFrom(domain): return 'int' elif Domains.NUMBER.isAssignableFrom(domain): return 'float' elif Domains.BOOLEAN.isAssignableFrom(domain): return 'bool' else: return 'string'
def __init__(self, *args, **kwargs): super(VTLKernel, self).__init__(*args, **kwargs) startJVM() from java.lang import System from java.io import ByteArrayOutputStream from java.io import PrintStream self.baos = ByteArrayOutputStream() ps = PrintStream(self.baos) System.setOut(ps) System.setErr(ps) it = JPackage('it') self.VTLSession = it.bancaditalia.oss.vtl.config.ConfigurationManager.getDefault().createSession()
def testGetArrayAsObject(self) : t = JPackage("jpype").array.TestArray() v = t.getArrayAsObject()
def testGetSubclass(self) : t = JPackage("jpype").array.TestArray() v = t.getSubClassArray() self.assertTrue(isinstance(v[0], unicode))
''' Created on 2012-12-22 @author: Man YUAN <*****@*****.**> ''' import numpy as np from terse_demo.util import jvm_util from jpype import JPackage,JArray,JDouble from terse_proto.tsmf.model import Polygon2D jvm_util.start_jvm(8998) JPolygon2D=JPackage('net').epsilony.tsmf.model.Polygon2D def sample_vertes_xys(): return np.array([[[0, 0], [1, 0], [1, 1],[0.5,0.5],[0,1]]],dtype=np.double) if __name__ == '__main__': pg_j = JPolygon2D.byCoordChains(sample_vertes_xys().tolist()) dist_func_j=np.frompyfunc(lambda x,y:pg_j.distanceFunc(x,y),2,1) pg_py = Polygon2D(sample_vertes_xys()) dist_func_py=np.frompyfunc(lambda x,y:pg_py.distance_function((x,y)),2,1) xs=np.linspace(-0.5,1.5,100) ys=np.linspace(-0.5,1.5,100) (g_xs,g_ys)=np.meshgrid(xs, ys) g_zs_j=dist_func_j(g_xs,g_ys)
def testGetSubclass(self): t = JPackage("jpype").array.TestArray() v = t.getSubClassArray() assert isinstance(v[0], str)
def _dump_model(self, model, format="TTL"): out = JPackage('java').io.StringWriter() model.write(out, format) return unicode.encode(out.toString(), 'utf-8')
''' Created on 2012-12-22 @author: Man YUAN <*****@*****.**> ''' import numpy as np from terse_demo.util import jvm_util from jpype import JPackage,JArray,JDouble jvm_util.start_jvm(8998) Polygon2D=JPackage('net').epsilony.tsmf.model.Polygon2D class Polygon2DPy(object): def __init__(self, vertex_xys): self.vertex_xys = np.array(vertex_xys,dtype=np.double) if len(self.vertex_xys.shape) < 2 or self.vertex_xys.shape[1] < 2 or self.vertex_xys.shape[0] < 3: raise ValueError("vertex_xys must have a shape which is bigger than (3,2)") def ray_crossing(self, xy): # Originate from: # Joseph O'Rourke, Computational Geometry in C,2ed. Page 244, Code 7.13 rcross = 0 lcross = 0 n = self.vertex_xys.shape[0] xys = self.vertex_xys x = xy[0] y = xy[1] for i in xrange(n): if np.alltrue(xys[i] == xy): return 'v'