home *** CD-ROM | disk | FTP | other *** search
- package java.lang;
-
- public final class Integer extends Number {
- public static final int MIN_VALUE = -2147483648;
- public static final int MAX_VALUE = 2147483647;
- private int value;
-
- public static String toString(int i, int radix) {
- if (radix < 2 || radix > 36) {
- radix = 10;
- }
-
- StringBuffer buf = new StringBuffer(radix >= 8 ? 12 : 33);
- boolean negative = i < 0;
- if (!negative) {
- i = -i;
- }
-
- while(i <= -radix) {
- buf.append(Character.forDigit(-(i % radix), radix));
- i /= radix;
- }
-
- buf.append(Character.forDigit(-i, radix));
- if (negative) {
- buf.append('-');
- }
-
- return buf.reverse().toString();
- }
-
- public static String toHexString(int i) {
- return toUnsignedString(i, 4);
- }
-
- public static String toOctalString(int i) {
- return toUnsignedString(i, 3);
- }
-
- public static String toBinaryString(int i) {
- return toUnsignedString(i, 1);
- }
-
- private static String toUnsignedString(int i, int shift) {
- StringBuffer buf = new StringBuffer(shift >= 3 ? 11 : 32);
- int radix = 1 << shift;
- int mask = radix - 1;
-
- do {
- buf.append(Character.forDigit(i & mask, radix));
- i >>>= shift;
- } while(i != 0);
-
- return buf.reverse().toString();
- }
-
- public static String toString(int i) {
- return toString(i, 10);
- }
-
- public static int parseInt(String s, int radix) throws NumberFormatException {
- if (s == null) {
- throw new NumberFormatException("null");
- } else {
- int result = 0;
- boolean negative = false;
- int i = 0;
- int max = s.length();
- if (max <= 0) {
- throw new NumberFormatException(s);
- } else {
- if (s.charAt(0) == '-') {
- negative = true;
- ++i;
- }
-
- while(i < max) {
- int digit = Character.digit(s.charAt(i++), radix);
- if (digit < 0) {
- throw new NumberFormatException(s);
- }
-
- result = result * radix + digit;
- }
-
- return negative ? -result : result;
- }
- }
- }
-
- public static int parseInt(String s) throws NumberFormatException {
- return parseInt(s, 10);
- }
-
- public static Integer valueOf(String s, int radix) throws NumberFormatException {
- return new Integer(parseInt(s, radix));
- }
-
- public static Integer valueOf(String s) throws NumberFormatException {
- return new Integer(parseInt(s, 10));
- }
-
- public Integer(int value) {
- this.value = value;
- }
-
- public Integer(String s) throws NumberFormatException {
- this.value = parseInt(s, 10);
- }
-
- public int intValue() {
- return this.value;
- }
-
- public long longValue() {
- return (long)this.value;
- }
-
- public float floatValue() {
- return (float)this.value;
- }
-
- public double doubleValue() {
- return (double)this.value;
- }
-
- public String toString() {
- return String.valueOf(this.value);
- }
-
- public int hashCode() {
- return this.value;
- }
-
- public boolean equals(Object obj) {
- if (obj != null && obj instanceof Integer) {
- return this.value == (Integer)obj;
- } else {
- return false;
- }
- }
-
- public static Integer getInteger(String nm) {
- return getInteger(nm, (Integer)null);
- }
-
- public static Integer getInteger(String nm, int val) {
- Integer result = getInteger(nm, (Integer)null);
- return result == null ? new Integer(val) : result;
- }
-
- public static Integer getInteger(String nm, Integer val) {
- SecurityManager.setScopePermission();
- String v = System.getProperty(nm);
- if (v != null) {
- try {
- return decode(v);
- } catch (NumberFormatException var3) {
- }
- }
-
- return val;
- }
-
- private static Integer decode(String nm) throws NumberFormatException {
- if (nm.startsWith("0x")) {
- return valueOf(nm.substring(2), 16);
- } else if (nm.startsWith("#")) {
- return valueOf(nm.substring(1), 16);
- } else {
- return nm.startsWith("0") && nm.length() > 1 ? valueOf(nm.substring(1), 8) : valueOf(nm);
- }
- }
- }
-