Modifier and Type | Method and Description |
---|---|
PyObject |
call(String name,
Object... args)
Call the callable Python object with the given name and arguments.
|
PyObject |
callMethod(String name,
Object... args)
Call the callable Python method with the given name and arguments.
|
<T> T |
createProxy(Class<T> type)
Create a Java proxy instance of this Python object which contains compatible methods to the ones provided in the
interface given by the
type parameter. |
Object |
createProxy(PyLib.CallableKind callableKind,
Class<?>... types)
Create a Java proxy instance of this Python object (or module) which contains compatible methods
(or functions) to the ones provided in the interfaces given by all the
type parameters. |
boolean |
equals(Object o)
Indicates whether some other object is "equal to" this one.
|
static PyObject |
executeCode(String code,
PyInputMode mode)
Executes Python source code.
|
static PyObject |
executeCode(String code,
PyInputMode mode,
Map<String,Object> globals,
Map<String,Object> locals)
Executes Python source code in the context specified by the
globals and locals maps. |
protected void |
finalize()
Decrements the reference count of the Python object which this class represents.
|
PyObject |
getAttribute(String name)
Gets the Python value of a Python attribute.
|
<T> T |
getAttribute(String name,
Class<? extends T> valueType)
Gets the value of a Python attribute as Java object of a given type.
|
double |
getDoubleValue() |
int |
getIntValue() |
<T> T[] |
getObjectArrayValue(Class<? extends T> itemType)
Gets this Python object as Java
Object[] value of the given item type. |
Object |
getObjectValue()
Gets this Python object as Java
Object value. |
long |
getPointer() |
String |
getStringValue() |
int |
hashCode()
Computes a hash code from this object's pointer value.
|
<T> void |
setAttribute(String name,
T value)
Sets the value of a Python attribute from the given Java object.
|
<T> void |
setAttribute(String name,
T value,
Class<? extends T> valueType)
Sets the value of a Python attribute from the given Java object and Java type (if given).
|
String |
toString()
Gets a string representation of the object using the format "PyObject(pointer=<value>)".
|
public static PyObject executeCode(String code, PyInputMode mode)
code
- The Python source code.mode
- The execution mode.public static PyObject executeCode(String code, PyInputMode mode, Map<String,Object> globals, Map<String,Object> locals)
globals
and locals
maps.
If a Java value in the globals
and locals
maps cannot be directly converted into a Python object, a Java wrapper will be created instead.
If a Java value is a wrapped Python object of type PyObject
, it will be unwrapped.
code
- The Python source code.mode
- The execution mode.globals
- The global variables to be set.locals
- The locals variables to be set.protected void finalize() throws Throwable
public final long getPointer()
public int getIntValue()
int
value.public double getDoubleValue()
double
value.public String getStringValue()
String
value.public Object getObjectValue()
Object
value.
If this Python object cannot be converted into a Java object, a Java wrapper of type PyObject
will be returned.
If this Python object is a wrapped Java object, it will be unwrapped.
Object
value.public <T> T[] getObjectArrayValue(Class<? extends T> itemType)
Object[]
value of the given item type.
Appropriate type conversions from Python to Java will be performed as needed.
If a Python item value cannot be converted into a Java item object, a Java wrapper of type PyObject
will be returned.
If a Python item value is a wrapped Java object, it will be unwrapped.
If this Python object value is a wrapped Java array object of given type, it will be unwrapped.
T
- The expected item type name.itemType
- The expected item type class.Object[]
value.public PyObject getAttribute(String name)
If the Python value cannot be converted into a Java object, a Java wrapper of type PyObject
will be returned.
If the Python value is a wrapped Java object, it will be unwrapped.
name
- A name of the Python attribute.public <T> T getAttribute(String name, Class<? extends T> valueType)
If the Python value cannot be converted into a Java object, a Java wrapper of type PyObject
will be returned.
If the Python value is a wrapped Java object, it will be unwrapped.
T
- The expected value type name.name
- A name of the Python attribute.valueType
- The type of the value or null
, if unknownpublic <T> void setAttribute(String name, T value)
If the Java value
cannot be directly converted into a Python object, a Java wrapper will be created instead.
If the Java value
is a wrapped Python object of type PyObject
, it will be unwrapped.
T
- The value type name.name
- A name of the Python attribute.value
- The new attribute value as Java object.public <T> void setAttribute(String name, T value, Class<? extends T> valueType)
If the Java value
cannot be directly converted into a Python object, a Java wrapper will be created instead.
If the Java value
is a wrapped Python object of type PyObject
, it will be unwrapped.
T
- The value type name.name
- A name of the Python attribute.value
- The new attribute value as Java object.valueType
- The value type used for the conversion. May be null
.public PyObject callMethod(String name, Object... args)
If a Java value in args
cannot be directly converted into a Python object, a Java wrapper will be created instead.
If the Java value in args
is a wrapped Python object of type PyObject
, it will be unwrapped.
name
- A name of a Python attribute that evaluates to a callable object.args
- The arguments for the method call.public PyObject call(String name, Object... args)
If a Java value in args
cannot be directly converted into a Python object, a Java wrapper will be created instead.
If the Java value in args
is a wrapped Python object of type PyObject
, it will be unwrapped.
name
- A name of a Python attribute that evaluates to a callable object,args
- The arguments for the call.public <T> T createProxy(Class<T> type)
type
parameter.T
- The interface name.type
- The interface class.public Object createProxy(PyLib.CallableKind callableKind, Class<?>... types)
type
parameters.callableKind
- The kind of calls to be made.types
- The interface types.public final String toString()
toString
in class Object
getPointer()
public final boolean equals(Object o)
equals
in class Object
o
- The other object.true
if the other object is an instance of PyObject
and if their pointers are equal, false
otherwise.getPointer()
public final int hashCode()
hashCode
in class Object
getPointer()
Copyright © 2014–2015 Brockmann Consult GmbH. All rights reserved.