valueOf() private method

private valueOf ( global par0 ) : global::java.lang.Long
par0 global
return global::java.lang.Long
Example #1
0
        public static Long decode(String nm)
        {
            int     radix    = 10;
            int     index    = 0;
            boolean negative = false;
            Long    result;

            if (nm.length() == 0)
            {
                throw new NumberFormatException("Zero length string");
            }
            char firstChar = nm.charAt(0);

            // Handle sign, if present
            if (firstChar == '-')
            {
                negative = true;
                index++;
            }
            else if (firstChar == '+')
            {
                index++;
            }
            // Handle radix specifier, if present
            if (nm.startsWith(new String("0x"), index) || nm.startsWith(new String("0X"), index))
            {
                index += 2;
                radix  = 16;
            }
            else if (nm.startsWith(new String("#"), index))
            {
                index++;
                radix = 16;
            }
            else if (nm.startsWith(new String("0"), index) && nm.length() > 1 + index)
            {
                index++;
                radix = 8;
            }
            if (nm.startsWith(new String("-"), index) || nm.startsWith(new String("+"), index))
            {
                throw new NumberFormatException("Sign character in wrong position");
            }
            try {
                result = Long.valueOf(nm.substring(index), radix);
                result = negative ? Long.valueOf(-result.longValue()) : result;
            } catch (NumberFormatException) {
                // If number is Long.MIN_VALUE, we'll end up here. The next line
                // handles this case, and causes any genuine format error to be
                // rethrown.
                String constant = negative ? new String("-" + nm.substring(index))
                                       : nm.substring(index);
                result = Long.valueOf(constant, radix);
            }
            return(result);
        }
Example #2
0
        public static Long getLong(String nm, long val)
        {
            Long result = Long.getLong(nm, null);

            return((result == null) ? Long.valueOf(val) : result);
        }
Example #3
0
 public static Long valueOf(String s)
 {
     return(Long.valueOf(parseLong(s, 10)));
 }
Example #4
0
 public static Long valueOf(String s, int radix)
 {
     return(Long.valueOf(parseLong(s, radix)));
 }