当前位置: 首页>>代码示例>>Python>>正文


Python JavaGateway.new_array方法代码示例

本文整理汇总了Python中py4j.java_gateway.JavaGateway.new_array方法的典型用法代码示例。如果您正苦于以下问题:Python JavaGateway.new_array方法的具体用法?Python JavaGateway.new_array怎么用?Python JavaGateway.new_array使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在py4j.java_gateway.JavaGateway的用法示例。


在下文中一共展示了JavaGateway.new_array方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: ArrayTest

# 需要导入模块: from py4j.java_gateway import JavaGateway [as 别名]
# 或者: from py4j.java_gateway.JavaGateway import new_array [as 别名]
class ArrayTest(unittest.TestCase):
    def setUp(self):
        self.p = start_example_app_process()
        time.sleep(0.5)
        self.gateway = JavaGateway()

    def tearDown(self):
        self.p.terminate()
        self.gateway.shutdown()
        time.sleep(0.5)

    def testArray(self):
        example = self.gateway.entry_point.getNewExample()
        array1 = example.getStringArray()
        array2 = example.getIntArray()
        self.assertEqual(3, len(array1))
        self.assertEqual(4, len(array2))

        self.assertEqual("333", array1[2])
        self.assertEqual(5, array2[1])

        array1[2] = "aaa"
        array2[1] = 6
        self.assertEqual("aaa", array1[2])
        self.assertEqual(6, array2[1])

        new_array = array2[1:3]
        self.assertEqual(2, len(new_array))
        self.assertEqual(1, new_array[1])

    def testCreateArray(self):
        int_class = self.gateway.jvm.int
        string_class = self.gateway.jvm.java.lang.String
        int_array = self.gateway.new_array(int_class, 2)
        string_array = self.gateway.new_array(string_class, 3, 5)
        self.assertEqual(2, len(int_array))
        self.assertEqual(3, len(string_array))
        self.assertEqual(5, len(string_array[0]))

    def testDoubleArray(self):
        double_class = self.gateway.jvm.double
        double_array = self.gateway.new_array(double_class, 2)
        double_array[0] = 2.2
        self.assertAlmostEqual(double_array[0], 2.2)

    def testFloatArray(self):
        float_class = self.gateway.jvm.float
        float_array = self.gateway.new_array(float_class, 2)
        float_array[0] = 2.2
        self.assertAlmostEqual(float_array[0], 2.2)

    def testCharArray(self):
        char_class = self.gateway.jvm.char
        char_array = self.gateway.new_array(char_class, 2)
        char_array[0] = "a"
        self.assertAlmostEqual(char_array[0], "a")
开发者ID:davidcsterratt,项目名称:py4j,代码行数:58,代码来源:java_array_test.py

示例2: Test

# 需要导入模块: from py4j.java_gateway import JavaGateway [as 别名]
# 或者: from py4j.java_gateway.JavaGateway import new_array [as 别名]
class Test(unittest.TestCase):
    def setUp(self):
#        logger = logging.getLogger("py4j")
#        logger.setLevel(logging.DEBUG)
#        logger.addHandler(logging.StreamHandler())
        self.p = start_example_app_process()
        time.sleep(0.5)
        self.gateway = JavaGateway()

    def tearDown(self):
        self.p.terminate()
        self.gateway.shutdown()

        time.sleep(0.5)

    def testArray(self):
#        self.gateway.jvm.py4j.GatewayServer.turnLoggingOn()
        example = self.gateway.entry_point.getNewExample()
        array1 = example.getStringArray()
        array2 = example.getIntArray()
        self.assertEqual(3, len(array1))
        self.assertEqual(4, len(array2))

        self.assertEqual('333', array1[2])
        self.assertEqual(5, array2[1])

        array1[2] = 'aaa'
        array2[1] = 6
        self.assertEqual('aaa', array1[2])
        self.assertEqual(6, array2[1])

        new_array = array2[1:3]
        self.assertEqual(2, len(new_array))
        self.assertEqual(1, new_array[1])

    def testCreateArray(self):
        int_class = self.gateway.jvm.int
        string_class = self.gateway.jvm.java.lang.String
        int_array = self.gateway.new_array(int_class, 2)
        string_array = self.gateway.new_array(string_class, 3, 5)
        self.assertEqual(2, len(int_array))
        self.assertEqual(3, len(string_array))
        self.assertEqual(5, len(string_array[0]))
开发者ID:pellis10asee,项目名称:sharkhunter-shb,代码行数:45,代码来源:java_array_test.py

示例3: ImageCover

# 需要导入模块: from py4j.java_gateway import JavaGateway [as 别名]
# 或者: from py4j.java_gateway.JavaGateway import new_array [as 别名]
class ImageCover(object):

    # Constructor: Crea la conexión con el programa Java y llama al constructor
    # de la clase ImageCover.java enviandole la ruta donde se encuentra la imagen.
    def __init__(self, path):
        self.gateway = JavaGateway()
        self.imageCover = self.gateway.jvm.ImageCover(path)

    # Cierra la conexión con el programa Java
    def close_java_connection(self):
        self.gateway.shutdown()

    # Devuelve la ruta a la imagen especificada en el constructor.
    def get_path(self):
        return self.imageCover.getPath()

    # Devuelve el alto de la imagen
    def get_height(self):
        return self.imageCover.getHeight()

    # Devuelve el ancho de la imagen
    def get_width(self):
        return self.imageCover.getWidth()

    # Devuelve la carpeta 'padre' de la imagen
    def get_parent_path(self):
        return self.imageCover.getParentPath()

    # Devuelve el nombre del archivo imagen
    def get_cover_name(self):
        return self.imageCover.getCoverName()

    # Devuelve la extensión de la imagen
    def get_extension(self):
        return self.imageCover.getExtension()

    # 'Dibuja' texto en la imagen. Recibe un array de String que contiene los textos a escribir,
    # las posiciones x e y donde se van a escribir los textos y el color del texto.
    # Por defecto, escribe los textos en la esquina superior derecha y el color del texto lo
    # calcula haciendo el inverso del color dominante en la imagen.
    def set_text(self, texts, x=-1, y=-1):
        # color = self.gateway.jvm.java.awt.Color.white
        # print(color)
        string_array = self.gateway.new_array(self.gateway.jvm.String, len(texts))
        for index, text in enumerate(texts):
            string_array[index] = text
        self.imageCover.setText(string_array, x, y)
开发者ID:tak30,项目名称:songs_of_anarchy,代码行数:49,代码来源:imageCover.py

示例4: JavaGateway

# 需要导入模块: from py4j.java_gateway import JavaGateway [as 别名]
# 或者: from py4j.java_gateway.JavaGateway import new_array [as 别名]
__author__ = 'GHajba'

from py4j.java_gateway import JavaGateway
import sys

gateway = JavaGateway()
app = gateway.entry_point

nums = gateway.new_array(gateway.jvm.int, len(sys.argv))
for i in range(1, len(sys.argv)):
    nums[i-1] = int(sys.argv[i])

print("The result is: %d"%app.addNumbers(nums))
开发者ID:ghajba,项目名称:JaPy,代码行数:15,代码来源:py4jPython.py


注:本文中的py4j.java_gateway.JavaGateway.new_array方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。