List of usage examples for org.apache.commons.lang3.math NumberUtils isNumber
public static boolean isNumber(final String str)
Checks whether the String a valid Java number.
Valid numbers include hexadecimal marked with the 0x
or 0X
qualifier, octal numbers, scientific notation and numbers marked with a type qualifier (e.g.
From source file:org.flowable.editor.dmn.converter.DmnJsonConverterUtil.java
public static String determineExpressionType(String expressionValue) { String expressionType = null; if (!"-".equals(expressionValue)) { expressionType = "string"; if (NumberUtils.isNumber(expressionValue)) { expressionType = "number"; } else {//from w w w . j a v a 2 s. c om try { new SimpleDateFormat("yyyy-MM-dd").parse(expressionValue); expressionType = "date"; } catch (ParseException pe) { if ("true".equalsIgnoreCase(expressionValue) || "false".equalsIgnoreCase(expressionType)) { expressionType = "boolean"; } } } } return expressionType; }
From source file:org.flowable.editor.language.json.converter.UserTaskJsonConverter.java
protected int getExtensionElementValueAsInt(String name, UserTask userTask) { int intValue = 0; String value = getExtensionElementValue(name, userTask); if (value != null && NumberUtils.isNumber(value)) { intValue = Integer.valueOf(value); }//w w w . j a va 2 s . c om return intValue; }
From source file:org.flowable.form.engine.impl.cmd.GetVariablesFromFormSubmissionCmd.java
@SuppressWarnings("unchecked") protected Object transformFormFieldValueToVariableValue(FormField formField, Object formFieldValue) { Object result = formFieldValue; if (formField.getType().equals(FormFieldTypes.DATE)) { if (StringUtils.isNotEmpty((String) formFieldValue)) { try { result = LocalDate.parse((String) formFieldValue); } catch (Exception e) { e.printStackTrace();// w ww. ja va 2s. co m result = null; } } } else if (formField.getType().equals(FormFieldTypes.INTEGER) && formFieldValue instanceof String) { String strFieldValue = (String) formFieldValue; if (StringUtils.isNotEmpty(strFieldValue) && NumberUtils.isNumber(strFieldValue)) { result = Long.valueOf(strFieldValue); } else { result = null; } } else if (formField.getType().equals(FormFieldTypes.AMOUNT) && formFieldValue instanceof String) { try { result = Double.parseDouble((String) formFieldValue); } catch (NumberFormatException e) { result = null; } } else if (formField.getType().equals(FormFieldTypes.DROPDOWN)) { if (formFieldValue instanceof Map<?, ?>) { result = ((Map<?, ?>) formFieldValue).get("id"); if (result == null) { // fallback to name for manual config options result = ((Map<?, ?>) formFieldValue).get("name"); } } } else if (formField.getType().equals(FormFieldTypes.UPLOAD)) { result = (String) formFieldValue; } else if (formField.getType().equals(FormFieldTypes.PEOPLE) || formField.getType().equals(FormFieldTypes.FUNCTIONAL_GROUP)) { if (formFieldValue instanceof Map<?, ?>) { Map<String, Object> value = (Map<String, Object>) formFieldValue; Object id = value.get("id"); if (id instanceof Number) { result = ((Number) id).longValue(); } else { // Wrong type, ignore result = null; } } else { // Incorrect or empty map, ignore result = null; } } // Default: no processing needs to be done, can be stored as-is return result; }
From source file:org.goko.controller.grbl.v08.GrblCommunicator.java
private void parseTuple(String[] values, Tuple6b target) throws GkException { if (values != null && values.length >= 3) { Unit<Length> unit = grbl.getConfiguration().getReportUnit(); if (NumberUtils.isNumber(values[0])) { target.setX(Length.valueOf(new BigDecimal(values[0]), unit)); }/*from w ww .j a v a 2 s . c o m*/ if (NumberUtils.isNumber(values[1])) { target.setY(Length.valueOf(new BigDecimal(values[1]), unit)); } if (NumberUtils.isNumber(values[2])) { target.setZ(Length.valueOf(new BigDecimal(values[2]), unit)); } } }
From source file:org.goko.controller.grbl.v09.GrblCommunicator.java
private void parseTuple(Tuple6b target, String... values) throws GkException { if (values != null && values.length >= 3) { Unit<Length> unit = grbl.getConfiguration().getReportUnit(); if (NumberUtils.isNumber(values[0])) { target.setX(Length.valueOf(new BigDecimal(values[0]), unit)); }/* ww w. j a v a 2 s. co m*/ if (NumberUtils.isNumber(values[1])) { target.setY(Length.valueOf(new BigDecimal(values[1]), unit)); } if (NumberUtils.isNumber(values[2])) { target.setZ(Length.valueOf(new BigDecimal(values[2]), unit)); } } }
From source file:org.goko.grbl.controller.GrblCommunicator.java
private void parseTuple(String[] values, Tuple6b target) throws GkException { if (values != null && values.length >= 3) { Unit<Length> unit = grbl.getConfiguration().getReportUnit(); if (NumberUtils.isNumber(values[0])) { target.setX(NumberQuantity.of(new BigDecimal(values[0]), unit)); }/*from ww w . j av a2 s . co m*/ if (NumberUtils.isNumber(values[1])) { target.setY(NumberQuantity.of(new BigDecimal(values[1]), unit)); } if (NumberUtils.isNumber(values[2])) { target.setZ(NumberQuantity.of(new BigDecimal(values[2]), unit)); } } }
From source file:org.gvnix.web.datatables.util.DatatablesUtils.java
public static boolean checkNumericFilters(String expression, MessageSource messageSource) { if (NumberUtils.isNumber(expression)) { return true; } else {//from w ww . j a v a 2s . c o m // Getting expressions with symbols Pattern symbolOperator = Pattern.compile("([!=><][=>]?)([-]?[\\d.,]*)"); Matcher symbolMatcher = symbolOperator.matcher(expression); if (symbolMatcher.matches()) { String symbolExpression = symbolMatcher.group(1); String value = symbolMatcher.group(2); if (!StringUtils.isBlank(value)) { if (symbolExpression.equals("=") || symbolExpression.equals("==")) { return true; } else if (symbolExpression.equals(">") || symbolExpression.equals(">>")) { return true; } else if (symbolExpression.equals("<")) { return true; } else if (symbolExpression.equals(">=")) { return true; } else if (symbolExpression.equals("<=")) { return true; } else if (symbolExpression.equals("!=") || symbolExpression.equals("<>")) { return true; } } } // Get all operations String isNullOperation = ISNULL_OPE; String isNotNullOperation = NOTNULL_OPE; String betweenOperation = "BETWEEN"; if (messageSource != null) { isNullOperation = messageSource.getMessage(G_ISNULL_OPE, null, LocaleContextHolder.getLocale()); isNotNullOperation = messageSource.getMessage(G_NOTNULL_OPE, null, LocaleContextHolder.getLocale()); betweenOperation = messageSource.getMessage("global.filters.operations.number.between", null, LocaleContextHolder.getLocale()); } // If written function is BETWEEN function Pattern betweenFunctionOperator = Pattern .compile(String.format("%s[(]([-]?[\\d.,]*);([-]?[\\d.,]*)[)]", betweenOperation)); Matcher betweenFunctionMatcher = betweenFunctionOperator.matcher(expression); if (betweenFunctionMatcher.matches()) { // Getting valueFrom and valueTo String valueFrom = betweenFunctionMatcher.group(1); String valueTo = betweenFunctionMatcher.group(2); if (!StringUtils.isBlank(valueFrom) && !StringUtils.isBlank(valueTo)) { return true; } } // If written expression is ISNULL operation Pattern isNullOperator = Pattern.compile(String.format("%s", isNullOperation)); Matcher isNullMatcher = isNullOperator.matcher(expression); if (isNullMatcher.matches()) { return true; } // If written expression is ISNOTNULL operation Pattern isNotNullOperator = Pattern.compile(String.format("%s", isNotNullOperation)); Matcher isNotNullMatcher = isNotNullOperator.matcher(expression); if (isNotNullMatcher.matches()) { return true; } } return false; }
From source file:org.gvnix.web.datatables.util.impl.DatatablesUtilsBeanImpl.java
@Override public boolean checkNumericFilters(String expression) { if (NumberUtils.isNumber(expression)) { return true; } else {//from w ww .j a v a 2 s . c om // Getting expressions with symbols Pattern symbolOperator = Pattern.compile("([!=><][=>]?)([-]?[\\d.,]*)"); Matcher symbolMatcher = symbolOperator.matcher(expression); if (symbolMatcher.matches()) { String symbolExpression = symbolMatcher.group(1); String value = symbolMatcher.group(2); if (!StringUtils.isBlank(value)) { if (symbolExpression.equals("=") || symbolExpression.equals("==")) { return true; } else if (symbolExpression.equals(">") || symbolExpression.equals(">>")) { return true; } else if (symbolExpression.equals("<")) { return true; } else if (symbolExpression.equals(">=")) { return true; } else if (symbolExpression.equals("<=")) { return true; } else if (symbolExpression.equals("!=") || symbolExpression.equals("<>")) { return true; } } } // Get all operations String isNullOperation = ISNULL_OPE; String isNotNullOperation = NOTNULL_OPE; String betweenOperation = "BETWEEN"; if (messageSource != null) { isNullOperation = messageSource.getMessage(G_ISNULL_OPE, null, LocaleContextHolder.getLocale()); isNotNullOperation = messageSource.getMessage(G_NOTNULL_OPE, null, LocaleContextHolder.getLocale()); betweenOperation = messageSource.getMessage("global.filters.operations.number.between", null, LocaleContextHolder.getLocale()); } // If written function is BETWEEN function Pattern betweenFunctionOperator = Pattern .compile(String.format("%s[(]([-]?[\\d.,]*);([-]?[\\d.,]*)[)]", betweenOperation)); Matcher betweenFunctionMatcher = betweenFunctionOperator.matcher(expression); if (betweenFunctionMatcher.matches()) { // Getting valueFrom and valueTo String valueFrom = betweenFunctionMatcher.group(1); String valueTo = betweenFunctionMatcher.group(2); if (!StringUtils.isBlank(valueFrom) && !StringUtils.isBlank(valueTo)) { return true; } } // If written expression is ISNULL operation Pattern isNullOperator = Pattern.compile(String.format("%s", isNullOperation)); Matcher isNullMatcher = isNullOperator.matcher(expression); if (isNullMatcher.matches()) { return true; } // If written expression is ISNOTNULL operation Pattern isNotNullOperator = Pattern.compile(String.format("%s", isNotNullOperation)); Matcher isNotNullMatcher = isNotNullOperator.matcher(expression); if (isNotNullMatcher.matches()) { return true; } } return false; }
From source file:org.gvnix.web.datatables.util.QuerydslUtils.java
/** * Check if a string is valid for a type <br/> * If conversion service is not provided try to check by apache commons * utilities. <b>TODO</b> in this (no-conversionService) case just * implemented for numerics//from w w w . j av a 2 s . c o m * * @param string * @param typeDescriptor * @param conversionService (optional) * @return */ private static boolean isValidValueFor(String string, TypeDescriptor typeDescriptor, ConversionService conversionService) { if (conversionService != null) { try { conversionService.convert(string, STRING_TYPE_DESCRIPTOR, typeDescriptor); } catch (ConversionException e) { return false; } return true; } else { Class<?> fieldType = typeDescriptor.getType(); if (Number.class.isAssignableFrom(fieldType) || NUMBER_PRIMITIVES.contains(fieldType)) { return NumberUtils.isNumber(string); } // TODO implement other types return true; } }
From source file:org.hac.service.impl.LengthCheck.java
/** * ??//from w ww. java2 s . c o m */ @SuppressWarnings("unchecked") @Override protected Map<String, Object> executeService(Map<String, Object> inputData) throws TsrvfwSystemException, TsrvfwBusinessException { // ??? if (!LogicUtils.isNotEmptyMap(inputData)) { throw new HACSystemException("?????"); } // ?? for (Map.Entry<String, ?> e : inputData.entrySet()) { Map<String, Object> valueMap = (Map<String, Object>) inputData.get(e.getKey()); // ??? if (!LogicUtils.isNotEmptyMap(valueMap)) { throw new HACSystemException("?????"); } String data = LogicUtils.getMapValueToString(valueMap, "data"); String length = LogicUtils.getMapValueToString(valueMap, "length"); if (!NumberUtils.isNumber(length)) { throw new HACSystemException("?????"); } if (LogicUtils.isNotEmptyString(data)) { if (data.length() >= Integer.parseInt(length)) { throw new HACBusinessException(this.getClass().getName() + ":00001", "", (String[]) valueMap.get("name")); } } } Map<String, Object> resultMap = new HashMap<String, Object>(); resultMap.put(ActionCommonConst.RESULT_CODE, ActionCommonConst.RESULT_SUCCESS); return resultMap; }