org.springframework.util.NumberUtils Java Examples
The following examples show how to use
org.springframework.util.NumberUtils.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SingleColumnRowMapper.java From java-technology-stack with MIT License | 6 votes |
/** * Convert the given column value to the specified required type. * Only called if the extracted column value does not match already. * <p>If the required type is String, the value will simply get stringified * via {@code toString()}. In case of a Number, the value will be * converted into a Number, either through number conversion or through * String parsing (depending on the value type). Otherwise, the value will * be converted to a required type using the {@link ConversionService}. * @param value the column value as extracted from {@code getColumnValue()} * (never {@code null}) * @param requiredType the type that each result object is expected to match * (never {@code null}) * @return the converted value * @see #getColumnValue(java.sql.ResultSet, int, Class) */ @SuppressWarnings("unchecked") @Nullable protected Object convertValueToRequiredType(Object value, Class<?> requiredType) { if (String.class == requiredType) { return value.toString(); } else if (Number.class.isAssignableFrom(requiredType)) { if (value instanceof Number) { // Convert original Number to target Number class. return NumberUtils.convertNumberToTargetClass(((Number) value), (Class<Number>) requiredType); } else { // Convert stringified value to target Number class. return NumberUtils.parseNumber(value.toString(),(Class<Number>) requiredType); } } else if (this.conversionService != null && this.conversionService.canConvert(value.getClass(), requiredType)) { return this.conversionService.convert(value, requiredType); } else { throw new IllegalArgumentException( "Value [" + value + "] is of type [" + value.getClass().getName() + "] and cannot be converted to required type [" + requiredType.getName() + "]"); } }
Example #2
Source File: SingleColumnRowMapper.java From spring-analysis-note with MIT License | 6 votes |
/** * Convert the given column value to the specified required type. * Only called if the extracted column value does not match already. * <p>If the required type is String, the value will simply get stringified * via {@code toString()}. In case of a Number, the value will be * converted into a Number, either through number conversion or through * String parsing (depending on the value type). Otherwise, the value will * be converted to a required type using the {@link ConversionService}. * @param value the column value as extracted from {@code getColumnValue()} * (never {@code null}) * @param requiredType the type that each result object is expected to match * (never {@code null}) * @return the converted value * @see #getColumnValue(java.sql.ResultSet, int, Class) */ @SuppressWarnings("unchecked") @Nullable protected Object convertValueToRequiredType(Object value, Class<?> requiredType) { if (String.class == requiredType) { return value.toString(); } else if (Number.class.isAssignableFrom(requiredType)) { if (value instanceof Number) { // Convert original Number to target Number class. return NumberUtils.convertNumberToTargetClass(((Number) value), (Class<Number>) requiredType); } else { // Convert stringified value to target Number class. return NumberUtils.parseNumber(value.toString(),(Class<Number>) requiredType); } } else if (this.conversionService != null && this.conversionService.canConvert(value.getClass(), requiredType)) { return this.conversionService.convert(value, requiredType); } else { throw new IllegalArgumentException( "Value [" + value + "] is of type [" + value.getClass().getName() + "] and cannot be converted to required type [" + requiredType.getName() + "]"); } }
Example #3
Source File: CustomNumberEditor.java From blog_demos with Apache License 2.0 | 6 votes |
/** * Parse the Number from the given text, using the specified NumberFormat. */ @Override public void setAsText(String text) throws IllegalArgumentException { if (this.allowEmpty && !StringUtils.hasText(text)) { // Treat empty String as null value. setValue(null); } else if (this.numberFormat != null) { // Use given NumberFormat for parsing text. setValue(NumberUtils.parseNumber(text, this.numberClass, this.numberFormat)); } else { // Use default valueOf methods for parsing text. setValue(NumberUtils.parseNumber(text, this.numberClass)); } }
Example #4
Source File: DataAccessUtils.java From spring-analysis-note with MIT License | 6 votes |
/** * Return a unique result object from the given Collection. * Throws an exception if 0 or more than 1 result objects found, * of if the unique result object is not convertible to the * specified required type. * @param results the result Collection (can be {@code null} * but is not expected to contain {@code null} elements) * @return the unique result object * @throws IncorrectResultSizeDataAccessException if more than one * result object has been found in the given Collection * @throws EmptyResultDataAccessException if no result object * at all has been found in the given Collection * @throws TypeMismatchDataAccessException if the unique object does * not match the specified required type */ @SuppressWarnings("unchecked") public static <T> T objectResult(@Nullable Collection<?> results, @Nullable Class<T> requiredType) throws IncorrectResultSizeDataAccessException, TypeMismatchDataAccessException { Object result = requiredUniqueResult(results); if (requiredType != null && !requiredType.isInstance(result)) { if (String.class == requiredType) { result = result.toString(); } else if (Number.class.isAssignableFrom(requiredType) && Number.class.isInstance(result)) { try { result = NumberUtils.convertNumberToTargetClass(((Number) result), (Class<? extends Number>) requiredType); } catch (IllegalArgumentException ex) { throw new TypeMismatchDataAccessException(ex.getMessage()); } } else { throw new TypeMismatchDataAccessException( "Result object is of type [" + result.getClass().getName() + "] and could not be converted to required type [" + requiredType.getName() + "]"); } } return (T) result; }
Example #5
Source File: SingleColumnRowMapper.java From effectivejava with Apache License 2.0 | 6 votes |
/** * Convert the given column value to the specified required type. * Only called if the extracted column value does not match already. * <p>If the required type is String, the value will simply get stringified * via {@code toString()}. In case of a Number, the value will be * converted into a Number, either through number conversion or through * String parsing (depending on the value type). * @param value the column value as extracted from {@code getColumnValue()} * (never {@code null}) * @param requiredType the type that each result object is expected to match * (never {@code null}) * @return the converted value * @see #getColumnValue(java.sql.ResultSet, int, Class) */ @SuppressWarnings("unchecked") protected Object convertValueToRequiredType(Object value, Class<?> requiredType) { if (String.class.equals(requiredType)) { return value.toString(); } else if (Number.class.isAssignableFrom(requiredType)) { if (value instanceof Number) { // Convert original Number to target Number class. return NumberUtils.convertNumberToTargetClass(((Number) value), (Class<Number>) requiredType); } else { // Convert stringified value to target Number class. return NumberUtils.parseNumber(value.toString(),(Class<Number>) requiredType); } } else { throw new IllegalArgumentException( "Value [" + value + "] is of type [" + value.getClass().getName() + "] and cannot be converted to required type [" + requiredType.getName() + "]"); } }
Example #6
Source File: CustomNumberEditor.java From spring4-understanding with Apache License 2.0 | 6 votes |
/** * Parse the Number from the given text, using the specified NumberFormat. */ @Override public void setAsText(String text) throws IllegalArgumentException { if (this.allowEmpty && !StringUtils.hasText(text)) { // Treat empty String as null value. setValue(null); } else if (this.numberFormat != null) { // Use given NumberFormat for parsing text. setValue(NumberUtils.parseNumber(text, this.numberClass, this.numberFormat)); } else { // Use default valueOf methods for parsing text. setValue(NumberUtils.parseNumber(text, this.numberClass)); } }
Example #7
Source File: DataAccessUtils.java From spring4-understanding with Apache License 2.0 | 6 votes |
/** * Return a unique result object from the given Collection. * Throws an exception if 0 or more than 1 result objects found, * of if the unique result object is not convertable to the * specified required type. * @param results the result Collection (can be {@code null}) * @return the unique result object * @throws IncorrectResultSizeDataAccessException if more than one * result object has been found in the given Collection * @throws EmptyResultDataAccessException if no result object * at all has been found in the given Collection * @throws TypeMismatchDataAccessException if the unique object does * not match the specified required type */ @SuppressWarnings("unchecked") public static <T> T objectResult(Collection<?> results, Class<T> requiredType) throws IncorrectResultSizeDataAccessException, TypeMismatchDataAccessException { Object result = requiredUniqueResult(results); if (requiredType != null && !requiredType.isInstance(result)) { if (String.class == requiredType) { result = result.toString(); } else if (Number.class.isAssignableFrom(requiredType) && Number.class.isInstance(result)) { try { result = NumberUtils.convertNumberToTargetClass(((Number) result), (Class<? extends Number>) requiredType); } catch (IllegalArgumentException ex) { throw new TypeMismatchDataAccessException(ex.getMessage()); } } else { throw new TypeMismatchDataAccessException( "Result object is of type [" + result.getClass().getName() + "] and could not be converted to required type [" + requiredType.getName() + "]"); } } return (T) result; }
Example #8
Source File: CustomNumberEditor.java From lams with GNU General Public License v2.0 | 6 votes |
/** * Parse the Number from the given text, using the specified NumberFormat. */ @Override public void setAsText(String text) throws IllegalArgumentException { if (this.allowEmpty && !StringUtils.hasText(text)) { // Treat empty String as null value. setValue(null); } else if (this.numberFormat != null) { // Use given NumberFormat for parsing text. setValue(NumberUtils.parseNumber(text, this.numberClass, this.numberFormat)); } else { // Use default valueOf methods for parsing text. setValue(NumberUtils.parseNumber(text, this.numberClass)); } }
Example #9
Source File: DataAccessUtils.java From lams with GNU General Public License v2.0 | 6 votes |
/** * Return a unique result object from the given Collection. * Throws an exception if 0 or more than 1 result objects found, * of if the unique result object is not convertible to the * specified required type. * @param results the result Collection (can be {@code null}) * @return the unique result object * @throws IncorrectResultSizeDataAccessException if more than one * result object has been found in the given Collection * @throws EmptyResultDataAccessException if no result object * at all has been found in the given Collection * @throws TypeMismatchDataAccessException if the unique object does * not match the specified required type */ @SuppressWarnings("unchecked") public static <T> T objectResult(Collection<?> results, Class<T> requiredType) throws IncorrectResultSizeDataAccessException, TypeMismatchDataAccessException { Object result = requiredUniqueResult(results); if (requiredType != null && !requiredType.isInstance(result)) { if (String.class == requiredType) { result = result.toString(); } else if (Number.class.isAssignableFrom(requiredType) && Number.class.isInstance(result)) { try { result = NumberUtils.convertNumberToTargetClass(((Number) result), (Class<? extends Number>) requiredType); } catch (IllegalArgumentException ex) { throw new TypeMismatchDataAccessException(ex.getMessage()); } } else { throw new TypeMismatchDataAccessException( "Result object is of type [" + result.getClass().getName() + "] and could not be converted to required type [" + requiredType.getName() + "]"); } } return (T) result; }
Example #10
Source File: CustomNumberEditor.java From spring-analysis-note with MIT License | 6 votes |
/** * Parse the Number from the given text, using the specified NumberFormat. */ @Override public void setAsText(String text) throws IllegalArgumentException { if (this.allowEmpty && !StringUtils.hasText(text)) { // Treat empty String as null value. setValue(null); } else if (this.numberFormat != null) { // Use given NumberFormat for parsing text. setValue(NumberUtils.parseNumber(text, this.numberClass, this.numberFormat)); } else { // Use default valueOf methods for parsing text. setValue(NumberUtils.parseNumber(text, this.numberClass)); } }
Example #11
Source File: QueryGenerator.java From jeecg-cloud with Apache License 2.0 | 6 votes |
private static void addRuleToQueryWrapper(SysPermissionDataRuleModel dataRule, String name, Class propertyType, QueryWrapper<?> queryWrapper) { QueryRuleEnum rule = QueryRuleEnum.getByValue(dataRule.getRuleConditions()); if(rule.equals(QueryRuleEnum.IN) && ! propertyType.equals(String.class)) { String[] values = dataRule.getRuleValue().split(","); Object[] objs = new Object[values.length]; for (int i = 0; i < values.length; i++) { objs[i] = NumberUtils.parseNumber(values[i], propertyType); } addEasyQuery(queryWrapper, name, rule, objs); }else { if (propertyType.equals(String.class)) { addEasyQuery(queryWrapper, name, rule, converRuleValue(dataRule.getRuleValue())); }else if (propertyType.equals(Date.class)) { String dateStr =converRuleValue(dataRule.getRuleValue()); if(dateStr.length()==10){ addEasyQuery(queryWrapper, name, rule, DateUtils.str2Date(dateStr,DateUtils.date_sdf.get())); }else{ addEasyQuery(queryWrapper, name, rule, DateUtils.str2Date(dateStr,DateUtils.datetimeFormat.get())); } }else { addEasyQuery(queryWrapper, name, rule, NumberUtils.parseNumber(dataRule.getRuleValue(), propertyType)); } } }
Example #12
Source File: SingleColumnRowMapper.java From lams with GNU General Public License v2.0 | 6 votes |
/** * Convert the given column value to the specified required type. * Only called if the extracted column value does not match already. * <p>If the required type is String, the value will simply get stringified * via {@code toString()}. In case of a Number, the value will be * converted into a Number, either through number conversion or through * String parsing (depending on the value type). * @param value the column value as extracted from {@code getColumnValue()} * (never {@code null}) * @param requiredType the type that each result object is expected to match * (never {@code null}) * @return the converted value * @see #getColumnValue(java.sql.ResultSet, int, Class) */ @SuppressWarnings("unchecked") protected Object convertValueToRequiredType(Object value, Class<?> requiredType) { if (String.class == requiredType) { return value.toString(); } else if (Number.class.isAssignableFrom(requiredType)) { if (value instanceof Number) { // Convert original Number to target Number class. return NumberUtils.convertNumberToTargetClass(((Number) value), (Class<Number>) requiredType); } else { // Convert stringified value to target Number class. return NumberUtils.parseNumber(value.toString(),(Class<Number>) requiredType); } } else { throw new IllegalArgumentException( "Value [" + value + "] is of type [" + value.getClass().getName() + "] and cannot be converted to required type [" + requiredType.getName() + "]"); } }
Example #13
Source File: DataAccessUtils.java From java-technology-stack with MIT License | 6 votes |
/** * Return a unique result object from the given Collection. * Throws an exception if 0 or more than 1 result objects found, * of if the unique result object is not convertible to the * specified required type. * @param results the result Collection (can be {@code null} * but is not expected to contain {@code null} elements) * @return the unique result object * @throws IncorrectResultSizeDataAccessException if more than one * result object has been found in the given Collection * @throws EmptyResultDataAccessException if no result object * at all has been found in the given Collection * @throws TypeMismatchDataAccessException if the unique object does * not match the specified required type */ @SuppressWarnings("unchecked") public static <T> T objectResult(@Nullable Collection<?> results, @Nullable Class<T> requiredType) throws IncorrectResultSizeDataAccessException, TypeMismatchDataAccessException { Object result = requiredUniqueResult(results); if (requiredType != null && !requiredType.isInstance(result)) { if (String.class == requiredType) { result = result.toString(); } else if (Number.class.isAssignableFrom(requiredType) && Number.class.isInstance(result)) { try { result = NumberUtils.convertNumberToTargetClass(((Number) result), (Class<? extends Number>) requiredType); } catch (IllegalArgumentException ex) { throw new TypeMismatchDataAccessException(ex.getMessage()); } } else { throw new TypeMismatchDataAccessException( "Result object is of type [" + result.getClass().getName() + "] and could not be converted to required type [" + requiredType.getName() + "]"); } } return (T) result; }
Example #14
Source File: HqlGenerateUtil.java From jeecg with Apache License 2.0 | 6 votes |
private static void addRuleToCriteria(TSDataRule tsDataRule, String aliasName, Class propertyType, CriteriaQuery cq) { HqlRuleEnum rule = HqlRuleEnum.getByValue(tsDataRule.getRuleConditions()); if (rule.equals(HqlRuleEnum.IN)) { String[] values = tsDataRule.getRuleValue().split(","); Object[] objs = new Object[values.length]; if (! propertyType.equals(String.class)) { for (int i = 0; i < values.length; i++) { objs[i] = NumberUtils.parseNumber(values[i], propertyType); } }else { objs = values; } ObjectParseUtil.addCriteria(cq, aliasName, rule, objs); } else { if (propertyType.equals(String.class)) { ObjectParseUtil.addCriteria(cq, aliasName, rule,converRuleValue(tsDataRule.getRuleValue())); } else { ObjectParseUtil.addCriteria(cq, aliasName, rule, NumberUtils.parseNumber(tsDataRule.getRuleValue(), propertyType)); } } }
Example #15
Source File: CustomNumberEditor.java From java-technology-stack with MIT License | 6 votes |
/** * Parse the Number from the given text, using the specified NumberFormat. */ @Override public void setAsText(String text) throws IllegalArgumentException { if (this.allowEmpty && !StringUtils.hasText(text)) { // Treat empty String as null value. setValue(null); } else if (this.numberFormat != null) { // Use given NumberFormat for parsing text. setValue(NumberUtils.parseNumber(text, this.numberClass, this.numberFormat)); } else { // Use default valueOf methods for parsing text. setValue(NumberUtils.parseNumber(text, this.numberClass)); } }
Example #16
Source File: QueueMessageUtils.java From spring-cloud-aws with Apache License 2.0 | 6 votes |
public static Object parseNumber(String value, String type) throws ClassNotFoundException { if (MessageAttributeDataTypes.NUMBER.equals(type)) { return NumberUtils.parseNumber(value, Number.class); } else { String javaType = type .substring(MessageAttributeDataTypes.NUMBER.length() + 1); if (PRIMITIVE_TO_WRAPPED.containsKey(javaType.toLowerCase())) { return NumberUtils.parseNumber(value, PRIMITIVE_TO_WRAPPED.get(javaType.toLowerCase())); } else { Class<? extends Number> numberTypeClass = Class.forName(javaType) .asSubclass(Number.class); return NumberUtils.parseNumber(value, numberTypeClass); } } }
Example #17
Source File: QueryGenerator.java From teaching with Apache License 2.0 | 6 votes |
private static void addRuleToQueryWrapper(SysPermissionDataRuleModel dataRule, String name, Class propertyType, QueryWrapper<?> queryWrapper) { QueryRuleEnum rule = QueryRuleEnum.getByValue(dataRule.getRuleConditions()); if(rule.equals(QueryRuleEnum.IN) && ! propertyType.equals(String.class)) { String[] values = dataRule.getRuleValue().split(","); Object[] objs = new Object[values.length]; for (int i = 0; i < values.length; i++) { objs[i] = NumberUtils.parseNumber(values[i], propertyType); } addEasyQuery(queryWrapper, name, rule, objs); }else { if (propertyType.equals(String.class)) { addEasyQuery(queryWrapper, name, rule, converRuleValue(dataRule.getRuleValue())); } else { addEasyQuery(queryWrapper, name, rule, NumberUtils.parseNumber(dataRule.getRuleValue(), propertyType)); } } }
Example #18
Source File: QueryGenerator.java From jeecg-boot-with-activiti with MIT License | 6 votes |
private static void addRuleToQueryWrapper(SysPermissionDataRule dataRule,String name, Class propertyType, QueryWrapper<?> queryWrapper) { QueryRuleEnum rule = QueryRuleEnum.getByValue(dataRule.getRuleConditions()); if(rule.equals(QueryRuleEnum.IN) && ! propertyType.equals(String.class)) { String[] values = dataRule.getRuleValue().split(","); Object[] objs = new Object[values.length]; for (int i = 0; i < values.length; i++) { objs[i] = NumberUtils.parseNumber(values[i], propertyType); } addEasyQuery(queryWrapper, name, rule, objs); }else { if (propertyType.equals(String.class)) { addEasyQuery(queryWrapper, name, rule, converRuleValue(dataRule.getRuleValue())); } else { addEasyQuery(queryWrapper, name, rule, NumberUtils.parseNumber(dataRule.getRuleValue(), propertyType)); } } }
Example #19
Source File: QueryGenerator.java From jeecg-boot with Apache License 2.0 | 6 votes |
private static void addRuleToQueryWrapper(SysPermissionDataRuleModel dataRule, String name, Class propertyType, QueryWrapper<?> queryWrapper) { QueryRuleEnum rule = QueryRuleEnum.getByValue(dataRule.getRuleConditions()); if(rule.equals(QueryRuleEnum.IN) && ! propertyType.equals(String.class)) { String[] values = dataRule.getRuleValue().split(","); Object[] objs = new Object[values.length]; for (int i = 0; i < values.length; i++) { objs[i] = NumberUtils.parseNumber(values[i], propertyType); } addEasyQuery(queryWrapper, name, rule, objs); }else { if (propertyType.equals(String.class)) { addEasyQuery(queryWrapper, name, rule, converRuleValue(dataRule.getRuleValue())); }else if (propertyType.equals(Date.class)) { String dateStr =converRuleValue(dataRule.getRuleValue()); if(dateStr.length()==10){ addEasyQuery(queryWrapper, name, rule, DateUtils.str2Date(dateStr,DateUtils.date_sdf.get())); }else{ addEasyQuery(queryWrapper, name, rule, DateUtils.str2Date(dateStr,DateUtils.datetimeFormat.get())); } }else { addEasyQuery(queryWrapper, name, rule, NumberUtils.parseNumber(dataRule.getRuleValue(), propertyType)); } } }
Example #20
Source File: StringToNumberConverterFactory.java From spring4-understanding with Apache License 2.0 | 5 votes |
@Override public T convert(String source) { if (source.length() == 0) { return null; } return NumberUtils.parseNumber(source, this.targetType); }
Example #21
Source File: OperatorPower.java From java-technology-stack with MIT License | 5 votes |
@Override public TypedValue getValueInternal(ExpressionState state) throws EvaluationException { SpelNodeImpl leftOp = getLeftOperand(); SpelNodeImpl rightOp = getRightOperand(); Object leftOperand = leftOp.getValueInternal(state).getValue(); Object rightOperand = rightOp.getValueInternal(state).getValue(); if (leftOperand instanceof Number && rightOperand instanceof Number) { Number leftNumber = (Number) leftOperand; Number rightNumber = (Number) rightOperand; if (leftNumber instanceof BigDecimal) { BigDecimal leftBigDecimal = NumberUtils.convertNumberToTargetClass(leftNumber, BigDecimal.class); return new TypedValue(leftBigDecimal.pow(rightNumber.intValue())); } else if (leftNumber instanceof BigInteger) { BigInteger leftBigInteger = NumberUtils.convertNumberToTargetClass(leftNumber, BigInteger.class); return new TypedValue(leftBigInteger.pow(rightNumber.intValue())); } else if (leftNumber instanceof Double || rightNumber instanceof Double) { return new TypedValue(Math.pow(leftNumber.doubleValue(), rightNumber.doubleValue())); } else if (leftNumber instanceof Float || rightNumber instanceof Float) { return new TypedValue(Math.pow(leftNumber.floatValue(), rightNumber.floatValue())); } double d = Math.pow(leftNumber.doubleValue(), rightNumber.doubleValue()); if (d > Integer.MAX_VALUE || leftNumber instanceof Long || rightNumber instanceof Long) { return new TypedValue((long) d); } else { return new TypedValue((int) d); } } return state.operate(Operation.POWER, leftOperand, rightOperand); }
Example #22
Source File: PeriodicTriggerTests.java From spring4-understanding with Apache License 2.0 | 5 votes |
private static Date asDate(Object o) { if (o == null) { return null; } if (o instanceof Date) { return (Date) o; } if (o instanceof Number) { return new Date(System.currentTimeMillis() + NumberUtils.convertNumberToTargetClass((Number) o, Long.class)); } throw new IllegalArgumentException( "expected Date or Number, but actual type was: " + o.getClass()); }
Example #23
Source File: WebSlider.java From cuba with Apache License 2.0 | 5 votes |
@SuppressWarnings("unchecked") protected V convertFromDouble(Double componentValue) throws ConversionException { if (componentValue == null) { return null; } Datatype<V> datatype = getDatatype(); return (V) NumberUtils.convertNumberToTargetClass(componentValue, datatype.getJavaClass()); }
Example #24
Source File: CustomNumberEditor.java From blog_demos with Apache License 2.0 | 5 votes |
/** * Coerce a Number value into the required target class, if necessary. */ @Override public void setValue(Object value) { if (value instanceof Number) { super.setValue(NumberUtils.convertNumberToTargetClass((Number) value, this.numberClass)); } else { super.setValue(value); } }
Example #25
Source File: QueryGenerator.java From teaching with Apache License 2.0 | 5 votes |
/** * 根据权限相关配置生成相关的SQL 语句 * @param searchObj * @param parameterMap * @return */ @SuppressWarnings({ "unchecked", "rawtypes" }) public static String installAuthJdbc(Class<?> clazz) { StringBuffer sb = new StringBuffer(); //权限查询 Map<String,SysPermissionDataRuleModel> ruleMap = getRuleMap(); PropertyDescriptor origDescriptors[] = PropertyUtils.getPropertyDescriptors(clazz); String sql_and = " and "; for (String c : ruleMap.keySet()) { if(oConvertUtils.isNotEmpty(c) && c.startsWith(SQL_RULES_COLUMN)){ sb.append(sql_and+getSqlRuleValue(ruleMap.get(c).getRuleValue())); } } String name; for (int i = 0; i < origDescriptors.length; i++) { name = origDescriptors[i].getName(); if (judgedIsUselessField(name)) { continue; } if(ruleMap.containsKey(name)) { SysPermissionDataRuleModel dataRule = ruleMap.get(name); QueryRuleEnum rule = QueryRuleEnum.getByValue(dataRule.getRuleConditions()); Class propType = origDescriptors[i].getPropertyType(); boolean isString = propType.equals(String.class); Object value; if(isString) { value = converRuleValue(dataRule.getRuleValue()); }else { value = NumberUtils.parseNumber(dataRule.getRuleValue(),propType); } String filedSql = getSingleSqlByRule(rule, oConvertUtils.camelToUnderline(name), value,isString); sb.append(sql_and+filedSql); } } log.info("query auth sql is:"+sb.toString()); return sb.toString(); }
Example #26
Source File: QueryGenerator.java From jeecg-boot with Apache License 2.0 | 5 votes |
/** * 根据权限相关配置生成相关的SQL 语句 * @param searchObj * @param parameterMap * @return */ @SuppressWarnings({ "unchecked", "rawtypes" }) public static String installAuthJdbc(Class<?> clazz) { StringBuffer sb = new StringBuffer(); //权限查询 Map<String,SysPermissionDataRuleModel> ruleMap = getRuleMap(); PropertyDescriptor origDescriptors[] = PropertyUtils.getPropertyDescriptors(clazz); String sql_and = " and "; for (String c : ruleMap.keySet()) { if(oConvertUtils.isNotEmpty(c) && c.startsWith(SQL_RULES_COLUMN)){ sb.append(sql_and+getSqlRuleValue(ruleMap.get(c).getRuleValue())); } } String name; for (int i = 0; i < origDescriptors.length; i++) { name = origDescriptors[i].getName(); if (judgedIsUselessField(name)) { continue; } if(ruleMap.containsKey(name)) { SysPermissionDataRuleModel dataRule = ruleMap.get(name); QueryRuleEnum rule = QueryRuleEnum.getByValue(dataRule.getRuleConditions()); Class propType = origDescriptors[i].getPropertyType(); boolean isString = propType.equals(String.class); Object value; if(isString) { value = converRuleValue(dataRule.getRuleValue()); }else { value = NumberUtils.parseNumber(dataRule.getRuleValue(),propType); } String filedSql = getSingleSqlByRule(rule, oConvertUtils.camelToUnderline(name), value,isString); sb.append(sql_and+filedSql); } } log.info("query auth sql is:"+sb.toString()); return sb.toString(); }
Example #27
Source File: OperatorPower.java From lams with GNU General Public License v2.0 | 5 votes |
@Override public TypedValue getValueInternal(ExpressionState state) throws EvaluationException { SpelNodeImpl leftOp = getLeftOperand(); SpelNodeImpl rightOp = getRightOperand(); Object leftOperand = leftOp.getValueInternal(state).getValue(); Object rightOperand = rightOp.getValueInternal(state).getValue(); if (leftOperand instanceof Number && rightOperand instanceof Number) { Number leftNumber = (Number) leftOperand; Number rightNumber = (Number) rightOperand; if (leftNumber instanceof BigDecimal) { BigDecimal leftBigDecimal = NumberUtils.convertNumberToTargetClass(leftNumber, BigDecimal.class); return new TypedValue(leftBigDecimal.pow(rightNumber.intValue())); } else if (leftNumber instanceof BigInteger) { BigInteger leftBigInteger = NumberUtils.convertNumberToTargetClass(leftNumber, BigInteger.class); return new TypedValue(leftBigInteger.pow(rightNumber.intValue())); } else if (leftNumber instanceof Double || rightNumber instanceof Double) { return new TypedValue(Math.pow(leftNumber.doubleValue(), rightNumber.doubleValue())); } else if (leftNumber instanceof Float || rightNumber instanceof Float) { return new TypedValue(Math.pow(leftNumber.floatValue(), rightNumber.floatValue())); } double d = Math.pow(leftNumber.doubleValue(), rightNumber.doubleValue()); if (d > Integer.MAX_VALUE || leftNumber instanceof Long || rightNumber instanceof Long) { return new TypedValue((long) d); } else { return new TypedValue((int) d); } } return state.operate(Operation.POWER, leftOperand, rightOperand); }
Example #28
Source File: OperatorPower.java From spring4-understanding with Apache License 2.0 | 5 votes |
@Override public TypedValue getValueInternal(ExpressionState state) throws EvaluationException { SpelNodeImpl leftOp = getLeftOperand(); SpelNodeImpl rightOp = getRightOperand(); Object leftOperand = leftOp.getValueInternal(state).getValue(); Object rightOperand = rightOp.getValueInternal(state).getValue(); if (leftOperand instanceof Number && rightOperand instanceof Number) { Number leftNumber = (Number) leftOperand; Number rightNumber = (Number) rightOperand; if (leftNumber instanceof BigDecimal) { BigDecimal leftBigDecimal = NumberUtils.convertNumberToTargetClass(leftNumber, BigDecimal.class); return new TypedValue(leftBigDecimal.pow(rightNumber.intValue())); } else if (leftNumber instanceof BigInteger) { BigInteger leftBigInteger = NumberUtils.convertNumberToTargetClass(leftNumber, BigInteger.class); return new TypedValue(leftBigInteger.pow(rightNumber.intValue())); } else if (leftNumber instanceof Double || rightNumber instanceof Double) { return new TypedValue(Math.pow(leftNumber.doubleValue(), rightNumber.doubleValue())); } else if (leftNumber instanceof Float || rightNumber instanceof Float) { return new TypedValue(Math.pow(leftNumber.floatValue(), rightNumber.floatValue())); } double d = Math.pow(leftNumber.doubleValue(), rightNumber.doubleValue()); if (d > Integer.MAX_VALUE || leftNumber instanceof Long || rightNumber instanceof Long) { return new TypedValue((long) d); } else { return new TypedValue((int) d); } } return state.operate(Operation.POWER, leftOperand, rightOperand); }
Example #29
Source File: ProjectController.java From DBus with Apache License 2.0 | 5 votes |
@ApiOperation(value = "search projects", notes = "search projects by userId, roleType") @ApiResponses({ @ApiResponse(code = 200, message = "OK", response = Map[].class) }) @GetMapping("") public ResultEntity queryProjects(HttpServletRequest req) { Integer userId = null; if (StringUtils.isNotBlank(req.getParameter("__user_id"))) userId = NumberUtils.parseNumber(req.getParameter("__user_id"), Integer.class); String roleType = req.getParameter("__role_type"); return service.queryProjects(userId, roleType); }
Example #30
Source File: CustomNumberEditor.java From lams with GNU General Public License v2.0 | 5 votes |
/** * Coerce a Number value into the required target class, if necessary. */ @Override public void setValue(Object value) { if (value instanceof Number) { super.setValue(NumberUtils.convertNumberToTargetClass((Number) value, this.numberClass)); } else { super.setValue(value); } }