| Method from java.lang.Long Detail: |
public static int bitCount(long lng) {
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;
}
Counts the number of 1 bits in the specified long value; this is also
referred to as population count. |
public byte byteValue() {
return (byte) value;
}
|
public int compareTo(Long object) {
return value > object.value ? 1 : (value < object.value ? -1 : 0);
}
Compares this object to the specified long object to determine their
relative order. |
public static Long decode(String string) throws NumberFormatException {
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);
}
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. |
public double doubleValue() {
return value;
}
|
public boolean equals(Object o) {
return (o instanceof Long)
&& (value == ((Long) o).value);
}
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. |
public float floatValue() {
return value;
}
|
public static Long getLong(String string) {
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;
}
}
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. |
public static Long getLong(String string,
long defaultValue) {
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);
}
}
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. |
public static Long getLong(String string,
Long defaultValue) {
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;
}
}
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. |
public int hashCode() {
return (int) (value ^ (value > > > 32));
}
|
public static long highestOneBit(long lng) {
lng |= (lng > > 1);
lng |= (lng > > 2);
lng |= (lng > > 4);
lng |= (lng > > 8);
lng |= (lng > > 16);
lng |= (lng > > 32);
return (lng & ~(lng > > > 1));
}
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. |
public int intValue() {
return (int) value;
}
|
public long longValue() {
return value;
}
Gets the primitive value of this long. |
public static long lowestOneBit(long lng) {
return (lng & (-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. |
public static int numberOfLeadingZeros(long lng) {
lng |= lng > > 1;
lng |= lng > > 2;
lng |= lng > > 4;
lng |= lng > > 8;
lng |= lng > > 16;
lng |= lng > > 32;
return bitCount(~lng);
}
Determines the number of leading zeros in the specified long value prior
to the highest one bit . |
public static int numberOfTrailingZeros(long lng) {
return bitCount((lng & -lng) - 1);
}
Determines the number of trailing zeros in the specified long value after
the lowest one bit . |
public static long parseLong(String string) throws NumberFormatException {
return parseLong(string, 10);
}
Parses the specified string as a signed decimal long value. The ASCII
character \u002d ('-') is recognized as the minus sign. |
public static long parseLong(String string,
int radix) throws NumberFormatException {
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);
}
Parses the specified string as a signed long value using the specified
radix. The ASCII character \u002d ('-') is recognized as the minus sign. |
public static long reverse(long lng) {
// 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);
}
Reverses the order of the bits of the specified long value. |
public static long reverseBytes(long lng) {
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);
}
Reverses the order of the bytes of the specified long value. |
public static long rotateLeft(long lng,
int distance) {
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)));
}
Rotates the bits of the specified long value to the left by the specified
number of bits. |
public static long rotateRight(long lng,
int distance) {
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) {
return (lng == 0 ? 0 : (lng < 0 ? -1 : 1));
}
Returns the value of the {@code signum} function for the specified long
value. |
public static String toBinaryString(long l) {
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);
}
Converts the specified long value into its binary string representation.
The returned string is a concatenation of '0' and '1' characters. |
public static String toHexString(long l) {
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);
}
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'. |
public static String toOctalString(long l) {
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);
}
Converts the specified long value into its octal string representation.
The returned string is a concatenation of characters from '0' to '7'. |
public String toString() {
return Long.toString(value);
}
|
public static String toString(long l) {
return toString(l, 10);
}
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'. |
public static String toString(long l,
int radix) {
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);
}
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. |
public static Long valueOf(String string) throws NumberFormatException {
return valueOf(parseLong(string));
}
Parses the specified string as a signed decimal long value. |
public static Long valueOf(long lng) {
if (lng < -128 || lng > 127) {
return new Long(lng);
}
return valueOfCache.CACHE[128+(int)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. |
public static Long valueOf(String string,
int radix) throws NumberFormatException {
return valueOf(parseLong(string, radix));
}
Parses the specified string as a signed long value using the specified
radix. |