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

📄 long.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.Long * *  (c) 1997 George David Morrison * *  API version: 1.0.2 * *  History: *  01JAN1997  Peter Nagy *    Initial version - copied from Integer *  02DEC1997 Glynn Clements *    Tidied up toString(long, int) */package java.lang;public final class Long extends Number implements Comparable {    public static final long MIN_VALUE = 0x8000000000000000L;    public static final long MAX_VALUE = 0x7FFFFFFFFFFFFFFFL;    public static final Class TYPE = Class.getPrimitiveType(Class.T_LONG);    private long value;    public Long(long value) {	this.value = value;    }    public Long(String s) throws NumberFormatException {	this.value = parseLong(s, 10);    }    public static String toString(long 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 * (int) (value % radix),					     radix));	    value /= radix;	}	if (sign < 0)	    result.append('-');	return result.reverse().toString();    }    private static String toUnsignedString(long 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((int) (value & mask), radix));	    value >>>= shift;	}	return result.reverse().toString();    }    public static String toHexString(long i) {	return toUnsignedString(i, 4);    }    public static String toOctalString(long i) {	return toUnsignedString(i, 3);    }    public static String toBinaryString(long i) {	return toUnsignedString(i, 1);    }    public static String toString(long value) {	return toString(value, 10);    }    private static long parseLong(String s, int radix, int offset)	throws NumberFormatException {	if (s == null || offset >= s.length())	    throw new NumberFormatException();	if (radix < Character.MIN_RADIX || radix > Character.MAX_RADIX)	    throw new NumberFormatException();	long result = 0;	int length = s.length();	if (s.charAt(offset) == '-') {	    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)		    throw new NumberFormatException();		if (result > MAX_VALUE - digit)		    throw new NumberFormatException();		result += digit;	    }	}	return result;    }    public static long parseLong(String s, int radix)	throws NumberFormatException {	return parseLong(s, radix, 0);    }    public static long parseLong(String s)	throws NumberFormatException {	return parseLong(s, 10);    }    public static Long valueOf(String s, int radix)	throws NumberFormatException {	return new Long(parseLong(s, radix));    }    public static Long valueOf(String s) throws NumberFormatException {	return valueOf(s, 10);    }    public static Long decode(String nm) throws NumberFormatException {	int length;	int offset;	int sign;	int radix;	long 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 = parseLong(nm, radix, offset);	if (magnitude < 0)	    throw new NumberFormatException();	return new Long(sign * magnitude);    }    public byte byteValue() {	return (byte) value;    }    public short shortValue() {	return (short) value;    }    public int intValue() {	return (int) value;    }    public long longValue() {	return value;    }    public float floatValue() {	return (float) value;    }    public double doubleValue() {	return (double) value;    }    public String toString() {	return toString(value, 10);    }    public int hashCode() {	return (int) (value ^ (value >>> 32));    }    public boolean equals(Object obj) {	return	    obj instanceof Long &&	    value == ((Long) obj).value;    }    public static Long getLong(String nm) {	return getLong(nm, null);    }    public static Long getLong(String nm, long val) {	Long result = getLong(nm, null);	return (result == null) ? new Long(val) : result;    }    public static Long getLong(String nm, Long 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 int compareTo(Long anotherLong) {	if (value == anotherLong.value)	    return 0;	else if (value < anotherLong.value)	    return -1;	else	    return 1;    }    public int compareTo(Object o) {	return compareTo((Long) o);    }}

⌨️ 快捷键说明

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