⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 integer.java

📁 一个开源的JAVA虚拟机
💻 JAVA
字号:
/*    libaegisvm - The Aegis Virtual Machine for executing Java bytecode    Copyright (C) 2001-2002  Philip W. L. Fong    This library is free software; you can redistribute it and/or    modify it under the terms of the GNU Lesser General Public    License as published by the Free Software Foundation; either    version 2.1 of the License, or (at your option) any later version.    This library is distributed in the hope that it will be useful,    but WITHOUT ANY WARRANTY; without even the implied warranty of    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU    Lesser General Public License for more details.    You should have received a copy of the GNU Lesser General Public    License along with this library; if not, write to the Free Software    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA*//* *  java.lang.Integer * *  (c) 1997 George David Morrison * *  API version: 1.0.2 * *  History: *  01JAN1997  George David Morrison *    Initial version *  02DEC1997 Glynn Clements *    Tidied up toString(int, int) */package java.lang;public class Integer extends Number implements java.io.Serializable {    public static final int MIN_VALUE = -2147483648;    public static final int MAX_VALUE =  2147483647;    public static final Class TYPE = Class.getPrimitiveType(Class.T_INT);    private int value;    public Integer(int value) {	this.value = value;    }    public Integer(String s) throws NumberFormatException {	value = parseInt(s, 10);    }    public static String toString(int value, int radix) {	StringBuffer result;	int sign;	if (value == 0)	    return "0";	result = new StringBuffer();	sign = (value < 0 ? -1 : 1);	while (value != 0) {	    result.append(Character.forDigit(sign * (value % radix), radix));	    value /= radix;	}	if (sign < 0)	    result.append('-');	return result.reverse().toString();    }    private static String toUnsignedString(int value, int shift) {	if (value == 0)	    return "0";	StringBuffer result = new StringBuffer();	int radix = 1 << shift;	int mask = radix - 1;	while (value != 0) {	    result.append(Character.forDigit(value & mask, radix));	    value >>>= shift;	}	return result.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);    }    public static String toString(int i) {	return toString(i, 10);    }    private static int parseInt(String s, int radix, int offset)	throws NumberFormatException {	if (s == null || s.length() == 0)	    throw new NumberFormatException();	if (radix < Character.MIN_RADIX || radix > Character.MAX_RADIX)	    throw new NumberFormatException();	int result = 0;	int length = s.length();	if (s.charAt(0) == '-') {	    offset++;	    if (offset == length)		throw new NumberFormatException();	    for (; offset < length; offset++) {		if (result < MIN_VALUE / radix)		    throw new NumberFormatException();		result *= radix;		int digit = Character.digit(s.charAt(offset), radix);		if (digit < 0 ||		    result < MIN_VALUE + digit)		    throw new NumberFormatException();		result -= digit;	    }	} else {	    for (; offset < length; offset++) {		if (result > MAX_VALUE / radix)		    throw new NumberFormatException();		result *= radix;		int digit = Character.digit(s.charAt(offset), radix);		if (digit < 0 ||		    result > MAX_VALUE - digit)		    throw new NumberFormatException();		result += digit;	    }	}	return result;    }    public static int parseInt(String s, int radix)	throws NumberFormatException {	return parseInt(s, radix, 0);    }    public static int parseInt(String s)	throws NumberFormatException {	return parseInt(s, 10, 0);    }    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 valueOf(s, 10);    }    public byte byteValue() {	return (byte) value;    }    public short shortValue() {	return (short) value;    }    public int intValue() {	return value;    }    public long longValue() {	return (long) value;    }    public float floatValue() {	return (float) value;    }    public double doubleValue() {	return (double) value;    }    public String toString() {	return toString(value);    }    public int hashCode() {	return value;    }    public boolean equals(Object obj) {	return	    obj instanceof Integer &&	    value == ((Integer) obj).value;    }    public static Integer getInteger(String nm) {	return getInteger(nm, null);    }    public static Integer getInteger(String nm, int val) {	Integer result = getInteger(nm, null);	return ((result == null) ? new Integer(val) : result);    }    public static Integer getInteger(String nm, Integer val) {	String s;	if (nm == null || nm.length() == 0)	    return val;	s = System.getProperty(nm);	if (s == null)	    return val;	try {	    return decode(s);	} catch (NumberFormatException e) {	    return val;	}    }    public static Integer decode(String nm) throws NumberFormatException {	int length;	int offset;	int sign;	int radix;	int magnitude;	if (nm == null || (length = nm.length()) == 0)	    throw new NumberFormatException();	if (nm.charAt(0) == '-') {	    sign = -1;	    offset = 1;	} else {	    sign = 1;	    offset = 0;	}	if (nm.startsWith("0x", offset)) {	    radix = 16;	    offset += 2;	} else if (nm.charAt(offset) == '#') {	    radix = 16;	    offset += 1;	} else if (nm.charAt(offset) == '0' && length > offset + 1) {	    radix = 8;	    offset += 1;	} else {	    radix = 10;	}	magnitude = parseInt(nm, radix, offset);	if (magnitude < 0)	    throw new NumberFormatException();	return new Integer(sign * magnitude);    }    public int compareTo(Integer anotherInteger) {	return value - anotherInteger.value;    }    public int compareTo(Object o) {	return compareTo((Integer) o);    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -