Mistři v programování na #hovnokod

Java #3848

musel jsem to zkrátit, nevešlo se celé

private static Map<String, Object> getMap(Map<Object,Map<String, Object>> alreadyMappedObject, Object v) {
    Map<String, Object> map = new HashMap<>();
    Method[] methods = v.getClass().getMethods();
    for (Method m : methods) {
        String name = m.getName();
        Class<?> returnType = m.getReturnType();
        if (Modifier.isPublic(m.getModifiers()) 
        && !Modifier.isStatic(m.getModifiers()) 
        && m.getParameterTypes().length == 0 
        && isTypeSupported(returnType)
        && isMethodSupported(name, returnType)) {
            String fieldName = getFieldName(name);
            Object value = null;
            try {
                m.setAccessible(true);
                value = m.invoke(v, (Object[]) null);
            } catch (IllegalAccessException e) {
                logger.warning("IllegalAccessException in getMap()", e);
            } catch (InvocationTargetException e) {
                logger.warning("InvocationTargetException in getMap()", e);
            }

            if (returnType.equals(List.class)){
                // WARN: It is a list of primitive, don't think we should recurse but have no use case for that yet...
                List<Map<String, Object>> subList = new ArrayList<Map<String, Object>>();
                List<Object> list = (List<Object>) value;
                if (list != null)
                {
                    for (Object o : list)
                    {
                        // Recurse
                        subList.add(getSubMap(alreadyMappedObject, o));
                    }
                }
                map.put(fieldName, subList);
            }
            else if (returnType.equals(Map.class))
            {
                // We have a map in the current class (like in DynamicDisplayInfo).
                map.put(fieldName, value);
            }
            else if (returnType.equals(Class.class))
            {
                // Need the class name so we can differenciate class types.
                map.put(fieldName, ((Class)value).getSimpleName());
            }
            else if (returnType.equals(String.class) 
                  || returnType.equals(boolean.class) 
                  || returnType.equals(Boolean.class) 
                  || returnType.equals(int.class)
                  || returnType.equals(Integer.class) 
                  || returnType.equals(long.class)
                  || returnType.equals(Long.class) 
                  || returnType.equals(float.class)
                  || returnType.equals(Float.class) 
                  || returnType.equals(short.class)
                  || returnType.equals(Short.class) 
                  || returnType.equals(double.class)
                  || returnType.equals(Double.class) 
                  || returnType.equals(char.class))
            {
                map.put(fieldName, value);
            }
            else if(returnType.equals(File.class))
            {
                map.put(fieldName, ((File)value).getAbsolutePath());
            }
            else
            {
                // Insurance policy: Only recurse if it is our object.
                if(value != null
                && returnType.getName().startsWith(PACKAGE))
                {
                    // Recurse
                    map.put(fieldName, getSubMap(alreadyMappedObject, value));
                }}}}
    return map;
}

Anonymous,