/* we are casting because the Map needs to be <?, ?> but we know it is <ReturnType, RequestArgumentType> for this thread
433577
@SuppressWarnings("unchecked")
    private RequestCollapser<BatchReturnType, ResponseType, RequestArgumentType> getCollapserForUserRequest(HystrixCollapserBridge<BatchReturnType, ResponseType, RequestArgumentType> commandCollapser) {
        return (RequestCollapser<BatchReturnType, ResponseType, RequestArgumentType>) getRequestVariableForCommand(commandCollapser).get(concurrencyStrategy);
    }
1150896
public void returnVoid() {
        if (!method.returnType.equals(TypeId.VOID)) {
            throw new IllegalArgumentException("declared " + method.returnType
                    + " but returned void");
        }
        addInstruction(new PlainInsn(Rops.RETURN_VOID, sourcePosition, null,
                RegisterSpecList.EMPTY));
    }
293775
@SuppressWarnings("unchecked")
   public static <T> T convert(Object object, @NonNull Class<T> desiredType) {
      if (object == null) {
         if (desiredType != null && desiredType.isPrimitive()) {
            return Defaults.defaultValue(desiredType);
         }
         return null;
      }


      if (object instanceof Val) {
         return convert(Cast.as(object, Val.class).get(), desiredType);
      }

      //Handle Enums
      if (Enum.class.isAssignableFrom(desiredType)) {
         Class<? extends Enum> enumClass = Cast.as(desiredType);
         return Cast.as(new EnumConverter(enumClass).apply(object));
      }

      //Handle Object arrays
      if (desiredType.isArray() && !desiredType.getComponentType().isPrimitive()) {
         Class<?> componentType = desiredType.getComponentType();
         return Cast.as(new ArrayConverter<>(componentType).apply(object));
      }

      if (converters.containsKey(desiredType)) {
         Object output = converters.get(desiredType).apply(object);
         if (output == null && desiredType.isPrimitive()) {
            return Defaults.defaultValue(desiredType);
         }
         return Cast.as(output);
      }

      if (Map.class.isAssignableFrom(desiredType)) {
         return Cast.as(convert(object, desiredType, Object.class, Object.class));
      }


      T result = new NewObjectConverter<>(desiredType).apply(object);
      if (result != null) {
         return result;
      }

      if (desiredType.isAssignableFrom(object.getClass())) {
         return Cast.as(object);
      }

      log.fine("Unable to convert object of type {0} to desired type of {1}", object.getClass(), desiredType);
      return null;
   }
364321
public static <K, V> MutableMap<K, V> selectMapOnValue(Map<K, V> map, final Predicate<? super V> predicate)
    {
        MutableMap<K, V> resultMap = UnifiedMap.newMap();
        final Procedure2<K, V> mapTransferProcedure = new MapPutProcedure<K, V>(resultMap);
        Procedure2<K, V> procedure = new Procedure2<K, V>()
        {
            public void value(K key, V value)
            {
                if (predicate.accept(value))
                {
                    mapTransferProcedure.value(key, value);
                }
            }
        };
        MapIterate.forEachKeyValue(map, procedure);
        return resultMap;
    }
49816
private TypeVarToTypeMap mapTypes( TypeVarToTypeMap actualParamByVarName, IType... types )
  {
    for( int i = 0; i < types.length; i++ )
    {
      IType type = types[i];
      if( type instanceof ITypeVariableType )
      {
        actualParamByVarName.put( (ITypeVariableType)types[i], types[i] );
      }
      if( type instanceof ITypeVariableArrayType )
      {
        mapTypes( actualParamByVarName, type.getComponentType() );
      }
      if( type.isParameterizedType() )
      {
        IType[] parameters = type.getTypeParameters();
        mapTypes( actualParamByVarName, parameters );
      }
      if( type instanceof IFunctionType )
      {
        IFunctionType funType = (IFunctionType)type;
        mapTypes( actualParamByVarName, funType.getReturnType() );
        IType[] paramTypes = funType.getParameterTypes();
        for( IType paramType : paramTypes )
        {
          mapTypes( actualParamByVarName, paramType );
        }
      }
    }
    return actualParamByVarName;
  }
678844
public static boolean shouldAutoCastTo(PrimitiveType from, PrimitiveType to) {
		InternalType[] castTypes = POSSIBLE_CAST_MAP.get(from);
		if (castTypes != null) {
			for (InternalType type : POSSIBLE_CAST_MAP.get(from)) {
				if (type.equals(to)) {
					return true;
				}
			}
		}
		return false;
	}
120483
private String typeParameters(Options opt, ParameterizedType t) {
	if (t == null)
	    return "";
	StringBuffer tp = new StringBuffer(1000).append("&lt;");
	Type args[] = t.typeArguments();
	for (int i = 0; i < args.length; i++) {
	    tp.append(type(opt, args[i], true));
	    if (i != args.length - 1)
		tp.append(", ");
	}
	return tp.append("&gt;").toString();
    }
851080
@SuppressWarnings("unchecked")
    private <T> T asMockedType(@SuppressWarnings("unused") T mockObject, 
                               Object capturingImposter) 
    {
        return (T) capturingImposter;
    }
590278
private Class<?> defineMapClass(ParameterizedTypeName mapTypeName) {
		if (mapTypeName.rawType.toString().startsWith(Map.class.getCanonicalName())) {
			// it's a list
			return HashMap.class;
		} else if (mapTypeName.rawType.toString().startsWith(SortedMap.class.getCanonicalName())) {
			return TreeMap.class;
		}
		try {
			return Class.forName(mapTypeName.rawType.toString());
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
			return null;
		}
	}
1051442
private RequestDTO makeRequestDTO(String methodName, Object[] args, Class<?>[] prarameterTypes) {
        RequestDTO request = new RequestDTO();
        request.setTraceId(IdGenerator.genUUID());
        request.setMethod(methodName);
        request.setParamterTypes(MethodUtil.getArgsTypeNameArray(prarameterTypes));
        request.setParameters(args);
        return request;
    }
855710
protected static boolean typeCheckMethodArgumentWithGenerics(ClassNode parameterType, ClassNode argumentType, boolean lastArg) {
        if (UNKNOWN_PARAMETER_TYPE == argumentType) {
            // called with null
            return !isPrimitiveType(parameterType);
        }
        if (!isAssignableTo(argumentType, parameterType) && !lastArg) {
            // incompatible assignment
            return false;
        }
        if (!isAssignableTo(argumentType, parameterType) && lastArg) {
            if (parameterType.isArray()) {
                if (!isAssignableTo(argumentType, parameterType.getComponentType())) {
                    return false;
                }
            } else {
                return false;
            }
        }
        if (parameterType.isUsingGenerics() && argumentType.isUsingGenerics()) {
            GenericsType gt = GenericsUtils.buildWildcardType(parameterType);
            if (!gt.isCompatibleWith(argumentType)) {
                boolean samCoercion = isSAMType(parameterType) && argumentType.equals(CLOSURE_TYPE);
                if (!samCoercion) return false;
            }
        } else if (parameterType.isArray() && argumentType.isArray()) {
            // verify component type
            return typeCheckMethodArgumentWithGenerics(parameterType.getComponentType(), argumentType.getComponentType(), lastArg);
        } else if (lastArg && parameterType.isArray()) {
            // verify component type, but if we reach that point, the only possibility is that the argument is
            // the last one of the call, so we're in the cast of a vargs call
            // (otherwise, we face a type checker bug)
            return typeCheckMethodArgumentWithGenerics(parameterType.getComponentType(), argumentType, lastArg);
        }
        return true;
    }
128770
@SuppressWarnings("unchecked")
  private Map<CharSequence, CharSequence> sneakyCast(Object m) {
    return (Map<CharSequence, CharSequence>) m;
  }
670139
@SuppressWarnings("unchecked")
    protected <T> Collection<T> castCollectionToType(Class collectionType, Collection<T> converted) throws ConversionException {
        if (!Collection.class.isAssignableFrom(collectionType)) {
            throw new ConversionException("Collection type should extends collection" + collectionType);
        }

        if (collectionType.isInterface()) {
            if (collectionType.isAssignableFrom(Set.class)) {
                return Collections.unmodifiableSet(new HashSet<>(converted));
            }
            if (collectionType.isAssignableFrom(List.class)) {
                return Collections.unmodifiableList(new LinkedList<>(converted));
            }
            if (collectionType.isAssignableFrom(Collection.class)) {
                return Collections.unmodifiableCollection(converted);
            }
            throw new ConversionException("Unsupported collection type " + collectionType);
        }
        try {
            Constructor constructor = collectionType.getConstructor(Collection.class);
            return (Collection<T>) constructor.newInstance(converted);
        } catch (Exception e) {
            throw new ConversionException("Could not create an instance of " + collectionType, e);
        }
    }
1074022
@Override
    public void setTypeMap(Map<String, Class<?>> arg0) throws SQLException {
        internalConn.setTypeMap(arg0);
    }
956543
@Override
    public Map<String, String[]> getParameterMap() {
        ServletRESTRequestImpl ret = castRequest();
        if (ret != null)
            return ret.getParameterMap();
        return null;
    }
222012
static <T> PathMapped<T> of(PathMapping mapping, PathMappingResult mappingResult, T value) {
        requireNonNull(mapping, "mapping");
        requireNonNull(mappingResult, "mappingResult");
        requireNonNull(value, "value");
        if (!mappingResult.isPresent()) {
            throw new IllegalArgumentException("mappingResult: " + mappingResult + " (must be present)");
        }

        return new PathMapped<>(mapping, mappingResult, value);
    }
247263
public Object castToType(int t, XPathContext support)
          throws javax.xml.transform.TransformerException
  {

    Object result;

    switch (t)
    {
    case CLASS_STRING :
      result = str();
      break;
    case CLASS_NUMBER :
      result = new Double(num());
      break;
    case CLASS_NODESET :
      result = iter();
      break;
    case CLASS_BOOLEAN :
      result = new Boolean(bool());
      break;
    case CLASS_UNKNOWN :
      result = m_obj;
      break;

    // %TBD%  What to do here?
    //    case CLASS_RTREEFRAG :
    //      result = rtree(support);
    //      break;
    default :
      error(XPATHErrorResources.ER_CANT_CONVERT_TO_TYPE,
            new Object[]{ getTypeString(),
                          Integer.toString(t) });  //"Can not convert "+getTypeString()+" to a type#"+t);

      result = null;
    }

    return result;
  }