Package com.illumon.iris.db.util
Interface PythonScope<PyObj>
- Type Parameters:
PyObj- the implementation's raw Python object type
- All Known Implementing Classes:
PythonScopeJpyImpl
public interface PythonScope<PyObj>
A collection of methods around retrieving objects from the given Python scope.
The scope is likely coming from some sort of Python dictionary. The scope might be local, global, or other.
-
Method Summary
Modifier and TypeMethodDescriptiondefault booleancontainsKey(String name) Finds out if a variable is in scopeconvertStringKey(PyObj key) The helper method to turn a raw key into a string key.convertValue(PyObj value) The helper method to turn a raw value into an implementation specific object.Equivalent togetEntriesRaw(), where the keys have been converted viaconvertStringKey(PyObj)(PyObj) and the values viaconvertValue(PyObj)(PyObj)Equivalent togetEntries().collect(someMapCollector)Retrieves all keys and values from the given scope.getKeys()Equivalent togetKeysRaw().map(convertStringKey(PyObj)(PyObj))default Collection<String>Equivalent togetKeys().collect(someCollector)Retrieves all keys from the give scope.Equivalent togetValueRaw(String).map(convertValue(PyObj)(PyObj))default <T> Optional<T>getValueRaw(String name) Retrieves a value from the given scope.default <T> Optional<T>getValueUnchecked(String name) Equivalent togetValue(String).map(x -> (T)x);org.jpy.PyDictWrapperglobals()
-
Method Details
-
getValueRaw
Retrieves a value from the given scope.No conversion is done.
- Parameters:
name- the name of the python variable- Returns:
- the value, or empty
-
getKeysRaw
Retrieves all keys from the give scope.No conversion is done.
Technically, the keys can be tuples...
- Returns:
- the keys
-
getEntriesRaw
Retrieves all keys and values from the given scope.No conversion is done.
- Returns:
- the keys and values
-
convertStringKey
The helper method to turn a raw key into a string key.Note: this assumes that all the keys are strings, which is not always true. Keys can also be tuples. TODO: revise interface as appropriate if this becomes an issue.
- Parameters:
key- the raw key- Returns:
- the string key
- Throws:
IllegalArgumentException- if the key is not a string
-
convertValue
The helper method to turn a raw value into an implementation specific object.This method should NOT convert PyObj of None type to null - we need to preserve the None object so it works with other Optional return values.
- Parameters:
value- the raw value- Returns:
- the converted object value
-
containsKey
Finds out if a variable is in scope- Parameters:
name- the name of the python variable- Returns:
- true iff the scope contains the variable
-
getValue
Equivalent togetValueRaw(String).map(convertValue(PyObj)(PyObj))- Parameters:
name- the name of the python variable- Returns:
- the converted object value, or empty
-
getValue
- Type Parameters:
T- the return type- Parameters:
name- the name of the python variableclazz- the class to cast to- Returns:
- the converted casted value, or empty
-
getValueUnchecked
Equivalent togetValue(String).map(x -> (T)x);- Type Parameters:
T- the return type- Parameters:
name- the name of the python variable- Returns:
- the converted casted value, or empty
-
getKeys
Equivalent togetKeysRaw().map(convertStringKey(PyObj)(PyObj))- Returns:
- the string keys
-
getEntries
Equivalent togetEntriesRaw(), where the keys have been converted viaconvertStringKey(PyObj)(PyObj) and the values viaconvertValue(PyObj)(PyObj)- Returns:
- the string keys and converted values
-
getKeysCollection
Equivalent togetKeys().collect(someCollector)- Returns:
- the string keys, as a collection
-
getEntriesMap
Equivalent togetEntries().collect(someMapCollector)- Returns:
- the string keys and converted values, as a map
-
globals
org.jpy.PyDictWrapper globals()
-