Methods Summary |
---|
public static int | bitCount(long lng)Counts the number of 1 bits in the specified long value; this is also
referred to as population count.
lng = (lng & 0x5555555555555555L) + ((lng >> 1) & 0x5555555555555555L);
lng = (lng & 0x3333333333333333L) + ((lng >> 2) & 0x3333333333333333L);
// adjust for 64-bit integer
int i = (int) ((lng >>> 32) + lng);
i = (i & 0x0F0F0F0F) + ((i >> 4) & 0x0F0F0F0F);
i = (i & 0x00FF00FF) + ((i >> 8) & 0x00FF00FF);
i = (i & 0x0000FFFF) + ((i >> 16) & 0x0000FFFF);
return i;
|
public byte | byteValue()
return (byte) value;
|
public int | compareTo(java.lang.Long object)Compares this object to the specified long object to determine their
relative order.
return value > object.value ? 1 : (value < object.value ? -1 : 0);
|
public static java.lang.Long | decode(java.lang.String string)Parses the specified string and returns a {@code Long} instance if the
string can be decoded into a long value. The string may be an optional
minus sign "-" followed by a hexadecimal ("0x..." or "#..."), octal
("0..."), or decimal ("...") representation of a long.
int length = string.length(), i = 0;
if (length == 0) {
throw new NumberFormatException();
}
char firstDigit = string.charAt(i);
boolean negative = firstDigit == '-";
if (negative) {
if (length == 1) {
throw new NumberFormatException(string);
}
firstDigit = string.charAt(++i);
}
int base = 10;
if (firstDigit == '0") {
if (++i == length) {
return valueOf(0L);
}
if ((firstDigit = string.charAt(i)) == 'x" || firstDigit == 'X") {
if (i == length) {
throw new NumberFormatException(string);
}
i++;
base = 16;
} else {
base = 8;
}
} else if (firstDigit == '#") {
if (i == length) {
throw new NumberFormatException(string);
}
i++;
base = 16;
}
long result = parse(string, i, base, negative);
return valueOf(result);
|
public double | doubleValue()
return value;
|
public boolean | equals(java.lang.Object o)Compares this instance with the specified object and indicates if they
are equal. In order to be equal, {@code o} must be an instance of
{@code Long} and have the same long value as this object.
return (o instanceof Long)
&& (value == ((Long) o).value);
|
public float | floatValue()
return value;
|
public static java.lang.Long | getLong(java.lang.String string, long defaultValue)Returns the {@code Long} value of the system property identified by
{@code string}. Returns the specified default value if {@code string} is
{@code null} or empty, if the property can not be found or if its value
can not be parsed as a long.
if (string == null || string.length() == 0) {
return valueOf(defaultValue);
}
String prop = System.getProperty(string);
if (prop == null) {
return valueOf(defaultValue);
}
try {
return decode(prop);
} catch (NumberFormatException ex) {
return valueOf(defaultValue);
}
|
public static java.lang.Long | getLong(java.lang.String string, java.lang.Long defaultValue)Returns the {@code Long} value of the system property identified by
{@code string}. Returns the specified default value if {@code string} is
{@code null} or empty, if the property can not be found or if its value
can not be parsed as a long.
if (string == null || string.length() == 0) {
return defaultValue;
}
String prop = System.getProperty(string);
if (prop == null) {
return defaultValue;
}
try {
return decode(prop);
} catch (NumberFormatException ex) {
return defaultValue;
}
|
public static java.lang.Long | getLong(java.lang.String string)Returns the {@code Long} value of the system property identified by
{@code string}. Returns {@code null} if {@code string} is {@code null}
or empty, if the property can not be found or if its value can not be
parsed as a long.
if (string == null || string.length() == 0) {
return null;
}
String prop = System.getProperty(string);
if (prop == null) {
return null;
}
try {
return decode(prop);
} catch (NumberFormatException ex) {
return null;
}
|
public int | hashCode()
return (int) (value ^ (value >>> 32));
|
public static long | highestOneBit(long lng)Determines the highest (leftmost) bit of the specified long value that is
1 and returns the bit mask value for that bit. This is also referred to
as the Most Significant 1 Bit. Returns zero if the specified long is
zero.
lng |= (lng >> 1);
lng |= (lng >> 2);
lng |= (lng >> 4);
lng |= (lng >> 8);
lng |= (lng >> 16);
lng |= (lng >> 32);
return (lng & ~(lng >>> 1));
|
public int | intValue()
return (int) value;
|
public long | longValue()Gets the primitive value of this long.
return value;
|
public static long | lowestOneBit(long lng)Determines the lowest (rightmost) bit of the specified long value that is
1 and returns the bit mask value for that bit. This is also referred to
as the Least Significant 1 Bit. Returns zero if the specified long is
zero.
return (lng & (-lng));
|
public static int | numberOfLeadingZeros(long lng)Determines the number of leading zeros in the specified long value prior
to the {@link #highestOneBit(long) highest one bit}.
lng |= lng >> 1;
lng |= lng >> 2;
lng |= lng >> 4;
lng |= lng >> 8;
lng |= lng >> 16;
lng |= lng >> 32;
return bitCount(~lng);
|
public static int | numberOfTrailingZeros(long lng)Determines the number of trailing zeros in the specified long value after
the {@link #lowestOneBit(long) lowest one bit}.
return bitCount((lng & -lng) - 1);
|
private static long | parse(java.lang.String string, int offset, int radix, boolean negative)
long max = Long.MIN_VALUE / radix;
long result = 0, length = string.length();
while (offset < length) {
int digit = Character.digit(string.charAt(offset++), radix);
if (digit == -1) {
throw new NumberFormatException(string);
}
if (max > result) {
throw new NumberFormatException(string);
}
long next = result * radix - digit;
if (next > result) {
throw new NumberFormatException(string);
}
result = next;
}
if (!negative) {
result = -result;
if (result < 0) {
throw new NumberFormatException(string);
}
}
return result;
|
public static long | parseLong(java.lang.String string)Parses the specified string as a signed decimal long value. The ASCII
character \u002d ('-') is recognized as the minus sign.
return parseLong(string, 10);
|
public static long | parseLong(java.lang.String string, int radix)Parses the specified string as a signed long value using the specified
radix. The ASCII character \u002d ('-') is recognized as the minus sign.
if (string == null || radix < Character.MIN_RADIX
|| radix > Character.MAX_RADIX) {
throw new NumberFormatException();
}
int length = string.length(), i = 0;
if (length == 0) {
throw new NumberFormatException(string);
}
boolean negative = string.charAt(i) == '-";
if (negative && ++i == length) {
throw new NumberFormatException(string);
}
return parse(string, i, radix, negative);
|
public static long | reverse(long lng)Reverses the order of the bits of the specified long value.
// From Hacker's Delight, 7-1, Figure 7-1
lng = (lng & 0x5555555555555555L) << 1 | (lng >> 1)
& 0x5555555555555555L;
lng = (lng & 0x3333333333333333L) << 2 | (lng >> 2)
& 0x3333333333333333L;
lng = (lng & 0x0F0F0F0F0F0F0F0FL) << 4 | (lng >> 4)
& 0x0F0F0F0F0F0F0F0FL;
return reverseBytes(lng);
|
public static long | reverseBytes(long lng)Reverses the order of the bytes of the specified long value.
long b7 = lng >>> 56;
long b6 = (lng >>> 40) & 0xFF00L;
long b5 = (lng >>> 24) & 0xFF0000L;
long b4 = (lng >>> 8) & 0xFF000000L;
long b3 = (lng & 0xFF000000L) << 8;
long b2 = (lng & 0xFF0000L) << 24;
long b1 = (lng & 0xFF00L) << 40;
long b0 = lng << 56;
return (b0 | b1 | b2 | b3 | b4 | b5 | b6 | b7);
|
public static long | rotateLeft(long lng, int distance)Rotates the bits of the specified long value to the left by the specified
number of bits.
if (distance == 0) {
return lng;
}
/*
* According to JLS3, 15.19, the right operand of a shift is always
* implicitly masked with 0x3F, which the negation of 'distance' is
* taking advantage of.
*/
return ((lng << distance) | (lng >>> (-distance)));
|
public static long | rotateRight(long lng, int distance)Rotates the bits of the specified long value to the right by the
specified number of bits.
if (distance == 0) {
return lng;
}
/*
* According to JLS3, 15.19, the right operand of a shift is always
* implicitly masked with 0x3F, which the negation of 'distance' is
* taking advantage of.
*/
return ((lng >>> distance) | (lng << (-distance)));
|
public short | shortValue()
return (short) value;
|
public static int | signum(long lng)Returns the value of the {@code signum} function for the specified long
value.
return (lng == 0 ? 0 : (lng < 0 ? -1 : 1));
|
public static java.lang.String | toBinaryString(long l)Converts the specified long value into its binary string representation.
The returned string is a concatenation of '0' and '1' characters.
int count = 1;
long j = l;
if (l < 0) {
count = 64;
} else {
while ((j >>= 1) != 0) {
count++;
}
}
char[] buffer = new char[count];
do {
buffer[--count] = (char) ((l & 1) + '0");
l >>= 1;
} while (count > 0);
return new String(0, buffer.length, buffer);
|
public static java.lang.String | toHexString(long l)Converts the specified long value into its hexadecimal string
representation. The returned string is a concatenation of characters from
'0' to '9' and 'a' to 'f'.
int count = 1;
long j = l;
if (l < 0) {
count = 16;
} else {
while ((j >>= 4) != 0) {
count++;
}
}
char[] buffer = new char[count];
do {
int t = (int) (l & 15);
if (t > 9) {
t = t - 10 + 'a";
} else {
t += '0";
}
buffer[--count] = (char) t;
l >>= 4;
} while (count > 0);
return new String(0, buffer.length, buffer);
|
public static java.lang.String | toOctalString(long l)Converts the specified long value into its octal string representation.
The returned string is a concatenation of characters from '0' to '7'.
int count = 1;
long j = l;
if (l < 0) {
count = 22;
} else {
while ((j >>>= 3) != 0) {
count++;
}
}
char[] buffer = new char[count];
do {
buffer[--count] = (char) ((l & 7) + '0");
l >>>= 3;
} while (count > 0);
return new String(0, buffer.length, buffer);
|
public java.lang.String | toString()
return Long.toString(value);
|
public static java.lang.String | toString(long l)Converts the specified long value into its decimal string representation.
The returned string is a concatenation of a minus sign if the number is
negative and characters from '0' to '9'.
return toString(l, 10);
|
public static java.lang.String | toString(long l, int radix)Converts the specified long value into a string representation based on
the specified radix. The returned string is a concatenation of a minus
sign if the number is negative and characters from '0' to '9' and 'a' to
'z', depending on the radix. If {@code radix} is not in the interval
defined by {@code Character.MIN_RADIX} and {@code Character.MAX_RADIX}
then 10 is used as the base for the conversion.
if (radix < Character.MIN_RADIX || radix > Character.MAX_RADIX) {
radix = 10;
}
if (l == 0) {
return "0"; //$NON-NLS-1$
}
int count = 2;
long j = l;
boolean negative = l < 0;
if (!negative) {
count = 1;
j = -l;
}
while ((l /= radix) != 0) {
count++;
}
char[] buffer = new char[count];
do {
int ch = 0 - (int) (j % radix);
if (ch > 9) {
ch = ch - 10 + 'a";
} else {
ch += '0";
}
buffer[--count] = (char) ch;
} while ((j /= radix) != 0);
if (negative) {
buffer[0] = '-";
}
return new String(0, buffer.length, buffer);
|
public static java.lang.Long | valueOf(java.lang.String string)Parses the specified string as a signed decimal long value.
return valueOf(parseLong(string));
|
public static java.lang.Long | valueOf(java.lang.String string, int radix)Parses the specified string as a signed long value using the specified
radix.
return valueOf(parseLong(string, radix));
|
public static java.lang.Long | valueOf(long lng)Returns a {@code Long} instance for the specified long value.
If it is not necessary to get a new {@code Long} instance, it is
recommended to use this method instead of the constructor, since it
maintains a cache of instances which may result in better performance.
if (lng < -128 || lng > 127) {
return new Long(lng);
}
return valueOfCache.CACHE[128+(int)lng];
|