Example usage for java.lang Character MIN_RADIX

List of usage examples for java.lang Character MIN_RADIX

Introduction

In this page you can find the example usage for java.lang Character MIN_RADIX.

Prototype

int MIN_RADIX

To view the source code for java.lang Character MIN_RADIX.

Click Source Link

Document

The minimum radix available for conversion to and from strings.

Usage

From source file:Main.java

public static void main(String[] args) {
    System.out.println("Character.MIN_RADIX:" + Character.MIN_RADIX);
}

From source file:Main.java

public static int parseInt(char[] string, int start, int length, int radix) throws NumberFormatException {
    if (radix < Character.MIN_RADIX || radix > Character.MAX_RADIX) {
        throw new NumberFormatException("Invalid radix: " + radix);
    }//from ww  w.jav  a  2 s.  c om
    if (string == null) {
        throw new NumberFormatException(new String(string, start, length));
    }
    int i = 0;
    if (length == 0) {
        throw new NumberFormatException(new String(string, start, length));
    }
    boolean negative = string[start + i] == '-';
    if (negative && ++i == length) {
        throw new NumberFormatException(new String(string, start, length));
    }

    return parse(string, start, length, i, radix, negative);
}

From source file:Main.java

/**
 * Parses the string argument as if it was an int value and returns the
 * result. Throws NumberFormatException if the string does not represent an
 * int quantity. The second argument specifies the radix to use when parsing
 * the value.//w  w w . ja  v a 2s .c  om
 *
 * @param chars a string representation of an int quantity.
 * @param radix the base to use for conversion.
 * @return int the value represented by the argument
 * @throws NumberFormatException if the argument could not be parsed as an int quantity.
 */
public static int parseInt(char[] chars, int offset, int len, int radix) throws NumberFormatException {
    if (chars == null || radix < Character.MIN_RADIX || radix > Character.MAX_RADIX) {
        throw new NumberFormatException();
    }
    int i = 0;
    if (len == 0) {
        throw new NumberFormatException("chars length is 0");
    }
    boolean negative = chars[offset + i] == '-';
    if (negative && ++i == len) {
        throw new NumberFormatException("can't convert to an int");
    }
    if (negative == true) {
        offset++;
        len--;
    }
    return parse(chars, offset, len, radix, negative);
}

From source file:org.apache.hadoop.hive.ql.udf.UDFConv.java

public Text evaluate(Text n, IntWritable fromBase, IntWritable toBase) {
    if (n == null || n.toString().equalsIgnoreCase("") || fromBase == null || toBase == null) {
        return null;
    }//  w  w  w.ja va2s.c om

    int fromBs = fromBase.get();
    int toBs = toBase.get();
    if (fromBs < Character.MIN_RADIX || fromBs > Character.MAX_RADIX || Math.abs(toBs) < Character.MIN_RADIX
            || Math.abs(toBs) > Character.MAX_RADIX) {
        return null;
    }

    byte[] num = n.getBytes();
    boolean negative = (num[0] == '-');
    int first = 0;
    if (negative) {
        first = 1;
    }
    Arrays.fill(value, (byte) 0);

    for (int i = 1; i <= n.getLength() - first; i++) {
        value[value.length - i] = num[n.getLength() - i];
    }
    char2byte(fromBs, value.length - n.getLength() + first);

    long val = encode(fromBs);
    if (negative && toBs > 0) {
        if (val < 0) {
            val = -1;
        } else {
            val = -val;
        }
    }
    if (toBs < 0 && val < 0) {
        val = -val;
        negative = true;
    }
    decode(val, Math.abs(toBs));

    for (first = 0; first < value.length - 1 && value[first] == 0; first++)
        ;

    byte2char(Math.abs(toBs), first);

    if (negative && toBs < 0) {
        value[--first] = '-';
    }

    result.set(value, first, value.length - first);
    return result;
}