Implemented to avoid megamorphic call on castProcedure.
760971
private static <T> void batchFastListCollect(T[] array, int start, int end, FastListCollectProcedure<T, ?> castProcedure)
    {
        for (int i = start; i < end; i++)
        {
            castProcedure.value(array[i]);
        }
    }
45469
@SuppressWarnings("unchecked")
    public static <T> T castObject(final Object castObject,
                                   final Class<T> fieldType) {
        if(fieldType == null)
            return null;

        final boolean isTypeString = fieldType.equals(String.class);
        if(castObject == null) {
            return (isTypeString)
                    ? ((T) "null")
                    : null;
        }

        final Class<?> castType         = castObject.getClass();
        final boolean isTypeAssignable  = fieldType.isAssignableFrom(castType);
        final boolean isTypeEquals      = areEquals(castType, fieldType);
        final boolean isTypeObject      = fieldType.equals(Object.class);

        return castObject(castObject, fieldType,
                isTypeAssignable, isTypeEquals,
                isTypeObject, isTypeString);
    }
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;
	}
965098
public static <T, E extends Exception> BinaryOperator<T> sneaked(
      SneakyBinaryOperator<T, E> binaryOperator) {
    return (t1, t2) -> {
      @SuppressWarnings("unchecked")
      SneakyBinaryOperator<T, RuntimeException> castedBinaryOperator =
          (SneakyBinaryOperator<T, RuntimeException>) binaryOperator;
      return castedBinaryOperator.apply(t1, t2);
    };
  }
268135
private static boolean castToBool(byte[] data) {
        for (int i = 0; i < data.length; i++)
        {
            // "Can be negative zero" - Bitcoin Core (see OpenSSL's BN_bn2mpi)
            if (data[i] != 0)
                return !(i == data.length - 1 && (data[i] & 0xFF) == 0x80);
        }
        return false;
    }
353069
def cast(self, value, custom_formatters=None, strict=True):
        """"""
        if value is None:
            if not self.nullable:
                raise InvalidSchemaValue("Null value for non-nullable schema", value, self.type)
            return self.default

        cast_mapping = self.get_cast_mapping(
            custom_formatters=custom_formatters, strict=strict)

        if self.type is not SchemaType.STRING and value == '':
            return None

        cast_callable = cast_mapping[self.type]
        try:
            return cast_callable(value)
        except ValueError:
            raise InvalidSchemaValue(
                "Failed to cast value {value} to type {type}", value, self.type)
864034
static Object bigIntegerBinaryOperation(BigInteger lhs, BigInteger rhs, int kind)
    {

        switch(kind)
        {
            // arithmetic
            case PLUS:
                return lhs.add(rhs);

            case MINUS:
                return lhs.subtract(rhs);

            case STAR:
                return lhs.multiply(rhs);

            case SLASH:
                return lhs.divide(rhs);

            case MOD:
            case MODX:
                return lhs.mod(rhs);

            case POWER:
            case POWERX:
                return lhs.pow(rhs.intValue());

            // bitwise
            case LSHIFT:
            case LSHIFTX:
                return lhs.shiftLeft(rhs.intValue());

            case RSIGNEDSHIFT:
            case RSIGNEDSHIFTX:
                return lhs.shiftRight(rhs.intValue());

            case RUNSIGNEDSHIFT:
            case RUNSIGNEDSHIFTX:
                if ( lhs.signum() >= 0 )
                    return lhs.shiftRight(rhs.intValue());
                BigInteger opener = BigInteger.ONE.shiftLeft(lhs.toString(2).length() + 1);
                BigInteger opened = lhs.subtract(opener);
                BigInteger mask = opener.subtract(BigInteger.ONE).shiftRight(rhs.intValue() + 1);
                return opened.shiftRight(rhs.intValue()).and(mask);


            case BIT_AND:
            case BIT_ANDX:
                return lhs.and(rhs);

            case BIT_OR:
            case BIT_ORX:
                return lhs.or(rhs);

            case XOR:
            case XORX:
                return lhs.xor(rhs);

        }
        throw new InterpreterError(
                "Unimplemented binary integer operator");
    }
1367774
private void checkIsCastableToDefinedType(Option o, Map<String, String> data) throws RequiredParametersException {
		if (o.hasType() && !o.isCastableToDefinedType(data.get(o.getName()))) {
			throw new RequiredParametersException("Value for parameter " + o.getName() +
					" cannot be cast to type " + o.getType());
		}
	}
630241
public static <T, V> Function<T, V> cast(Function<T, V> function)
    {
        return function;
    }
572153
@Pure
	public static <P1, P2, P3, P4, P5> Procedure4<P2, P3, P4, P5> curry(final Procedure5<? super P1, ? super P2, ? super P3, ? super P4, ? super P5> procedure,
			final P1 argument) {
		if (procedure == null)
			throw new NullPointerException("procedure");
		return new Procedure4<P2, P3, P4, P5>() {
			@Override
			public void apply(P2 p2, P3 p3, P4 p4, P5 p5) {
				procedure.apply(argument, p2, p3, p4, p5);
			}
		};
	}
148727
public static long castToIntegral(Decimal dec) {
		BigDecimal bd = dec.toBigDecimal();
		// rounding down. This is consistent with float=>int,
		// and consistent with SQLServer, Spark.
		bd = bd.setScale(0, RoundingMode.DOWN);
		return bd.longValue();
	}
797296
def _cast_output_to_type(value, typ):
    ''''''
    if typ == 'b':
        return bool(value)
    if typ == 'i':
        return int(value)
    return value
573044
private RValue executeConvert(Expr.Cast expr, CallStack frame) {
		RValue operand = executeExpression(ANY_T, expr.getOperand(), frame);
		return operand.convert(expr.getType());
	}
918532
private static <T> void batchFastListSelect(T[] array, int start, int end, FastListSelectProcedure<T> castProcedure)
    {
        for (int i = start; i < end; i++)
        {
            castProcedure.value(array[i]);
        }
    }
1312365
private MetaMethod specialCasedOverrideForCreate(final Method m) {
        return new MetaMethod() {

            @Override
            public int getModifiers() {
                return m.getModifiers();
            }

            @Override
            public String getName() {
                return m.getName();
            }

            @Override
            public Class<?> getReturnType() {
                return m.getReturnType();
            }

            @Override
            public CachedClass getDeclaringClass() {
                return ReflectionCache.getCachedClass(m.getDeclaringClass());
            }

            @Override
            @SuppressWarnings("unchecked")
            public Object invoke(Object object, final Object[] arguments) {
                return Observable.create(new GroovyCreateWrapper((Closure) arguments[0]));
            }

            @Override
            public CachedClass[] getParameterTypes() {
                if (parameterTypes == null) {
                    getParametersTypes0();
                }

                return parameterTypes;
            }

            private synchronized void getParametersTypes0() {
                if (parameterTypes != null)
                    return;

                Class [] npt = nativeParamTypes == null ? getPT() : nativeParamTypes;

                CachedClass[] pt = new CachedClass [npt.length];
                for (int i = 0; i != npt.length; ++i) {
                    if (Function.class.isAssignableFrom(npt[i])) {
                        // function type to be replaced by closure
                        pt[i] = ReflectionCache.getCachedClass(Closure.class);
                    } else {
                        // non-function type
                        pt[i] = ReflectionCache.getCachedClass(npt[i]);
                    }
                }

                nativeParamTypes = npt;
                setParametersTypes(pt);
            }

            @Override
            protected Class[] getPT() {
                return m.getParameterTypes();
            }
        };
    }
148055
private void eliminateCallTargetArgAt(Node ref, int argIndex) {
    Node callArgNode = ReferenceMap.getArgumentForCallOrNewOrDotCall(ref, argIndex);
    if (callArgNode != null) {
      NodeUtil.deleteNode(callArgNode, compiler);
    }
  }
945400
public void castToNonPrimitiveIfNecessary(final ClassNode sourceType, final ClassNode targetType) {
        OperandStack os = controller.getOperandStack();
        ClassNode boxedType = os.box();
        if (WideningCategories.implementsInterfaceOrSubclassOf(boxedType, targetType)) return;
        MethodVisitor mv = controller.getMethodVisitor();
        if (ClassHelper.CLASS_Type.equals(targetType)) {
            castToClassMethod.call(mv);
        } else if (ClassHelper.STRING_TYPE.equals(targetType)) {
            castToStringMethod.call(mv);
        } else if (targetType.isDerivedFrom(ClassHelper.Enum_Type)) {
            (new ClassExpression(targetType)).visit(controller.getAcg());
            os.remove(1);
            castToEnumMethod.call(mv);
            BytecodeHelper.doCast(mv, targetType);
        } else {
            (new ClassExpression(targetType)).visit(controller.getAcg());
            os.remove(1);
            castToTypeMethod.call(mv);
        }
    }