| Method from java.lang.Integer Detail: |
public static int bitCount(int i) {
i -= ((i > > 1) & 0x55555555);
i = (i & 0x33333333) + ((i > > 2) & 0x33333333);
i = (((i > > 4) + i) & 0x0F0F0F0F);
i += (i > > 8);
i += (i > > 16);
return (i & 0x0000003F);
}
Counts the number of 1 bits in the specified integer; this is also
referred to as population count. |
public byte byteValue() {
return (byte) value;
}
|
public int compareTo(Integer object) {
return value > object.value ? 1 : (value < object.value ? -1 : 0);
}
Compares this object to the specified integer object to determine their
relative order. |
public static Integer 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(0);
}
if ((firstDigit = string.charAt(i)) == 'x' || firstDigit == 'X') {
if (++i == length) {
throw new NumberFormatException(string);
}
base = 16;
} else {
base = 8;
}
} else if (firstDigit == '#') {
if (++i == length) {
throw new NumberFormatException(string);
}
base = 16;
}
int result = parse(string, i, base, negative);
return valueOf(result);
}
Parses the specified string and returns a {@code Integer} instance if the
string can be decoded into an integer value. The string may be an
optional minus sign "-" followed by a hexadecimal ("0x..." or "#..."),
octal ("0..."), or decimal ("...") representation of an integer. |
public double doubleValue() {
return value;
}
|
public boolean equals(Object o) {
return (o instanceof Integer)
&& (value == ((Integer) 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 Integer} and have the same integer value as this object. |
public float floatValue() {
return value;
}
|
public static Integer getInteger(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 Integer} 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 an integer. |
public static Integer getInteger(String string,
int 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 Integer} 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 an integer. |
public static Integer getInteger(String string,
Integer 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 Integer} 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 an integer. |
public int hashCode() {
return value;
}
|
public static int highestOneBit(int i) {
i |= (i > > 1);
i |= (i > > 2);
i |= (i > > 4);
i |= (i > > 8);
i |= (i > > 16);
return (i & ~(i > > > 1));
}
Determines the highest (leftmost) bit of the specified integer 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 integer is
zero. |
public int intValue() {
return value;
}
Gets the primitive value of this int. |
public long longValue() {
return value;
}
|
public static int lowestOneBit(int i) {
return (i & (-i));
}
Determines the lowest (rightmost) bit of the specified integer 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 integer
is zero. |
public static int numberOfLeadingZeros(int i) {
i |= i > > 1;
i |= i > > 2;
i |= i > > 4;
i |= i > > 8;
i |= i > > 16;
return bitCount(~i);
}
Determines the number of leading zeros in the specified integer prior to
the highest one bit . |
public static int numberOfTrailingZeros(int i) {
return bitCount((i & -i) - 1);
}
Determines the number of trailing zeros in the specified integer after
the lowest one bit . |
public static int parseInt(String string) throws NumberFormatException {
return parseInt(string, 10);
}
Parses the specified string as a signed decimal integer value. The ASCII
character \u002d ('-') is recognized as the minus sign. |
public static int parseInt(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 integer value using the specified
radix. The ASCII character \u002d ('-') is recognized as the minus sign. |
public static int reverse(int i) {
// From Hacker's Delight, 7-1, Figure 7-1
i = (i & 0x55555555) < < 1 | (i > > 1) & 0x55555555;
i = (i & 0x33333333) < < 2 | (i > > 2) & 0x33333333;
i = (i & 0x0F0F0F0F) < < 4 | (i > > 4) & 0x0F0F0F0F;
return reverseBytes(i);
}
Reverses the order of the bits of the specified integer. |
public static int reverseBytes(int i) {
int b3 = i > > > 24;
int b2 = (i > > > 8) & 0xFF00;
int b1 = (i & 0xFF00) < < 8;
int b0 = i < < 24;
return (b0 | b1 | b2 | b3);
}
Reverses the order of the bytes of the specified integer. |
public static int rotateLeft(int i,
int distance) {
if (distance == 0) {
return i;
}
/*
* According to JLS3, 15.19, the right operand of a shift is always
* implicitly masked with 0x1F, which the negation of 'distance' is
* taking advantage of.
*/
return ((i < < distance) | (i > > > (-distance)));
}
Rotates the bits of the specified integer to the left by the specified
number of bits. |
public static int rotateRight(int i,
int distance) {
if (distance == 0) {
return i;
}
/*
* According to JLS3, 15.19, the right operand of a shift is always
* implicitly masked with 0x1F, which the negation of 'distance' is
* taking advantage of.
*/
return ((i > > > distance) | (i < < (-distance)));
}
Rotates the bits of the specified integer to the right by the specified
number of bits. |
public short shortValue() {
return (short) value;
}
|
public static int signum(int i) {
return (i == 0 ? 0 : (i < 0 ? -1 : 1));
}
Returns the value of the {@code signum} function for the specified
integer. |
public static String toBinaryString(int i) {
int count = 1, j = i;
if (i < 0) {
count = 32;
} else {
while ((j > > >= 1) != 0) {
count++;
}
}
char[] buffer = new char[count];
do {
buffer[--count] = (char) ((i & 1) + '0');
i > > >= 1;
} while (count > 0);
return new String(0, buffer.length, buffer);
}
Converts the specified integer into its binary string representation. The
returned string is a concatenation of '0' and '1' characters. |
public static String toHexString(int i) {
int count = 1, j = i;
if (i < 0) {
count = 8;
} else {
while ((j > > >= 4) != 0) {
count++;
}
}
char[] buffer = new char[count];
do {
int t = i & 15;
if (t > 9) {
t = t - 10 + 'a';
} else {
t += '0';
}
buffer[--count] = (char) t;
i > > >= 4;
} while (count > 0);
return new String(0, buffer.length, buffer);
}
Converts the specified integer 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(int i) {
int count = 1, j = i;
if (i < 0) {
count = 11;
} else {
while ((j > > >= 3) != 0) {
count++;
}
}
char[] buffer = new char[count];
do {
buffer[--count] = (char) ((i & 7) + '0');
i > > >= 3;
} while (count > 0);
return new String(0, buffer.length, buffer);
}
Converts the specified integer into its octal string representation. The
returned string is a concatenation of characters from '0' to '7'. |
public String toString() {
return Integer.toString(value);
}
|
public static String toString(int value) {
if (value == 0) {
return "0"; //$NON-NLS-1$
}
// Faster algorithm for smaller Integers
if (value < 1000 && value > -1000) {
char[] buffer = new char[4];
int positive_value = value < 0 ? -value : value;
int first_digit = 0;
if (value < 0) {
buffer[0] = '-';
first_digit++;
}
int last_digit = first_digit;
int quot = positive_value;
do {
int res = quot / 10;
int digit_value = quot - ((res < < 3) + (res < < 1));
digit_value += '0';
buffer[last_digit++] = (char) digit_value;
quot = res;
} while (quot != 0);
int count = last_digit--;
do {
char tmp = buffer[last_digit];
buffer[last_digit--] = buffer[first_digit];
buffer[first_digit++] = tmp;
} while (first_digit < last_digit);
return new String(0, count, buffer);
}
if (value == MIN_VALUE) {
return "-2147483648";//$NON-NLS-1$
}
char[] buffer = new char[11];
int positive_value = value < 0 ? -value : value;
byte first_digit = 0;
if (value < 0) {
buffer[0] = '-';
first_digit++;
}
byte last_digit = first_digit;
byte count;
int number;
boolean start = false;
for (int i = 0; i < 9; i++) {
count = 0;
if (positive_value < (number = decimalScale[i])) {
if (start) {
buffer[last_digit++] = '0';
}
continue;
}
if (i > 0) {
number = (decimalScale[i] < < 3);
if (positive_value >= number) {
positive_value -= number;
count += 8;
}
number = (decimalScale[i] < < 2);
if (positive_value >= number) {
positive_value -= number;
count += 4;
}
}
number = (decimalScale[i] < < 1);
if (positive_value >= number) {
positive_value -= number;
count += 2;
}
if (positive_value >= decimalScale[i]) {
positive_value -= decimalScale[i];
count++;
}
if (count > 0 && !start) {
start = true;
}
if (start) {
buffer[last_digit++] = (char) (count + '0');
}
}
buffer[last_digit++] = (char) (positive_value + '0');
count = last_digit--;
return new String(0, count, buffer);
}
Converts the specified integer 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(int i,
int radix) {
if (radix < Character.MIN_RADIX || radix > Character.MAX_RADIX) {
radix = 10;
}
if (i == 0) {
return "0"; //$NON-NLS-1$
}
int count = 2, j = i;
boolean negative = i < 0;
if (!negative) {
count = 1;
j = -i;
}
while ((i /= radix) != 0) {
count++;
}
char[] buffer = new char[count];
do {
int ch = 0 - (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 integer 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 Integer valueOf(String string) throws NumberFormatException {
return valueOf(parseInt(string));
}
Parses the specified string as a signed decimal integer value. |
public static Integer valueOf(int i) {
if (i < -128 || i > 127) {
return new Integer(i);
}
return valueOfCache.CACHE [i+128];
}
Returns a {@code Integer} instance for the specified integer value.
If it is not necessary to get a new {@code Integer} 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 Integer valueOf(String string,
int radix) throws NumberFormatException {
return valueOf(parseInt(string, radix));
}
Parses the specified string as a signed integer value using the specified
radix. |