app/src/main/assets/python/app_packages/rubicon/java/api.py
def select_polymorph(polymorphs, args):
    """Determine the polymorphic signature that will match a given argument list.
    This is the mechanism used to reconcile Java's strict-typing polymorphism with
    Python's unique-name, weak typing polymorphism. When invoking a method on the
    Python side, the number and types of the arguments provided are used to determine
    which Java method will be invoked.
    polymorphs should be a dictionary, keyed by the JNI signature of the arguments
    expected by the method. The values in the dictionary are not used; this method
    is only used to determine, which key should be used.
    args is a list of arguments that have been passed to invoke the method.
    Returns a 3-tuple:
     * arg_sig - the actual signature of the provided arguments
     * match_types - the type list that was matched. This is a list of individual
       type signatures; not in string form like arg_sig, but as a list where each
       element is the type for a particular argument. (i.e.,
        [b'I', b'Ljava/lang/String;', b'Z'], not b'ILjava/langString;Z').
       The contents of match_types will be the same as arg_sig if there is a
       direct match in polymorphs; if there isn't, the signature of the matching
       polymorph will be returned.
     * polymorph - the value from the input polymorphs that matched. Equivalent
       to polymorphs[match_types]
    """
    arg_types = []
    if len(args) == 0:
        arg_sig = b''
        options = [[]]
    else:
        for arg in args:
            if isinstance(arg, (bool, jboolean)):
                arg_types.append([b'Z'])
            elif isinstance(arg, jbyte):
                arg_types.append([b'B'])
            elif isinstance(arg, jchar):
                arg_types.append([b'C'])
            elif isinstance(arg, jshort):
                arg_types.append([b'S'])
            elif isinstance(arg, jint):
                arg_types.append([b'I'])
            elif isinstance(arg, int):
                arg_types.append([b'I', b'J', b'S'])
            elif isinstance(arg, jlong):
                arg_types.append([b'J'])
            elif isinstance(arg, jfloat):
                arg_types.append([b'F'])
            elif isinstance(arg, float):
                arg_types.append([b'D', b'F'])
            elif isinstance(arg, jdouble):
                arg_types.append([b'D'])
            elif isinstance(arg, str):
                arg_types.append([
                    b"Ljava/lang/String;",
                    b"Ljava/io/Serializable;",
                    b"Ljava/lang/Comparable;",
                    b"Ljava/lang/CharSequence;",
                    b"Ljava/lang/Object;",
                ])
            # If char arrays are useful to handle, add them later. Handle all other types of primitive type arrays.
            elif isinstance(arg, bytes):
                arg_types.append([b'[B'])
            elif isinstance(arg, Sequence) and len(arg) > 0:
                # If arg is an iterable of all the same basic numeric type, then
                # an array of that Java type can work.
                if isinstance(arg[0], (bool, jboolean)):
                    if all((isinstance(item, (bool, jboolean)) for item in arg)):
                        arg_types.append([b'[Z'])
                    else:
                        raise ValueError("Convert entire list to bool/jboolean to create a Java boolean array")
                elif isinstance(arg[0], (int, jint)):
                    if all((isinstance(item, (int, jint)) for item in arg)):
                        arg_types.append([b'[I'])
                    else:
                        raise ValueError("Unable to treat all data in list as integers")
                elif isinstance(arg[0], (float, jfloat, jdouble)):
                    if all((isinstance(item, (float, jfloat, jdouble)) for item in arg)):
                        arg_types.append([b'[D', b'[F'])
                    else:
                        raise ValueError("Unable to treat all data in list as floats/doubles")
                else:
                    raise ValueError("Unable convert sequence into array of Java primitive types")
            elif isinstance(arg, (JavaInstance, JavaProxy)):
                arg_types.append(arg.__class__.__dict__['_alternates'])
            else:
                raise ValueError("Unknown argument type", arg, type(arg))

        arg_sig = b''.join(t[0] for t in arg_types)

        options = list(itertools.product(*arg_types))

    for option in options:
        try:
            return arg_sig, option, polymorphs[b''.join(option)]
        except KeyError:
            pass

    raise KeyError(arg_sig)
Determine the polymorphic signature that will match a given argument list.
    This is the mechanism used to reconcile Java's strict-typing polymorphism with
    Python's unique-name, weak typing polymorphism. When invoking a method on the
    Python side, the number and types of the arguments provided are used to determine
    which Java method will be invoked.
    polymorphs should be a dictionary, keyed by the JNI signature of the arguments
    expected by the method. The values in the dictionary are not used; this method
    is only used to determine, which key should be used.
    args is a list of arguments that have been passed to invoke the method.
    Returns a 3-tuple:
     * arg_sig - the actual signature of the provided arguments
     * match_types - the type list that was matched. This is a list of individual
       type signatures; not in string form like arg_sig, but as a list where each
       element is the type for a particular argument. (i.e.,
        [b'I', b'Ljava/lang/String;', b'Z'], not b'ILjava/langString;Z').
       The contents of match_types will be the same as arg_sig if there is a
       direct match in polymorphs; if there isn't, the signature of the matching
       polymorph will be returned.
     * polymorph - the value from the input polymorphs that matched. Equivalent
       to polymorphs[match_types]
    
Determine the polymorphic signature that will match a given argument list.
This is the mechanism used to reconcile Java's strict-typing polymorphism with
Python's unique-name, weak typing polymorphism. When invoking a method on the
Python side, the number and types of the arguments provided are used to determine
which Java method will be invoked.
polymorphs should be a dictionary, keyed by the JNI signature of the arguments
expected by the method. The values in the dictionary are not used; this method
is only used to determine, which key should be used.
args is a list of arguments that have been passed to invoke the method.
Returns a 3-tuple:
arg_sig - the actual signature of the provided arguments
match_types - the type list that was matched. This is a list of individual
type signatures; not in string form like arg_sig, but as a list where each
element is the type for a particular argument.
Determine the polymorphic signature that will match a given argument list . This is the mechanism used to reconcile Java ' s strict - typing polymorphism with Python ' s unique - name weak typing polymorphism . When invoking a method on the Python side the number and types of the arguments provided are used to determine which Java method will be invoked . polymorphs should be a dictionary keyed by the JNI signature of the arguments expected by the method . The values in the dictionary are not used ; this method is only used to determine which key should be used . args is a list of arguments that have been passed to invoke the method . Returns a 3 - tuple : arg_sig - the actual signature of the provided arguments match_types - the type list that was matched . This is a list of individual type signatures ; not in string form like arg_sig but as a list where each element is the type for a particular argument .
def select_polymorph(polymorphs, args):
    arg_types = []
    if len(args) == 0:
        arg_sig = b''
        options = [[]]
    else:
        for arg in args:
            if isinstance(arg, (bool, jboolean)):
                arg_types.append([b'Z'])
            elif isinstance(arg, jbyte):
                arg_types.append([b'B'])
            elif isinstance(arg, jchar):
                arg_types.append([b'C'])
            elif isinstance(arg, jshort):
                arg_types.append([b'S'])
            elif isinstance(arg, jint):
                arg_types.append([b'I'])
            elif isinstance(arg, int):
                arg_types.append([b'I', b'J', b'S'])
            elif isinstance(arg, jlong):
                arg_types.append([b'J'])
            elif isinstance(arg, jfloat):
                arg_types.append([b'F'])
            elif isinstance(arg, float):
                arg_types.append([b'D', b'F'])
            elif isinstance(arg, jdouble):
                arg_types.append([b'D'])
            elif isinstance(arg, str):
                arg_types.append([
                    b"Ljava/lang/String;",
                    b"Ljava/io/Serializable;",
                    b"Ljava/lang/Comparable;",
                    b"Ljava/lang/CharSequence;",
                    b"Ljava/lang/Object;",
                ])
            elif isinstance(arg, bytes):
                arg_types.append([b'[B'])
            elif isinstance(arg, Sequence) and len(arg) > 0:
                if isinstance(arg[0], (bool, jboolean)):
                    if all((isinstance(item, (bool, jboolean)) for item in arg)):
                        arg_types.append([b'[Z'])
                    else:
                        raise ValueError("Convert entire list to bool/jboolean to create a Java boolean array")
                elif isinstance(arg[0], (int, jint)):
                    if all((isinstance(item, (int, jint)) for item in arg)):
                        arg_types.append([b'[I'])
                    else:
                        raise ValueError("Unable to treat all data in list as integers")
                elif isinstance(arg[0], (float, jfloat, jdouble)):
                    if all((isinstance(item, (float, jfloat, jdouble)) for item in arg)):
                        arg_types.append([b'[D', b'[F'])
                    else:
                        raise ValueError("Unable to treat all data in list as floats/doubles")
                else:
                    raise ValueError("Unable convert sequence into array of Java primitive types")
            elif isinstance(arg, (JavaInstance, JavaProxy)):
                arg_types.append(arg.__class__.__dict__['_alternates'])
            else:
                raise ValueError("Unknown argument type", arg, type(arg))
        arg_sig = b''.join(t[0] for t in arg_types)
        options = list(itertools.product(*arg_types))
    for option in options:
        try:
            return arg_sig, option, polymorphs[b''.join(option)]
        except KeyError:
            pass
    raise KeyError(arg_sig)
def select_polymorph ( polymorphs , args ) : arg_types = [ ] if len ( args ) == 0 : arg_sig = b'' options = [ [ ] ] else : for arg in args : if isinstance ( arg , ( bool , jboolean ) ) : arg_types . append ( [ b'Z' ] ) elif isinstance ( arg , jbyte ) : arg_types . append ( [ b'B' ] ) elif isinstance ( arg , jchar ) : arg_types . append ( [ b'C' ] ) elif isinstance ( arg , jshort ) : arg_types . append ( [ b'S' ] ) elif isinstance ( arg , jint ) : arg_types . append ( [ b'I' ] ) elif isinstance ( arg , int ) : arg_types . append ( [ b'I' , b'J' , b'S' ] ) elif isinstance ( arg , jlong ) : arg_types . append ( [ b'J' ] ) elif isinstance ( arg , jfloat ) : arg_types . append ( [ b'F' ] ) elif isinstance ( arg , float ) : arg_types . append ( [ b'D' , b'F' ] ) elif isinstance ( arg , jdouble ) : arg_types . append ( [ b'D' ] ) elif isinstance ( arg , str ) : arg_types . append ( [ b"Ljava/lang/String;" , b"Ljava/io/Serializable;" , b"Ljava/lang/Comparable;" , b"Ljava/lang/CharSequence;" , b"Ljava/lang/Object;" , ] ) elif isinstance ( arg , bytes ) : arg_types . append ( [ b'[B' ] ) elif isinstance ( arg , Sequence ) and len ( arg ) > 0 : if isinstance ( arg [ 0 ] , ( bool , jboolean ) ) : if all ( ( isinstance ( item , ( bool , jboolean ) ) for item in arg ) ) : arg_types . append ( [ b'[Z' ] ) else : raise ValueError ( "Convert entire list to bool/jboolean to create a Java boolean array" ) elif isinstance ( arg [ 0 ] , ( int , jint ) ) : if all ( ( isinstance ( item , ( int , jint ) ) for item in arg ) ) : arg_types . append ( [ b'[I' ] ) else : raise ValueError ( "Unable to treat all data in list as integers" ) elif isinstance ( arg [ 0 ] , ( float , jfloat , jdouble ) ) : if all ( ( isinstance ( item , ( float , jfloat , jdouble ) ) for item in arg ) ) : arg_types . append ( [ b'[D' , b'[F' ] ) else : raise ValueError ( "Unable to treat all data in list as floats/doubles" ) else : raise ValueError ( "Unable convert sequence into array of Java primitive types" ) elif isinstance ( arg , ( JavaInstance , JavaProxy ) ) : arg_types . append ( arg . __class__ . __dict__ [ '_alternates' ] ) else : raise ValueError ( "Unknown argument type" , arg , type ( arg ) ) arg_sig = b'' . join ( t [ 0 ] for t in arg_types ) options = list ( itertools . product ( * arg_types ) ) for option in options : try : return arg_sig , option , polymorphs [ b'' . join ( option ) ] except KeyError : pass raise KeyError ( arg_sig )
Determine the polymorphic signature that will match a given argument list.
Determine the polymorphic signature that will match a given argument list .
"""Determine the polymorphic signature that will match a given argument list.
    This is the mechanism used to reconcile Java's strict-typing polymorphism with
    Python's unique-name, weak typing polymorphism. When invoking a method on the
    Python side, the number and types of the arguments provided are used to determine
    which Java method will be invoked.
    polymorphs should be a dictionary, keyed by the JNI signature of the arguments
    expected by the method. The values in the dictionary are not used; this method
    is only used to determine, which key should be used.
    args is a list of arguments that have been passed to invoke the method.
    Returns a 3-tuple:
     * arg_sig - the actual signature of the provided arguments
     * match_types - the type list that was matched. This is a list of individual
       type signatures; not in string form like arg_sig, but as a list where each
       element is the type for a particular argument. (i.e.,
        [b'I', b'Ljava/lang/String;', b'Z'], not b'ILjava/langString;Z').
       The contents of match_types will be the same as arg_sig if there is a
       direct match in polymorphs; if there isn't, the signature of the matching
       polymorph will be returned.
     * polymorph - the value from the input polymorphs that matched. Equivalent
       to polymorphs[match_types]
    """ # If char arrays are useful to handle, add them later. Handle all other types of primitive type arrays. # If arg is an iterable of all the same basic numeric type, then # an array of that Java type can work.
polymorphs
args