Coerces a value to the given primitive number class
191941
public static Number coerceToPrimitiveNumber(Object pValue,
                                                 Class pClass,
                                                 Logger pLogger)
            throws ELException {
        if (pValue == null ||
                "".equals(pValue)) {
            return coerceToPrimitiveNumber(0, pClass);
        } else if (pValue instanceof Character) {
            char val = ((Character) pValue).charValue();
            return coerceToPrimitiveNumber((short) val, pClass);
        } else if (pValue instanceof Boolean) {
            if (pLogger.isLoggingError()) {
                pLogger.logError(Constants.BOOLEAN_TO_NUMBER,
                        pValue,
                        pClass.getName());
            }
            return coerceToPrimitiveNumber(0, pClass);
        } else if (pValue.getClass() == pClass) {
            return (Number) pValue;
        } else if (pValue instanceof Number) {
            return coerceToPrimitiveNumber((Number) pValue, pClass);
        } else if (pValue instanceof String) {
            try {
                return coerceToPrimitiveNumber((String) pValue, pClass);
            }
            catch (Exception exc) {
                if (pLogger.isLoggingError()) {
                    pLogger.logError
                            (Constants.STRING_TO_NUMBER_EXCEPTION,
                                    (String) pValue,
                                    pClass.getName());
                }
                return coerceToPrimitiveNumber(0, pClass);
            }
        } else {
            if (pLogger.isLoggingError()) {
                pLogger.logError
                        (Constants.COERCE_TO_NUMBER,
                                pValue.getClass().getName(),
                                pClass.getName());
            }
            return coerceToPrimitiveNumber(0, pClass);
        }
    }
240691
def _cast_value(value, _type):
    
    if _type.upper() == 'FLOAT64':
        return float64(value)
    elif _type.upper() == 'FLOAT32':
        return float32(value)
    elif _type.upper() == 'INT32':
        return int32(value)
    elif _type.upper() == 'UINT16':
        return uint16(value)
    elif _type.upper() == 'INT16':
        return int16(value)
    elif _type.upper() == 'BOOLEAN':
        return uint8(value)
    else:
        return float64(value)
1204736
def p_const_value_primitive(self, p):
        ''''''
        p[0] = ast.ConstPrimitiveValue(p[1], lineno=p.lineno(1))
1212320
def coerce(self, value):
        """"""
        if self.type == Style:
            return value
        elif self.type == list:
            return self.type(
                map(self.subtype, map(lambda x: x.strip(), value.split(',')))
            )
        elif self.type == dict:
            rv = {}
            for pair in value.split(','):
                key, val = pair.split(':')
                key = key.strip()
                val = val.strip()
                try:
                    rv[key] = self.subtype(val)
                except Exception:
                    rv[key] = val
            return rv
        return self.type(value)
727710
def coerce(cls, key, value):
        ""

        if not isinstance(value, MutableDict):
            if isinstance(value, dict):
                return MutableDict(value)

            # this call will raise ValueError
            return Mutable.coerce(key, value)
        else:
            return value
377102
def convert_to_int(value):
    
    if not value:
        return None

    # Apart from numbers also accept values that end with px
    if isinstance(value, str):
        value = value.strip(' px')

    try:
        return int(value)
    except (TypeError, ValueError):
        return None
484236
private void primitive(int typeCode, Object obj) {
        switch (typeCode) {
        case T_BOOLEAN:
            dest.emit(LDC, ((Boolean) obj).booleanValue()? 1 : 0);
            break;
        case T_CHAR:
            dest.emit(LDC, ((Character) obj).charValue());
            break;
        case T_BYTE:
        case T_SHORT:
            dest.emit(LDC, ((Number) obj).intValue());
            break;
        case T_INT:
        case T_FLOAT:
        case T_LONG:
        case T_DOUBLE:
            dest.emitGeneric(LDC, new Object[] { obj });
            break;
        default:
            throw new IllegalArgumentException("not supported: " + typeCode);
        }
    }
636805
protected BigDecimal coerceToBigDecimal(Value value) {
		
		if (!(value instanceof NumberValue))
			throw new CommandExecutionException("Value is not a number");
		return ((NumberValue) value).get();
	}
1201042
public int toInteger(Object val) {
    if (val == null) {
      return 0;
    }
    else if (val instanceof Double) {
      if (!Double.isNaN(((Double) val).doubleValue())) {
        return 0;
      }
      else {
        return ((Double) val).intValue();
      }
    }
    else if (val instanceof Number) {
      return ((Number) val).intValue();
    }
    else if (val instanceof String) {
      if ("".equals(val)) {
        return 0;
      }
      return Integer.parseInt((String) val);
    }
    else if (val instanceof Boolean) {
      return ((Boolean) val).booleanValue() ? 1 : 0;
    }
    else if (val instanceof Character) {
      return ((Character) val).charValue();
    }

    throw new ArithmeticException("Integer coercion: " + val.getClass().getName() + ":(" + val + ")");
  }
374998
def coerce(self, value, **kwargs):
        """"""

        Location = namedtuple('Location', ['lat', 'lon'])
        return Location(float(value.get('lat')), float(value.get('lon')))
119073
public static Integer coerceToInteger(Object pValue,
                                          Logger pLogger)
            throws ELException {
        if (pValue == null) {
            return null;
        } else if (pValue instanceof Character) {
            return PrimitiveObjects.getInteger
                    ((int) (((Character) pValue).charValue()));
        } else if (pValue instanceof Boolean) {
            if (pLogger.isLoggingWarning()) {
                pLogger.logWarning(Constants.BOOLEAN_TO_NUMBER,
                        pValue,
                        Integer.class.getName());
            }
            return PrimitiveObjects.getInteger
                    (((Boolean) pValue).booleanValue() ? 1 : 0);
        } else if (pValue instanceof Integer) {
            return (Integer) pValue;
        } else if (pValue instanceof Number) {
            return PrimitiveObjects.getInteger(((Number) pValue).intValue());
        } else if (pValue instanceof String) {
            try {
                return Integer.valueOf((String) pValue);
            }
            catch (Exception exc) {
                if (pLogger.isLoggingWarning()) {
                    pLogger.logWarning
                            (Constants.STRING_TO_NUMBER_EXCEPTION,
                                    (String) pValue,
                                    Integer.class.getName());
                }
                return null;
            }
        } else {
            if (pLogger.isLoggingWarning()) {
                pLogger.logWarning
                        (Constants.COERCE_TO_NUMBER,
                                pValue.getClass().getName(),
                                Integer.class.getName());
            }
            return null;
        }
    }
832129
public function coerce($value): int
    {
        if ($value === '') {
            throw new InvalidTypeException('Int cannot represent non 32-bit signed integer value: (empty string)');
        }

        if (\is_bool($value)) {
            $value = (int)$value;
        }

        if (!\is_numeric($value) || $value > PHP_INT_MAX || $value < PHP_INT_MIN) {
            throw new InvalidTypeException(
                \sprintf('Int cannot represent non 32-bit signed integer value: %s', $value)
            );
        }

        $floatValue = (float)$value;

        if ($floatValue != $value || \floor($floatValue) !== $floatValue) {
            throw new InvalidTypeException(\sprintf('Int cannot represent non-integer value: %s', $value));
        }

        return (int)$value;
    }
1048256
def _coerceValue(self,value,strict=0):
        
        try:
            if isinstance(value,str):
                # allow single blank-separated string as input
                value = value.split()
            if len(value) != len(self.value):
                raise IndexError
            v = len(self.value)*[0]
            for i in range(len(v)):
                v[i] = self._coerceOneValue(value[i],strict)
            return v
        except (IndexError, TypeError):
            raise ValueError("Value must be a " + repr(len(self.value)) +
                    "-element array for " + self.name)
369860
private static MethodHandle selectNumberTransformer(Class param, Object arg) {
        param = TypeHelper.getWrapperClass(param);

        if (param == Byte.class) {
            return TO_BYTE;
        } else if (param == Character.class || param == Integer.class) {
            return TO_INT;
        } else  if (param == Long.class) {
            return TO_LONG;
        } else if (param == Float.class) {
            return TO_FLOAT;
        } else if (param == Double.class) {
            return TO_DOUBLE;
        } else if (param == BigInteger.class) {
            return TO_BIG_INT;
        } else if (param == BigDecimal.class) {
            if (arg instanceof Double) {
                return DOUBLE_TO_BIG_DEC;
            } else if (arg instanceof Long) {
                return LONG_TO_BIG_DEC;
            } else if (arg instanceof BigInteger) {
                return BIG_INT_TO_BIG_DEC;
            } else {
                return DOUBLE_TO_BIG_DEC_WITH_CONVERSION;
            }
        } else if (param == Short.class) {
            return TO_SHORT;
        } else {
             return null;
        }
    }
670414
def coerce(cls, key, value):
        """"""

        if isinstance(value, string_types):
            value = value.strip()
            if value[0] == '[':  # It's json encoded, probably
                try:
                    value = json.loads(value)
                except ValueError:
                    raise ValueError("Failed to parse JSON: '{}' ".format(value))
            else:
                value = value.split(',')

        if not value:
            value = []

        self = MutationList((MutationObj.coerce(key, v) for v in value))
        self._key = key
        return self
89125
def coerce(value):
        
        is_number = lambda x: isinstance(x, (int, float, complex)) #is x an instance of those things
        if isinstance(value, IntervalCell) or issubclass(value.__class__,IntervalCell): 
            #if intervalcell or subclass, return the subclass
            return value
        elif is_number(value):
            return IntervalCell(value, value)
        elif hasattr(value, 'low') and hasattr(value, 'high'):
            # duck type
            assert value.low <= value.high, "Invalid low/high in %s" % str(value)
            return value
        elif isinstance(value, (list, tuple)) and all(map(is_number, value)):
            if len(value) == 1:
                low, high = value[0], value[0]
            elif len(value) == 2:
                low, high = value
            else:
                low, high = min(value), max(value)
            if high < low:
                raise Contradiction("Low must be lte High") 
            return IntervalCell(low, high)
        else:
            raise Exception("Don't know how to coerce %s" % (type(value)))
61683
def coerce(cls, key, value):
        """"""
        if isinstance(value, PasswordHash):
            return value
        return super(PasswordHash, cls).coerce(key, value)