Merge "Issue #2250 add array functionality checking to JUtil" into development
Former-commit-id:796bd10c81
[formerly2e42aaccad
[formerlye214710122
] [formerly796bd10c81
[formerly 96ba088c29bf105688fbcad5bdfa620cf1875b14]]] Former-commit-id:2e42aaccad
[formerlye214710122
] Former-commit-id:2e42aaccad
Former-commit-id:da447be5e3
This commit is contained in:
commit
5e29af9868
2 changed files with 102 additions and 34 deletions
|
@ -0,0 +1,45 @@
|
||||||
|
/**
|
||||||
|
* This software was developed and / or modified by Raytheon Company,
|
||||||
|
* pursuant to Contract DG133W-05-CQ-1067 with the US Government.
|
||||||
|
*
|
||||||
|
* U.S. EXPORT CONTROLLED TECHNICAL DATA
|
||||||
|
* This software product contains export-restricted data whose
|
||||||
|
* export/transfer/disclosure is restricted by U.S. law. Dissemination
|
||||||
|
* to non-U.S. persons whether in the United States or abroad requires
|
||||||
|
* an export license or other authorization.
|
||||||
|
*
|
||||||
|
* Contractor Name: Raytheon Company
|
||||||
|
* Contractor Address: 6825 Pine Street, Suite 340
|
||||||
|
* Mail Stop B8
|
||||||
|
* Omaha, NE 68106
|
||||||
|
* 402.291.0100
|
||||||
|
*
|
||||||
|
* See the AWIPS II Master Rights File ("Master Rights File.pdf") for
|
||||||
|
* further licensing information.
|
||||||
|
**/
|
||||||
|
package com.raytheon.uf.common.python;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Home for methods that can't be done from Python on PyJObjects but need to be
|
||||||
|
* done on Java objects.
|
||||||
|
*
|
||||||
|
* <pre>
|
||||||
|
*
|
||||||
|
* SOFTWARE HISTORY
|
||||||
|
*
|
||||||
|
* Date Ticket# Engineer Description
|
||||||
|
* ------------ ---------- ----------- --------------------------
|
||||||
|
* Aug 22, 2013 mnash Initial creation
|
||||||
|
*
|
||||||
|
* </pre>
|
||||||
|
*
|
||||||
|
* @author mnash
|
||||||
|
* @version 1.0
|
||||||
|
*/
|
||||||
|
|
||||||
|
public class PyJavaUtil {
|
||||||
|
|
||||||
|
public static boolean isArray(Object obj) {
|
||||||
|
return obj.getClass().isArray();
|
||||||
|
}
|
||||||
|
}
|
|
@ -23,10 +23,17 @@ from java.lang import Integer, Float, Long, Boolean, String, Object, Double
|
||||||
from java.util import HashMap, LinkedHashMap, ArrayList
|
from java.util import HashMap, LinkedHashMap, ArrayList
|
||||||
from java.util import Collections
|
from java.util import Collections
|
||||||
from java.util import Date
|
from java.util import Date
|
||||||
|
from java.lang.reflect import Array
|
||||||
from collections import OrderedDict
|
from collections import OrderedDict
|
||||||
|
|
||||||
|
from shapely.geometry.base import BaseGeometry
|
||||||
|
from shapely import wkt
|
||||||
|
|
||||||
import jep
|
import jep
|
||||||
import datetime
|
import datetime
|
||||||
|
from com.vividsolutions.jts.io import WKTReader
|
||||||
|
from com.raytheon.uf.common.python import PyJavaUtil
|
||||||
|
from org.apache.commons.lang import ArrayUtils
|
||||||
|
|
||||||
#
|
#
|
||||||
# Provides convenience methods for Java-Python bridging
|
# Provides convenience methods for Java-Python bridging
|
||||||
|
@ -44,6 +51,7 @@ import datetime
|
||||||
#
|
#
|
||||||
#
|
#
|
||||||
|
|
||||||
|
JEP_ARRAY_TYPE = type(jep.jarray(0,Object))
|
||||||
|
|
||||||
def javaStringListToPylist(jlist):
|
def javaStringListToPylist(jlist):
|
||||||
pylist = []
|
pylist = []
|
||||||
|
@ -132,13 +140,17 @@ def pyValToJavaObj(val):
|
||||||
retObj = pyDictToJavaMap(val)
|
retObj = pyDictToJavaMap(val)
|
||||||
elif issubclass(valtype, JavaWrapperClass):
|
elif issubclass(valtype, JavaWrapperClass):
|
||||||
retObj = val.toJavaObj()
|
retObj = val.toJavaObj()
|
||||||
|
elif issubclass(valtype, BaseGeometry):
|
||||||
|
reader = WKBReader()
|
||||||
|
retObj = reader.read(val.to_wkb)
|
||||||
return retObj
|
return retObj
|
||||||
|
|
||||||
def javaObjToPyVal(obj, customConverter=None):
|
def javaObjToPyVal(obj, customConverter=None):
|
||||||
retVal = None
|
retVal = None
|
||||||
if obj is None:
|
if obj is None:
|
||||||
return retVal
|
return retVal
|
||||||
|
# handle pyjobjects
|
||||||
|
if hasattr(obj, 'jclassname'):
|
||||||
objtype = obj.jclassname
|
objtype = obj.jclassname
|
||||||
if objtype == "java.lang.Integer":
|
if objtype == "java.lang.Integer":
|
||||||
retVal = obj.intValue()
|
retVal = obj.intValue()
|
||||||
|
@ -152,11 +164,12 @@ def javaObjToPyVal(obj, customConverter=None):
|
||||||
retVal = obj.doubleValue()
|
retVal = obj.doubleValue()
|
||||||
elif objtype == "java.util.Date":
|
elif objtype == "java.util.Date":
|
||||||
retVal = datetime.datetime.fromtimestamp(obj.getTime() / 1000)
|
retVal = datetime.datetime.fromtimestamp(obj.getTime() / 1000)
|
||||||
elif isinstance(obj, type(jep.jarray(0, Object))):
|
elif objtype in ["com.vividsolutions.jts.geom.Geometry", "com.vividsolutions.jts.geom.GeometryCollection",
|
||||||
retVal = []
|
"com.vividsolutions.jts.geom.Polygon", "com.vividsolutions.jts.geom.MultiPolygon",
|
||||||
size = len(obj)
|
"com.vividsolutions.jts.geom.LineString", "com.vividsolutions.jts.geom.MultiLineString",
|
||||||
for i in range(size):
|
"com.vividsolutions.jts.geom.Point", "com.vividsolutions.jts.geom.MultiPoint",
|
||||||
retVal.append(javaObjToPyVal(obj.get(i), customConverter))
|
"com.vividsolutions.jts.geom.LinearRing"] :
|
||||||
|
retVal = wkt.loads(obj.toText())
|
||||||
elif objtype in ["java.util.ArrayList", "java.util.Arrays$ArrayList"]:
|
elif objtype in ["java.util.ArrayList", "java.util.Arrays$ArrayList"]:
|
||||||
retVal = []
|
retVal = []
|
||||||
size = obj.size()
|
size = obj.size()
|
||||||
|
@ -170,11 +183,21 @@ def javaObjToPyVal(obj, customConverter=None):
|
||||||
retVal = tuple(tempList)
|
retVal = tuple(tempList)
|
||||||
elif objtype == "java.util.HashMap":
|
elif objtype == "java.util.HashMap":
|
||||||
retVal = javaMapToPyDict(obj, customConverter)
|
retVal = javaMapToPyDict(obj, customConverter)
|
||||||
|
elif PyJavaUtil.isArray(obj):
|
||||||
|
retVal = []
|
||||||
|
size = Array.getLength(obj)
|
||||||
|
for i in range(size):
|
||||||
|
retVal.append(javaObjToPyVal(Array.get(obj, i), customConverter))
|
||||||
elif customConverter is not None:
|
elif customConverter is not None:
|
||||||
retVal = customConverter(obj)
|
retVal = customConverter(obj)
|
||||||
|
|
||||||
if retVal is None:
|
if retVal is None:
|
||||||
retVal = str(obj)
|
retVal = str(obj)
|
||||||
|
# test for jep array type
|
||||||
|
elif isinstance(obj, JEP_ARRAY_TYPE):
|
||||||
|
retVal = []
|
||||||
|
size = len(obj)
|
||||||
|
for i in range(size):
|
||||||
|
retVal.append(javaObjToPyVal(obj[i], customConverter))
|
||||||
return retVal
|
return retVal
|
||||||
|
|
||||||
class JavaWrapperClass(object):
|
class JavaWrapperClass(object):
|
||||||
|
|
Loading…
Add table
Reference in a new issue