从unit的入参argMap内get元素取值，如果不存在取值，那么返回给定的默认值，返回类型为泛型；
注意，此方法仅仅是为了方便使用，不能保证类型转换不出问题，需要调用者来保证类型转换正确性。

@throws ClassCastException 类型转换异常
965214
public <T> T get(String key, T defaultValue) {
        T value = get(key);
        if (value == null) {
            return defaultValue;
        }
        return value;
    }
695072
private Map<String, InnerClassAccess> getAccessMapForClass(String className) throws ClassNotFoundException {

        Map<String, InnerClassAccess> map = classToAccessMap.get(className);
        if (map == null) {
            map = new HashMap<>(3);

            if (!className.startsWith("[")) {
                JavaClass javaClass = Repository.lookupClass(className);

                Method[] methodList = javaClass.getMethods();
                for (Method method : methodList) {
                    String methodName = method.getName();
                    if (!methodName.startsWith("access$")) {
                        continue;
                    }

                    Code code = method.getCode();
                    if (code == null) {
                        continue;
                    }

                    if (DEBUG) {
                        System.out.println("Analyzing " + className + "." + method.getName()
                                + " as an inner-class access method...");
                    }

                    byte[] instructionList = code.getCode();
                    String methodSig = method.getSignature();
                    InstructionCallback callback = new InstructionCallback(javaClass, methodName, methodSig, instructionList);
                    //                    try {
                    new BytecodeScanner().scan(instructionList, callback);
                    //                    } catch (LookupFailure lf) {
                    //                        throw lf.getException();
                    //                    }
                    InnerClassAccess access = callback.getAccess();
                    if (DEBUG) {
                        System.out.println((access != null ? "IS" : "IS NOT") + " an inner-class access method");
                    }
                    if (access != null) {
                        map.put(methodName, access);
                    }
                }
            }

            if (map.size() == 0) {
                map = Collections.emptyMap();
            } else {
                map = new HashMap<>(map);
            }

            classToAccessMap.put(className, map);
        }

        return map;
    }
769750
private Class<?>[] getTypes(Object[] args) {
        if (args == null || args.length == 0) {
            return null;
        }
        List<Class<?>> classList = new ArrayList<Class<?>>();
        for (Object obj : args) {
            classList.add(obj == null ? Object.class : obj.getClass());
        }
        return classList.toArray(new Class[] {});
    }
573616
public T argMax() {
        double maxCount = -Double.MAX_VALUE;
        T maxKey = null;
        for (Map.Entry<T, AtomicDouble> entry : map.entrySet()) {
            if (entry.getValue().get() > maxCount || maxKey == null) {
                maxKey = entry.getKey();
                maxCount = entry.getValue().get();
            }
        }
        return maxKey;
    }
918658
public static Class<?>[] collectArgTypes(final Object[] args) {
        final Class<?>[] result = new Class<?>[args.length];
        collectArgTypes(args, result, 0, 0, args.length);
        return result;
    }
54129
public Map<String, String> getArgMap(){
		Map<String, String> ret = new LinkedHashMap<String, String>();
		String[] ar = StringUtils.split(this.getArgs(), ',');
		if(ar!=null){
			for(String s : ar){
				String[] kv = StringUtils.split(s, ":", 2);
				if(kv!=null && kv.length==2){
					ret.put(StringUtils.trim(kv[0]), StringUtils.trim(kv[1]));
				}
				else{
					//TODO error log?
				}
			}
		}
		return ret;
	}
753793
@SuppressWarnings("unchecked")
	public static <T> T cast(Object obj, Class<T> clazz) {
		// 已经是同类型的就不用转
		if(obj != null && clazz.isInstance(obj)) {
			return (T) obj;
		}
		
		// 对于obj是null但是目标clazz是【基础类型】时，转成 0
		if(clazz == Integer.class || clazz == int.class) {
			if(obj == null) {
				return clazz == int.class ? (T) new Integer(0) : null;
			}
			if(obj instanceof Integer) {
				return (T) obj;
			}
			return (T) new Integer(obj.toString());
		}
		if(clazz == Long.class || clazz == long.class) {
			if(obj == null) {
				return clazz == long.class ? (T) new Long(0L) : null;
			}
			if(obj instanceof Long) {
				return (T) obj;
			}
			return (T) new Long(obj.toString());
		}
		if(clazz == Byte.class || clazz == byte.class) {
			if(obj == null) {
				return clazz == byte.class ? (T) new Byte((byte)0) : null;
			}
			if(obj instanceof Byte) {
				return (T) obj;
			}
			return (T) new Byte(obj.toString());
		}
		if(clazz == Character.class || clazz == char.class) {
			if(obj == null) {
				return clazz == char.class ? (T) new Character((char)0) : null;
			}
			if(obj instanceof Character) {
				return (T) obj;
			}
			return (T) new Character((char)0); // char没有办法从其它类型转
		}
		if(clazz == Short.class || clazz == short.class) {
			if(obj == null) {
				return clazz == short.class ? (T) new Short((short)0) : null;
			}
			if(obj instanceof Short) {
				return (T) obj;
			}
			return (T) new Short(obj.toString());
		}
		if(clazz == Boolean.class || clazz == boolean.class) {
			if(obj == null) {
				return clazz == boolean.class ? (T) new Boolean(false) : null;
			}
			if(obj instanceof Boolean) {
				return (T) obj;
			}
			if(obj instanceof Number) {
				return (T) new Boolean(((Number) obj).intValue() != 0);
			}
			return (T) new Boolean(obj.toString());
		}
		if(clazz == Float.class || clazz == float.class) {
			if(obj == null) {
				return clazz == float.class ? (T) new Float(0f) : null;
			}
			if(obj instanceof Float) {
				return (T) obj;
			}
			return (T) new Float(obj.toString());
		}
		if(clazz == Double.class || clazz == double.class) {
			if(obj == null) {
				return clazz == double.class ? (T) new Double(0d) : null;
			}
			if(obj instanceof Double) {
				return (T) obj;
			}
			return (T) new Double(obj.toString());
		}
		
		if(obj == null) {
			return null;
		}
		
		if(clazz == String.class) {
			return (T) obj.toString();
		}
		if(clazz == BigDecimal.class) {
			return (T) new BigDecimal(obj.toString());
		}
		if (clazz == java.sql.Date.class && obj instanceof java.util.Date) {
			return (T) new java.sql.Date(((java.util.Date)obj).getTime());
		}
		
		// TODO 可能还有更多的类型需要转换
		
		return (T) obj;
	}
561376
public <T extends DajlabModelInterface> T get(Class<T> clazz) {

		T ret = null;
		try {
			ret = (T) dajlab.get(clazz.getName());
		} catch (ClassCastException e) {
			e.printStackTrace();
		}
		return ret;
	}
1285347
private RequestArguments.Argument arg(Request R) {
      if( _arg != null ) return _arg;
      Class clzz = R.getClass();
      // An amazing crazy API from the JDK again.  Cannot search for protected
      // fields without either (1) throwing NoSuchFieldException if you ask in
      // a subclass, or (2) sorting through the list of ALL fields and EACH
      // level of the hierarchy.  Sadly, I catch NSFE & loop.
      while( true ) {
        try {
          Field field = clzz.getDeclaredField(_name);
          field.setAccessible(true);
          Object o = field.get(R);
          return _arg=((RequestArguments.Argument)o);
        }
        catch(   NoSuchFieldException ie ) { clzz = clzz.getSuperclass(); }
        catch( IllegalAccessException ie ) { break; }
        catch( ClassCastException ie ) { break; }
      }
      return null;
    }
1066150
@SuppressWarnings("rawtypes")
    public static void populateArgumentsForCriteria(AbstractHibernateDatastore datastore, Class<?> targetClass, Criteria c, Map argMap, ConversionService conversionService, boolean useDefaultMapping) {
        Integer maxParam = null;
        Integer offsetParam = null;
        if (argMap.containsKey(ARGUMENT_MAX)) {
            maxParam = conversionService.convert(argMap.get(ARGUMENT_MAX),Integer.class);
        }
        if (argMap.containsKey(ARGUMENT_OFFSET)) {
            offsetParam = conversionService.convert(argMap.get(ARGUMENT_OFFSET),Integer.class);
        }
        if (argMap.containsKey(ARGUMENT_FETCH_SIZE)) {
            c.setFetchSize(conversionService.convert(argMap.get(ARGUMENT_FETCH_SIZE),Integer.class));
        }
        if (argMap.containsKey(ARGUMENT_TIMEOUT)) {
            c.setTimeout(conversionService.convert(argMap.get(ARGUMENT_TIMEOUT),Integer.class));
        }
        if (argMap.containsKey(ARGUMENT_FLUSH_MODE)) {
            c.setFlushMode(convertFlushMode(argMap.get(ARGUMENT_FLUSH_MODE)));
        }
        if (argMap.containsKey(ARGUMENT_READ_ONLY)) {
            c.setReadOnly(ClassUtils.getBooleanFromMap(ARGUMENT_READ_ONLY, argMap));
        }
        String orderParam = (String)argMap.get(ARGUMENT_ORDER);
        Object fetchObj = argMap.get(ARGUMENT_FETCH);
        if (fetchObj instanceof Map) {
            Map fetch = (Map)fetchObj;
            for (Object o : fetch.keySet()) {
                String associationName = (String) o;
                c.setFetchMode(associationName, getFetchMode(fetch.get(associationName)));
            }
        }

        final int max = maxParam == null ? -1 : maxParam;
        final int offset = offsetParam == null ? -1 : offsetParam;
        if (max > -1) {
            c.setMaxResults(max);
        }
        if (offset > -1) {
            c.setFirstResult(offset);
        }
        if (ClassUtils.getBooleanFromMap(ARGUMENT_LOCK, argMap)) {
            c.setLockMode(LockMode.PESSIMISTIC_WRITE);
            c.setCacheable(false);
        }
        else {
            if (argMap.containsKey(ARGUMENT_CACHE)) {
                c.setCacheable(ClassUtils.getBooleanFromMap(ARGUMENT_CACHE, argMap));
            } else {
                cacheCriteriaByMapping(targetClass, c);
            }
        }

        final Object sortObj = argMap.get(ARGUMENT_SORT);
        if (sortObj != null) {
            boolean ignoreCase = true;
            Object caseArg = argMap.get(ARGUMENT_IGNORE_CASE);
            if (caseArg instanceof Boolean) {
                ignoreCase = (Boolean) caseArg;
            }
            if (sortObj instanceof Map) {
                Map sortMap = (Map) sortObj;
                for (Object sort : sortMap.keySet()) {
                    final String order = ORDER_DESC.equalsIgnoreCase((String) sortMap.get(sort)) ? ORDER_DESC : ORDER_ASC;
                    addOrderPossiblyNested(datastore, c, targetClass, (String) sort, order, ignoreCase);
                }
            } else {
                final String sort = (String) sortObj;
                final String order = ORDER_DESC.equalsIgnoreCase(orderParam) ? ORDER_DESC : ORDER_ASC;
                addOrderPossiblyNested(datastore, c, targetClass, sort, order, ignoreCase);
            }
        }
        else if (useDefaultMapping) {
            Mapping m = GrailsDomainBinder.getMapping(targetClass);
            if (m != null) {
                Map sortMap = m.getSort().getNamesAndDirections();
                for (Object sort : sortMap.keySet()) {
                    final String order = ORDER_DESC.equalsIgnoreCase((String) sortMap.get(sort)) ? ORDER_DESC : ORDER_ASC;
                    addOrderPossiblyNested(datastore, c, targetClass, (String) sort, order, true);
                }
            }
        }
    }
577840
public <T> T getArgBean(Class<? extends T> beanClass) {
        return Reflection.toType(argMap, beanClass);
    }
307630
static String getArgumentTypesAsString(Object... arguments) {
        StringBuilder argumentsAsString = new StringBuilder();
        final String noParameters = "<none>";
        if (arguments != null && arguments.length != 0) {
            for (int i = 0; i < arguments.length; i++) {
                String argumentName = null;
                Object argument = arguments[i];

                if (argument instanceof Class<?>) {
                    argumentName = ((Class<?>) argument).getName();
                } else if (argument instanceof Class<?>[] && arguments.length == 1) {
                    Class<?>[] argumentArray = (Class<?>[]) argument;
                    if (argumentArray.length > 0) {
                        for (int j = 0; j < argumentArray.length; j++) {
                            appendArgument(argumentsAsString, j,
                                    argumentArray[j] == null ? "null" : getUnproxyType(argumentArray[j]).getName(),
                                    argumentArray);
                        }
                        return argumentsAsString.toString();
                    } else {
                        argumentName = noParameters;
                    }
                } else if (argument == null) {
                    argumentName = "null";
                } else {
                    argumentName = getUnproxyType(argument).getName();
                }
                appendArgument(argumentsAsString, i, argumentName, arguments);
            }
        } else {
            argumentsAsString.append("<none>");
        }
        return argumentsAsString.toString();
    }
409693
private String getMethodArgs(Method m)
    {
        StringBuffer sb = new StringBuffer();
        Class [] argTypes = m.getParameterTypes();
        for (int i = 0; i < argTypes.length; i++)
        {
            if (i != 0) sb.append(",");
            sb.append(argTypes[i].toString());
        }
        return sb.toString();
    }
894282
private Object getTarget(Map<String, Command> references) throws Exception
	{
		if (target == null)
		{
			if (isReference())
			{
				Command cmd = references.get(getAttr("idref")); //$NON-NLS-1$
				target = (cmd != null) ? cmd.getResultValue() : null;
			}
			else if (isExecutable())
			{
				String className = null;

				if (isPrimitive())
				{
					className = getPrimitiveClassName(tagName);
				}
				else if (isTag("class")) { //$NON-NLS-1$
					className = getPrimitiveClassName(tagName);
				}
				else if (isConstructor() || isStaticMethod() || isField())
				{
					className = getAttr("class"); //$NON-NLS-1$
				}
				else if (isArray())
				{
					className = getAttr("class"); //$NON-NLS-1$
					Class<?> componentType = isPrimitiveClassName(className) ? getPrimitiveClass(className) : Class.forName(className, true, Thread
							.currentThread().getContextClassLoader());
					className = Array.newInstance(componentType, 0).getClass().getName();
				}

				if (className != null)
				{
					try
					{
						target = Class.forName(className, true, Thread.currentThread().getContextClassLoader());
					}
					catch (ClassNotFoundException e)
					{
						target = Class.forName(className);
					}

					if (isField())
					{
						String fieldName = getAttr("field"); //$NON-NLS-1$
						target = ((Class<?>) target).getField(fieldName);
					}
				}
				else
				{
					throw new Exception(Messages.getString("beans.42", className)); //$NON-NLS-1$
				}
			}
			else if (ctx.isArray())
			{
				// target = ctx.getTarget(references);
				target = Class.forName("java.lang.reflect.Array"); //$NON-NLS-1$
			}
		}
		return target;
	}
364435
private static <E, T, X extends RuntimeException> List<E> convertBeans(List<T> source, Class<E> targetClass,
            Supplier<X> exceptionSupplier, boolean parallelConvert, boolean nonNullFilter) {
        Objects.requireNonNull(targetClass, "TargetClass can not be null");
        if (Objects.isNull(source)) {
            return SupplierUtil.ifNonNullThrowOrElse(exceptionSupplier, Collections::emptyList);
        }
        // 若异常提供者不为NULL，则先校验是否存在NULL对象，存在则抛出异常
        if (Objects.nonNull(exceptionSupplier)) {
            Stream<T> stream = parallelConvert ? source.parallelStream() : source.stream();
            boolean hasNullObj = stream.anyMatch(Objects::isNull);
            if (hasNullObj) {
                throw exceptionSupplier.get();
            }
        }
        // 一次性获取，避免每次转换都要查找导致的额外消耗
        Optional<T> sourceElement = source.stream().filter(Objects::nonNull).findAny();
        if (!sourceElement.isPresent()) {
            return Collections.emptyList();
        }
        Handler handler = ConverterContext.getActionHandler(sourceElement.get().getClass(), targetClass);
        log.info("Call method \"{}\"", handler.getMethod());

        Stream<T> stream = parallelConvert ? source.parallelStream() : source.stream();
        if (nonNullFilter) {
            stream = stream.filter(Objects::nonNull);
        }
        return stream.map(convertedObj -> convertBean(convertedObj, targetClass, handler)).collect(Collectors.toList());
    }
1276898
public static Class getTypeClass(Type type)
    {
        Class typeClassClass = null;

        if (type instanceof Class) {
            typeClassClass = (Class) type;
        } else if (type instanceof ParameterizedType) {
            typeClassClass = (Class) ((ParameterizedType) type).getRawType();
        } else if (type instanceof GenericArrayType) {
            Class<?> arrrayParameter = getTypeClass(((GenericArrayType) type).getGenericComponentType());
            if (arrrayParameter != null) {
                typeClassClass = Array.newInstance(arrrayParameter, 0).getClass();
            }
        }

        return typeClassClass;
    }
856159
public String getArgDecl(HashMap<String,TypeMirror> bindingMap)
    {
        StringBuffer sb = new StringBuffer();

        if ( _methodDecl.getParameters() == null )
            return "";
        
        int i = 0;
        for (ParameterDeclaration paramDecl : _methodDecl.getParameters())
        {
            TypeMirror paramType = paramDecl.getType();
            if ( paramType == null )
                return "";
                
            if (bindingMap != null && bindingMap.containsKey(paramType.toString()))
                paramType = bindingMap.get(paramType.toString());

            if (i != 0)
                sb.append(", ");
            
            sb.append(paramType.toString());

            sb.append(' ');

            // BUGBUG: when the MethodDeclaration is derived from Reflection, this seems
            // to return 'arg0' for all arguments!
            String argName = paramDecl.getSimpleName();
            if (argName.equals("arg0"))
                sb.append("arg" + i);
            else
                sb.append(argName);

            i++;
        }
        return sb.toString();
    }