Issue #2250 add array functionality checking to JUtil

Change-Id: Iffb4ba9dedd23641de82d99550e2b0473f4a5d23

Former-commit-id: 2ed6658f4a [formerly 57681b27b9 [formerly a09ef5f2bad2a83394ec9a5f0dbb2edd4df0b961]]
Former-commit-id: 57681b27b9
Former-commit-id: a5db9ddb3f
This commit is contained in:
Matt Nash 2013-08-23 11:07:18 -05:00
parent c56cfb7e92
commit 3d871bef4c
2 changed files with 102 additions and 34 deletions

View file

@ -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();
}
}

View file

@ -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 Collections
from java.util import Date
from java.lang.reflect import Array
from collections import OrderedDict
from shapely.geometry.base import BaseGeometry
from shapely import wkt
import jep
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
@ -44,6 +51,7 @@ import datetime
#
#
JEP_ARRAY_TYPE = type(jep.jarray(0,Object))
def javaStringListToPylist(jlist):
pylist = []
@ -132,13 +140,17 @@ def pyValToJavaObj(val):
retObj = pyDictToJavaMap(val)
elif issubclass(valtype, JavaWrapperClass):
retObj = val.toJavaObj()
elif issubclass(valtype, BaseGeometry):
reader = WKBReader()
retObj = reader.read(val.to_wkb)
return retObj
def javaObjToPyVal(obj, customConverter=None):
retVal = None
if obj is None:
return retVal
# handle pyjobjects
if hasattr(obj, 'jclassname'):
objtype = obj.jclassname
if objtype == "java.lang.Integer":
retVal = obj.intValue()
@ -152,11 +164,12 @@ def javaObjToPyVal(obj, customConverter=None):
retVal = obj.doubleValue()
elif objtype == "java.util.Date":
retVal = datetime.datetime.fromtimestamp(obj.getTime() / 1000)
elif isinstance(obj, type(jep.jarray(0, Object))):
retVal = []
size = len(obj)
for i in range(size):
retVal.append(javaObjToPyVal(obj.get(i), customConverter))
elif objtype in ["com.vividsolutions.jts.geom.Geometry", "com.vividsolutions.jts.geom.GeometryCollection",
"com.vividsolutions.jts.geom.Polygon", "com.vividsolutions.jts.geom.MultiPolygon",
"com.vividsolutions.jts.geom.LineString", "com.vividsolutions.jts.geom.MultiLineString",
"com.vividsolutions.jts.geom.Point", "com.vividsolutions.jts.geom.MultiPoint",
"com.vividsolutions.jts.geom.LinearRing"] :
retVal = wkt.loads(obj.toText())
elif objtype in ["java.util.ArrayList", "java.util.Arrays$ArrayList"]:
retVal = []
size = obj.size()
@ -170,11 +183,21 @@ def javaObjToPyVal(obj, customConverter=None):
retVal = tuple(tempList)
elif objtype == "java.util.HashMap":
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:
retVal = customConverter(obj)
if retVal is None:
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
class JavaWrapperClass(object):