All Downloads are FREE. Search and download functionalities are using the official Maven repository.

home.lib.jython.alertlib.Mapper.py Maven / Gradle / Ivy

There is a newer version: 1.10.2
Show newest version
from java import util
#http://www.ibm.com/developerworks/java/tutorials/j-jython2/section7.html
#class Mapper:
def mapMapFromJava (map):
    """ Convert a Map to a Dictionary. """
    result = {}
    iter = map.keySet().iterator()
    while iter.hasNext():
        key = iter.next()
        result[mapFromJava(key)] = mapFromJava(map.get(key))
    return result

def mapCollectionFromJava (coll):
    """ Convert a Collection to a List. """
    result = []
    iter = coll.iterator();
    while iter.hasNext():
        result.append(mapFromJava(iter.next()))
    return result

def mapFromJava (object):
    """ Convert a Java type to a Jython type. """
    if object is None: return object
    if   isinstance(object, util.Map):        
        result = mapMapFromJava(object)
    elif isinstance(object, util.Collection): 
        result = mapCollectionFromJava(object)
    else:                                     
        result = object
    return result




© 2015 - 2024 Weber Informatics LLC | Privacy Policy