<p>
Convert a <code>String</code> to a <code>BigDecimal</code>.
</p>

<p>
Returns an empty {@code Optional} if the string is {@code null} or can't be parsed as {@code BigDecimal}.
</p>

@param str a <code>String</code> to convert, may be null
@return
760454
public static Optional<BigDecimal> createBigDecimal(final String str) {
        if (N.isNullOrEmptyOrBlank(str) || str.trim().startsWith("--")) {
            return Optional.empty();
        }

        try {
            return Optional.of(new BigDecimal(str));
        } catch (NumberFormatException e) {
            return Optional.empty();
        }
    }
196436
public BigDecimal getValueAsBigDecimal() {
        String value = (String) $(valueBoxBase.getElement()).val();
        if (value != null && !value.isEmpty()) {
            return new BigDecimal(value);
        } else {
            return null;
        }
    }
604369
private static Integer toInt(String str) {

        Integer num = null;
        try {
            num = Integer.parseInt(str);
        } catch (NumberFormatException ex) {
            log.severe(String.format("failed to convert str: %s to integer", str));
        }

        return num;
    }
906866
public static long indexFromString(String str)
    {
        // The length of the decimal string representation of
        //  Integer.MAX_VALUE, 2147483647
        final int MAX_VALUE_LENGTH = 10;

        int len = str.length();
        if (len > 0) {
            int i = 0;
            boolean negate = false;
            int c = str.charAt(0);
            if (c == '-') {
                if (len > 1) {
                    c = str.charAt(1);
                    if (c == '0') return -1L; // "-0" is not an index
                    i = 1;
                    negate = true;
                }
            }
            c -= '0';
            if (0 <= c && c <= 9
                && len <= (negate ? MAX_VALUE_LENGTH + 1 : MAX_VALUE_LENGTH))
            {
                // Use negative numbers to accumulate index to handle
                // Integer.MIN_VALUE that is greater by 1 in absolute value
                // then Integer.MAX_VALUE
                int index = -c;
                int oldIndex = 0;
                i++;
                if (index != 0) {
                    // Note that 00, 01, 000 etc. are not indexes
                    while (i != len && 0 <= (c = str.charAt(i) - '0') && c <= 9)
                    {
                        oldIndex = index;
                        index = 10 * index - c;
                        i++;
                    }
                }
                // Make sure all characters were consumed and that it couldn't
                // have overflowed.
                if (i == len &&
                    (oldIndex > (Integer.MIN_VALUE / 10) ||
                     (oldIndex == (Integer.MIN_VALUE / 10) &&
                      c <= (negate ? -(Integer.MIN_VALUE % 10)
                                   : (Integer.MAX_VALUE % 10)))))
                {
                    return 0xFFFFFFFFL & (negate ? index : -index);
                }
            }
        }
        return -1L;
    }
650658
public static String decode(String str) {
    if (str!=null) {
      try {
        StringBuilder sb = new StringBuilder();
        for (int idx = str.toLowerCase().indexOf("%2f"); idx>=0; idx = str.toLowerCase().indexOf("%2f")) {
          sb.append(java.net.URLDecoder.decode(str.substring(0, idx),"UTF-8")).append(str.substring(idx, idx+3));
          str = str.substring(idx+3);
        }
        sb.append(java.net.URLDecoder.decode(str,"UTF-8"));
        str = sb.toString();
      } catch (Exception ex) {
      }
    }
    return str;
  }
1232281
public static Number createNumber(String str) throws ParseException
    {
        try
        {
            if (str.indexOf('.') != -1)
            {
                return Double.valueOf(str);
            }
            return Long.valueOf(str);
        }
        catch (NumberFormatException e)
        {
            throw new ParseException(e.getMessage());
        }
    }
643819
public static Stream fromString(String str) {
        if (str == null || str.isEmpty()) {
            throw new IllegalArgumentException("Cannot create a stream from an empty or null string");
        }
        Stream stream = new Stream();
        stream.hash = str;
        return stream;
    }
613695
public static String initCap(String str) {
        assertStringNotNull(str);
        if (is_Null_or_Empty(str)) {
            return str;
        }
        if (str.length() == 1) {
            return str.toUpperCase();
        }
        final char chars[] = str.toCharArray();
        chars[0] = Character.toUpperCase(chars[0]);
        return new String(chars);
    }
469147
public static long toLongValue(String str) throws PageException {
	BigInteger bi = null;
	try {
	    bi = new BigInteger(str);

	}
	catch (Throwable t) {
	    ExceptionUtil.rethrowIfNecessary(t);
	}
	if (bi != null) {
	    if (bi.bitLength() < 64) return bi.longValue();
	    throw new ApplicationException("number [" + str + "] cannot be casted to a long value, number is to long (" + (bi.bitLength() + 1) + " bit)");
	}
	return (long) toDoubleValue(str);
    }
1355863
public static boolean isDelimiter(String str)
    {
        if (str != null && ("-".equals(str) || "－".equals(str)))
            return true;
        else
            return false;
    }
49921
public static String emptyToNull(String str) {
        return (str != null && !str.isEmpty()) ? str : null;
    }
416709
public static Integer str2state(String str)
    {
        Integer state;

        if (str == null)
        {
            return null;
        }

        state = inverseStateMap.get(str);

        if (state == null)
        {
            Matcher matcher = UNKNOWN_STATE_PATTERN.matcher(str);
            if (matcher.matches())
            {
                try
                {
                    state = Integer.valueOf(matcher.group(1));
                }
                catch (NumberFormatException e)
                {
                    // should not happen as the pattern requires \d+ for the state.
                    throw new IllegalArgumentException("Unable to convert state '" + str + "' to integer representation", e);
                }
            }
        }

        return state;
    }
1137434
public Coin parse(String str) throws NumberFormatException {
        return Coin.valueOf(parseValue(str, Coin.SMALLEST_UNIT_EXPONENT));
    }
578283
public static String getAdiVarna(String str)
    {
        if (str.length() == 0) return null;
        String adiVarna = String.valueOf(str.charAt(0));

        if (str.length() > 1 && str.charAt(1) == '3') // for pluta
        {
            adiVarna += String.valueOf(str.charAt(1));
        }

        return adiVarna;

    }
333249
public static Double stringToDouble(String strString, int ibScale) throws Exception
    {
        Number objData;
        initGlobals();      // Make sure you have the utilities
        if ((strString == null) || (strString.equals(Constant.BLANK)))
            return null;
        strString = DataConverters.stripNonNumber(strString);
        try   {
            synchronized (gNumberFormat)
            {
                objData = gNumberFormat.parse(strString);
            }
            if (!(objData instanceof Double))
            {
                if (objData instanceof Number)
                    objData = new Double(objData.doubleValue());
                else
                    objData = null;
            }
        } catch (ParseException ex)   {
            objData = null;
        }
        if (objData == null)
        {
            try   {
                objData = new Double(strString);
            } catch (NumberFormatException ex)  {
                throw ex;
            }
        }
        if (ibScale != -1)
            objData = new Double(Math.floor(((Double)objData).doubleValue() * Math.pow(10, ibScale) + 0.5) / Math.pow(10, ibScale));
        return (Double)objData;
    }
1256015
public int
getValue(String str) {
	str = sanitize(str);
	Integer value = (Integer) strings.get(str);
	if (value != null) {
		return value.intValue();
	}
	if (prefix != null) {
		if (str.startsWith(prefix)) {
			int val = parseNumeric(str.substring(prefix.length()));
			if (val >= 0) {
				return val;
			}
		}
	}
	if (numericok) {
		return parseNumeric(str);
	}
	return -1;
}
1178013
public static PrivateKey stringToRSAPrivateKey (String str)
    {
        try {
            BigInteger mod = new BigInteger(str.substring(0, str.indexOf(SPLIT)), 16);
            BigInteger exp = new BigInteger(str.substring(str.indexOf(SPLIT) + 1), 16);
            RSAPrivateKeySpec keySpec = new RSAPrivateKeySpec(mod, exp);
            KeyFactory kf = KeyFactory.getInstance("RSA");
            return kf.generatePrivate(keySpec);
        } catch (NumberFormatException nfe) {
            log.warning("Failed to read key from string.", "str", str, nfe);
        } catch (GeneralSecurityException gse) {
            log.warning("Failed to read key from string.", "str", str, gse);
        }
        return null;
    }