public final static Number coerceToNumber(final Object obj) { if (obj == null) { return ZERO; } else if (obj instanceof Number) { return (Number) obj; } else { String str = coerceToString(obj); if (isStringFloat(str)) { return toFloat(str); } else { return toNumber(str); } } }
public Object invoke(ELContext context, Object[] params) throws ELException { if (this.expectedType != null) { return ELSupport.coerceToType(this.expr, this.expectedType); } else { return this.expr; } }
public final static boolean isDoubleStringOp(final Object obj0, final Object obj1) { return (isDoubleOp(obj0, obj1) || (obj0 instanceof String && isStringFloat((String) obj0)) || (obj1 instanceof String && isStringFloat((String) obj1))); }
return false; } else if (obj0 instanceof Boolean || obj1 instanceof Boolean) { return coerceToBoolean(obj0).equals(coerceToBoolean(obj1)); } else if (obj0.getClass().isEnum()) { return obj0.equals(coerceToEnum(obj1, obj0.getClass())); } else if (obj1.getClass().isEnum()) { return obj1.equals(coerceToEnum(obj0, obj1.getClass())); } else if (obj0 instanceof String || obj1 instanceof String) { int lexCompare = coerceToString(obj0).compareTo(coerceToString(obj1)); return (lexCompare == 0) ? true : false; if (isBigDecimalOp(obj0, obj1)) { BigDecimal bd0 = (BigDecimal) coerceToNumber(obj0, BigDecimal.class); BigDecimal bd1 = (BigDecimal) coerceToNumber(obj1, BigDecimal.class); return bd0.equals(bd1); if (isDoubleOp(obj0, obj1)) { Double d0 = (Double) coerceToNumber(obj0, Double.class); Double d1 = (Double) coerceToNumber(obj1, Double.class); return d0.equals(d1); if (isBigIntegerOp(obj0, obj1)) { BigInteger bi0 = (BigInteger) coerceToNumber(obj0, BigInteger.class); BigInteger bi1 = (BigInteger) coerceToNumber(obj1, BigInteger.class); return bi0.equals(bi1); if (isLongOp(obj0, obj1)) { Long l0 = (Long) coerceToNumber(obj0, Long.class); Long l1 = (Long) coerceToNumber(obj1, Long.class);
if (obj0 == obj1 || equals(obj0, obj1)) { return 0; if (isBigDecimalOp(obj0, obj1)) { BigDecimal bd0 = (BigDecimal) coerceToNumber(obj0, BigDecimal.class); BigDecimal bd1 = (BigDecimal) coerceToNumber(obj1, BigDecimal.class); return bd0.compareTo(bd1); if (isDoubleOp(obj0, obj1)) { Double d0 = (Double) coerceToNumber(obj0, Double.class); Double d1 = (Double) coerceToNumber(obj1, Double.class); return d0.compareTo(d1); if (isBigIntegerOp(obj0, obj1)) { BigInteger bi0 = (BigInteger) coerceToNumber(obj0, BigInteger.class); BigInteger bi1 = (BigInteger) coerceToNumber(obj1, BigInteger.class); return bi0.compareTo(bi1); if (isLongOp(obj0, obj1)) { Long l0 = (Long) coerceToNumber(obj0, Long.class); Long l1 = (Long) coerceToNumber(obj1, Long.class); return l0.compareTo(l1); return coerceToString(obj0).compareTo(coerceToString(obj1));
return coerceToString(obj); return coerceToNumber(obj, type); return coerceToCharacter(obj); return coerceToBoolean(obj); return coerceToEnum(obj, type);
public final static Number coerceToNumber(final Object obj, final Class type) throws IllegalArgumentException { if (obj == null || "".equals(obj)) { return coerceToNumber(ZERO, type); } if (obj instanceof String) { return coerceToNumber((String) obj, type); } if (ELArithmetic.isNumber(obj)) { return coerceToNumber((Number) obj, type); } Class objType = obj.getClass(); if (Character.class.equals(objType) || Character.TYPE == objType) { return coerceToNumber(new Short((short) ((Character) obj) .charValue()), type); } throw new IllegalArgumentException(MessageFactory.get("error.convert", obj, objType, type)); }
public static Method findMethod(Object base, Object name, Object[] params) { Method r = null; if (base != null && name != null) { Class type = base.getClass(); String methodName = ELSupport.coerceToString(name); MethodCache m = methodCache.get(type); // if (m == null || type != m.getType()) { // m = new MethodCache(type); // methodCache.set(type, m); // } r = m.findMethod(methodName, params); if (r == null) { throw new MethodNotFoundException(MessageFactory.get( "error.method.notfound", base, name, paramString(paramTypes(params)))); } } else { throw new MethodNotFoundException(); } return r; }
return false; } else if (obj0 instanceof Boolean || obj1 instanceof Boolean) { return coerceToBoolean(obj0).equals(coerceToBoolean(obj1)); } else if (obj0.getClass().isEnum()) { return obj0.equals(coerceToEnum(obj1, obj0.getClass())); } else if (obj1.getClass().isEnum()) { return obj1.equals(coerceToEnum(obj0, obj1.getClass())); } else if (obj0 instanceof String || obj1 instanceof String) { int lexCompare = coerceToString(obj0).compareTo(coerceToString(obj1)); return (lexCompare == 0) ? true : false; if (isBigDecimalOp(obj0, obj1)) { BigDecimal bd0 = (BigDecimal) coerceToNumber(obj0, BigDecimal.class); BigDecimal bd1 = (BigDecimal) coerceToNumber(obj1, BigDecimal.class); return bd0.equals(bd1); if (isDoubleOp(obj0, obj1)) { Double d0 = (Double) coerceToNumber(obj0, Double.class); Double d1 = (Double) coerceToNumber(obj1, Double.class); return d0.equals(d1); if (isBigIntegerOp(obj0, obj1)) { BigInteger bi0 = (BigInteger) coerceToNumber(obj0, BigInteger.class); BigInteger bi1 = (BigInteger) coerceToNumber(obj1, BigInteger.class); return bi0.equals(bi1); if (isLongOp(obj0, obj1)) { Long l0 = (Long) coerceToNumber(obj0, Long.class); Long l1 = (Long) coerceToNumber(obj1, Long.class);
if (obj0 == obj1 || equals(obj0, obj1)) { return 0; if (isBigDecimalOp(obj0, obj1)) { BigDecimal bd0 = (BigDecimal) coerceToNumber(obj0, BigDecimal.class); BigDecimal bd1 = (BigDecimal) coerceToNumber(obj1, BigDecimal.class); return bd0.compareTo(bd1); if (isDoubleOp(obj0, obj1)) { Double d0 = (Double) coerceToNumber(obj0, Double.class); Double d1 = (Double) coerceToNumber(obj1, Double.class); return d0.compareTo(d1); if (isBigIntegerOp(obj0, obj1)) { BigInteger bi0 = (BigInteger) coerceToNumber(obj0, BigInteger.class); BigInteger bi1 = (BigInteger) coerceToNumber(obj1, BigInteger.class); return bi0.compareTo(bi1); if (isLongOp(obj0, obj1)) { Long l0 = (Long) coerceToNumber(obj0, Long.class); Long l1 = (Long) coerceToNumber(obj1, Long.class); return l0.compareTo(l1); return coerceToString(obj0).compareTo(coerceToString(obj1));
return coerceToString(obj); return coerceToNumber(obj, type); return coerceToCharacter(obj); return coerceToBoolean(obj); return coerceToEnum(obj, type);
public final static Number coerceToNumber(final Object obj, final Class type) throws IllegalArgumentException { if (obj == null || "".equals(obj)) { if (type == Number.class) return null; else return coerceToNumber(ZERO, type); } if (obj instanceof String) { return coerceToNumber((String) obj, type); } if (ELArithmetic.isNumber(obj)) { return coerceToNumber((Number) obj, type); } Class objType = obj.getClass(); if (Character.class.equals(objType) || Character.TYPE == objType) { return coerceToNumber(new Short((short) ((Character) obj) .charValue()), type); } throw new IllegalArgumentException(MessageFactory.get("error.convert", obj, objType, type)); }
public static Method findMethod(Object base, Object name, Object[] params) { Method r = null; if (base != null && name != null) { Class type = base.getClass(); String methodName = ELSupport.coerceToString(name); MethodCache m = methodCache.get(type); // if (m == null || type != m.getType()) { // m = new MethodCache(type); // methodCache.set(type, m); // } r = m.findMethod(methodName, params); if (r == null) { throw new MethodNotFoundException(MessageFactory.get( "error.method.notfound", base, name, paramString(paramTypes(params)))); } } else { throw new MethodNotFoundException(); } return r; }
return false; } else if (obj0 instanceof Boolean || obj1 instanceof Boolean) { return coerceToBoolean(obj0).equals(coerceToBoolean(obj1)); } else if (obj0.getClass().isEnum()) { return obj0.equals(coerceToEnum(obj1, obj0.getClass())); } else if (obj1.getClass().isEnum()) { return obj1.equals(coerceToEnum(obj0, obj1.getClass())); } else if (obj0 instanceof String || obj1 instanceof String) { int lexCompare = coerceToString(obj0).compareTo(coerceToString(obj1)); return (lexCompare == 0) ? true : false; if (isBigDecimalOp(obj0, obj1)) { BigDecimal bd0 = (BigDecimal) coerceToNumber(obj0, BigDecimal.class); BigDecimal bd1 = (BigDecimal) coerceToNumber(obj1, BigDecimal.class); return bd0.equals(bd1); if (isDoubleOp(obj0, obj1)) { Double d0 = (Double) coerceToNumber(obj0, Double.class); Double d1 = (Double) coerceToNumber(obj1, Double.class); return d0.equals(d1); if (isBigIntegerOp(obj0, obj1)) { BigInteger bi0 = (BigInteger) coerceToNumber(obj0, BigInteger.class); BigInteger bi1 = (BigInteger) coerceToNumber(obj1, BigInteger.class); return bi0.equals(bi1); if (isLongOp(obj0, obj1)) { Long l0 = (Long) coerceToNumber(obj0, Long.class); Long l1 = (Long) coerceToNumber(obj1, Long.class);
if (obj0 == obj1 || equals(obj0, obj1)) { return 0; if (isBigDecimalOp(obj0, obj1)) { BigDecimal bd0 = (BigDecimal) coerceToNumber(obj0, BigDecimal.class); BigDecimal bd1 = (BigDecimal) coerceToNumber(obj1, BigDecimal.class); return bd0.compareTo(bd1); if (isDoubleOp(obj0, obj1)) { Double d0 = (Double) coerceToNumber(obj0, Double.class); Double d1 = (Double) coerceToNumber(obj1, Double.class); return d0.compareTo(d1); if (isBigIntegerOp(obj0, obj1)) { BigInteger bi0 = (BigInteger) coerceToNumber(obj0, BigInteger.class); BigInteger bi1 = (BigInteger) coerceToNumber(obj1, BigInteger.class); return bi0.compareTo(bi1); if (isLongOp(obj0, obj1)) { Long l0 = (Long) coerceToNumber(obj0, Long.class); Long l1 = (Long) coerceToNumber(obj1, Long.class); return l0.compareTo(l1); return coerceToString(obj0).compareTo(coerceToString(obj1));
return coerceToString(obj); return coerceToNumber(obj, type); return coerceToCharacter(obj); return coerceToBoolean(obj); return coerceToEnum(obj, type);
public final static Number coerceToNumber(final Object obj) { if (obj == null) { return ZERO; } else if (obj instanceof Number) { return (Number) obj; } else { String str = coerceToString(obj); if (isStringFloat(str)) { return toFloat(str); } else { return toNumber(str); } } }
public Object getValue(ELContext context) { if (this.expectedType != null) { return ELSupport.coerceToType(this.value, this.expectedType); } return this.value; }
public final static boolean isDoubleStringOp(final Object obj0, final Object obj1) { return (isDoubleOp(obj0, obj1) || (obj0 instanceof String && isStringFloat((String) obj0)) || (obj1 instanceof String && isStringFloat((String) obj1))); }
public final static Number coerceToNumber(final Object obj, final Class type) throws IllegalArgumentException { if (obj == null || "".equals(obj)) { if (type == Number.class) return null; else return coerceToNumber(ZERO, type); } if (obj instanceof String) { return coerceToNumber((String) obj, type); } if (ELArithmetic.isNumber(obj)) { return coerceToNumber((Number) obj, type); } Class objType = obj.getClass(); if (Character.class.equals(objType) || Character.TYPE == objType) { return coerceToNumber(new Short((short) ((Character) obj) .charValue()), type); } throw new IllegalArgumentException(MessageFactory.get("error.convert", obj, objType, type)); }