Protocol { public final static Object getObject(String commandPart, Gateway gateway) { if (isEmpty(commandPart) || isEnd(commandPart)) { throw new Py4JException("Command Part is Empty or is the End of Command Part"); } else { switch (commandPart.charAt(0)) { case BOOLEAN_TYPE: return getBoolean(commandPart); case DOUBLE_TYPE: return getDouble(commandPart); case LONG_TYPE: return getLong(commandPart); case INTEGER_TYPE: try { return getInteger(commandPart); } catch (NumberFormatException e) { return getLong(commandPart); } case BYTES_TYPE: return getBytes(commandPart); case NULL_TYPE: return getNull(commandPart); case VOID: return getNull(commandPart); case REFERENCE_TYPE: return getReference(commandPart, gateway); case STRING_TYPE: return getString(commandPart); case DECIMAL_TYPE: return getDecimal(commandPart); case PYTHON_PROXY_TYPE: return getPythonProxy(commandPart, gateway); default: throw new Py4JException("Command Part is unknown: " + commandPart); } } }  static String encodeBytes(byte[] bytes); final static boolean getBoolean(String commandPart); final static byte[] getBytes(String commandPart); final static BigDecimal getDecimal(String commandPart); final static double getDouble(String commandPart); final static int getInteger(String commandPart); final static long getLong(String commandPart); final static String getMemberOutputCommand(char memberType); final static String getMemberOutputCommand(char memberType, String fqn); static String getNoSuchFieldOutputCommand(); final static Object getNull(String commandPart); final static Object getObject(String commandPart, Gateway gateway); final static String getOutputCommand(ReturnObject rObject); final static String getOutputErrorCommand(); final static String getOutputErrorCommand(String errorMessage); final static String getOutputErrorCommand(Throwable throwable); final static String getOutputFatalErrorCommand(Throwable throwable); final static String getOutputVoidCommand(); final static String getAuthCommand(String authToken); static char getPrimitiveType(Object primitiveObject); static Object getPythonProxy(String commandPart, Gateway gateway); static Object getPythonProxyHandler(ClassLoader classLoader, Class[] interfacesToImplement, String objectId,
			Gateway gateway); final static Object getReference(String commandPart, Gateway gateway); final static Object getReturnValue(String returnMessage, Gateway gateway); final static Throwable getRootThrowable(Throwable throwable, boolean skipInvocation); final static String getString(String commandPart); final static String getThrowableAsString(Throwable throwable); final static boolean isBoolean(String commandPart); final static boolean isReturnMessage(String commandPart); final static boolean isBytes(String commandPart); final static boolean isDecimal(String commandPart); final static boolean isDouble(String commandPart); final static boolean isEmpty(String commandPart); final static boolean isEnd(String commandPart); final static boolean isError(String returnMessage); final static boolean isInteger(String commandPart); final static boolean isLong(String commandPart); final static boolean isNull(String commandPart); final static boolean isPythonProxy(String commandPart); final static boolean isReference(String commandPart); final static boolean isString(String commandPart); final static char BYTES_TYPE; final static char INTEGER_TYPE; final static char LONG_TYPE; final static char BOOLEAN_TYPE; final static char DOUBLE_TYPE; final static char DECIMAL_TYPE; final static char STRING_TYPE; final static char REFERENCE_TYPE; final static char LIST_TYPE; final static char SET_TYPE; final static char ARRAY_TYPE; final static char MAP_TYPE; final static char ITERATOR_TYPE; final static char NULL_TYPE; final static char PYTHON_PROXY_TYPE; final static char PACKAGE_TYPE; final static char CLASS_TYPE; final static char METHOD_TYPE; final static char NO_MEMBER; final static char VOID; final static char RETURN_MESSAGE; final static char END; final static char END_OUTPUT; final static char ERROR; final static char FATAL_ERROR; final static char SUCCESS; final static String AUTH_COMMAND_NAME; final static String ERROR_COMMAND; final static String VOID_COMMAND; final static String NO_SUCH_FIELD; final static String ENTRY_POINT_OBJECT_ID; final static String DEFAULT_JVM_OBJECT_ID; final static String GATEWAY_SERVER_ID; final static String STATIC_PREFIX; final static String PYTHON_NAN; final static String PYTHON_INFINITY; final static String PYTHON_NEGATIVE_INFINITY; }
@Test public void testGetObject() { Gateway gateway = new Gateway(null); Object obj1 = new Object(); gateway.putObject("o123", obj1); assertEquals(1, Protocol.getObject("i1", null)); assertEquals(true, Protocol.getObject("bTrue", null)); assertEquals(1.234, (Double) Protocol.getObject("d1.234", null), 0.001); assertEquals(obj1, Protocol.getObject("ro123", gateway)); assertEquals("Hello\nWorld\t", Protocol.getObject("sHello\\nWorld\t", null)); assertEquals(123l, Protocol.getObject("L123", null)); assertEquals(new BigDecimal("-14.456"), Protocol.getObject("D-14.456", null)); assertNull(Protocol.getObject("n", null)); try { Protocol.getObject(null, null); fail(); } catch (Py4JException e) { assertTrue(true); } try { Protocol.getObject("", null); fail(); } catch (Py4JException e) { assertTrue(true); } try { Protocol.getObject("e", null); fail(); } catch (Py4JException e) { assertTrue(true); } try { Protocol.getObject("z123", null); fail(); } catch (Py4JException e) { assertTrue(true); } }