Integer.java revision 1390
0N/A * Copyright 1994-2006 Sun Microsystems, Inc. All Rights Reserved. 0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 0N/A * This code is free software; you can redistribute it and/or modify it 0N/A * under the terms of the GNU General Public License version 2 only, as 0N/A * published by the Free Software Foundation. Sun designates this 0N/A * particular file as subject to the "Classpath" exception as provided 0N/A * by Sun in the LICENSE file that accompanied this code. 0N/A * This code is distributed in the hope that it will be useful, but WITHOUT 0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 0N/A * version 2 for more details (a copy is included in the LICENSE file that 0N/A * accompanied this code). 0N/A * You should have received a copy of the GNU General Public License version 0N/A * 2 along with this work; if not, write to the Free Software Foundation, 0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 0N/A * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 0N/A * CA 95054 USA or visit www.sun.com if you need additional information or 0N/A * have any questions. 0N/A * The {@code Integer} class wraps a value of the primitive type 0N/A * {@code int} in an object. An object of type {@code Integer} 0N/A * contains a single field whose type is {@code int}. 0N/A * <p>In addition, this class provides several methods for converting 0N/A * an {@code int} to a {@code String} and a {@code String} to an 0N/A * {@code int}, as well as other constants and methods useful when 0N/A * dealing with an {@code int}. 0N/A * <p>Implementation note: The implementations of the "bit twiddling" 0N/A * methods (such as {@link #highestOneBit(int) highestOneBit} and 0N/A * {@link #numberOfTrailingZeros(int) numberOfTrailingZeros}) are 0N/A * based on material from Henry S. Warren, Jr.'s <i>Hacker's 0N/A * Delight</i>, (Addison Wesley, 2002). 0N/A * @author Lee Boynton 0N/A * @author Arthur van Hoff 0N/A * @author Josh Bloch 0N/A * @author Joseph D. Darcy 0N/A * A constant holding the minimum value an {@code int} can 0N/A * have, -2<sup>31</sup>. 0N/A * A constant holding the maximum value an {@code int} can 0N/A * have, 2<sup>31</sup>-1. 0N/A * The {@code Class} instance representing the primitive type 0N/A * All possible chars for representing a number as a String 0N/A '0' ,
'1' ,
'2' ,
'3' ,
'4' ,
'5' ,
0N/A '6' ,
'7' ,
'8' ,
'9' ,
'a' ,
'b' ,
0N/A 'c' ,
'd' ,
'e' ,
'f' ,
'g' ,
'h' ,
0N/A 'i' ,
'j' ,
'k' ,
'l' ,
'm' ,
'n' ,
0N/A 'o' ,
'p' ,
'q' ,
'r' ,
's' ,
't' ,
0N/A 'u' ,
'v' ,
'w' ,
'x' ,
'y' ,
'z' 0N/A * Returns a string representation of the first argument in the 0N/A * radix specified by the second argument. 0N/A * <p>If the radix is smaller than {@code Character.MIN_RADIX} 0N/A * or larger than {@code Character.MAX_RADIX}, then the radix 0N/A * {@code 10} is used instead. 0N/A * <p>If the first argument is negative, the first element of the 0N/A * result is the ASCII minus character {@code '-'} 0N/A * (<code>'\u002D'</code>). If the first argument is not 0N/A * negative, no sign character appears in the result. 0N/A * <p>The remaining characters of the result represent the magnitude 0N/A * of the first argument. If the magnitude is zero, it is 0N/A * represented by a single zero character {@code '0'} 0N/A * (<code>'\u0030'</code>); otherwise, the first character of 0N/A * the representation of the magnitude will not be the zero 0N/A * character. The following ASCII characters are used as digits: 0N/A * {@code 0123456789abcdefghijklmnopqrstuvwxyz} 0N/A * These are <code>'\u0030'</code> through 0N/A * <code>'\u0039'</code> and <code>'\u0061'</code> through 0N/A * <code>'\u007A'</code>. If {@code radix} is 0N/A * <var>N</var>, then the first <var>N</var> of these characters 0N/A * are used as radix-<var>N</var> digits in the order shown. Thus, 0N/A * the digits for hexadecimal (radix 16) are 0N/A * {@code 0123456789abcdef}. If uppercase letters are 0N/A * desired, the {@link java.lang.String#toUpperCase()} method may 0N/A * be called on the result: 0N/A * {@code Integer.toString(n, 16).toUpperCase()} 0N/A * @param i an integer to be converted to a string. 0N/A * @param radix the radix to use in the string representation. 0N/A * @return a string representation of the argument in the specified radix. 0N/A * @see java.lang.Character#MAX_RADIX 0N/A * @see java.lang.Character#MIN_RADIX 0N/A /* Use the faster version */ 0N/A * Returns a string representation of the integer argument as an 0N/A * unsigned integer in base 16. 0N/A * <p>The unsigned integer value is the argument plus 2<sup>32</sup> 0N/A * if the argument is negative; otherwise, it is equal to the 0N/A * argument. This value is converted to a string of ASCII digits 0N/A * in hexadecimal (base 16) with no extra leading 0N/A * {@code 0}s. If the unsigned magnitude is zero, it is 0N/A * represented by a single zero character {@code '0'} 0N/A * (<code>'\u0030'</code>); otherwise, the first character of 0N/A * the representation of the unsigned magnitude will not be the 0N/A * zero character. The following characters are used as 0N/A * hexadecimal digits: 0N/A * {@code 0123456789abcdef} 0N/A * These are the characters <code>'\u0030'</code> through 0N/A * <code>'\u0039'</code> and <code>'\u0061'</code> through 0N/A * <code>'\u0066'</code>. If uppercase letters are 0N/A * desired, the {@link java.lang.String#toUpperCase()} method may 0N/A * be called on the result: 0N/A * {@code Integer.toHexString(n).toUpperCase()} 0N/A * @param i an integer to be converted to a string. 0N/A * @return the string representation of the unsigned integer value 0N/A * represented by the argument in hexadecimal (base 16). 0N/A * Returns a string representation of the integer argument as an 0N/A * unsigned integer in base 8. 0N/A * <p>The unsigned integer value is the argument plus 2<sup>32</sup> 0N/A * if the argument is negative; otherwise, it is equal to the 0N/A * argument. This value is converted to a string of ASCII digits 0N/A * in octal (base 8) with no extra leading {@code 0}s. 0N/A * <p>If the unsigned magnitude is zero, it is represented by a 0N/A * single zero character {@code '0'} 0N/A * (<code>'\u0030'</code>); otherwise, the first character of 0N/A * the representation of the unsigned magnitude will not be the 0N/A * zero character. The following characters are used as octal 0N/A * These are the characters <code>'\u0030'</code> through 0N/A * <code>'\u0037'</code>. 0N/A * @param i an integer to be converted to a string. 0N/A * @return the string representation of the unsigned integer value 0N/A * represented by the argument in octal (base 8). 0N/A * Returns a string representation of the integer argument as an 0N/A * unsigned integer in base 2. 0N/A * <p>The unsigned integer value is the argument plus 2<sup>32</sup> 0N/A * if the argument is negative; otherwise it is equal to the 0N/A * argument. This value is converted to a string of ASCII digits 0N/A * in binary (base 2) with no extra leading {@code 0}s. 0N/A * If the unsigned magnitude is zero, it is represented by a 0N/A * single zero character {@code '0'} 0N/A * (<code>'\u0030'</code>); otherwise, the first character of 0N/A * the representation of the unsigned magnitude will not be the 0N/A * zero character. The characters {@code '0'} 0N/A * (<code>'\u0030'</code>) and {@code '1'} 0N/A * (<code>'\u0031'</code>) are used as binary digits. 0N/A * @param i an integer to be converted to a string. 0N/A * @return the string representation of the unsigned integer value 0N/A * represented by the argument in binary (base 2). 0N/A * Convert the integer to an unsigned number. 0N/A '0',
'0',
'0',
'0',
'0',
'0',
'0',
'0',
'0',
'0',
0N/A '1',
'1',
'1',
'1',
'1',
'1',
'1',
'1',
'1',
'1',
0N/A '2',
'2',
'2',
'2',
'2',
'2',
'2',
'2',
'2',
'2',
0N/A '3',
'3',
'3',
'3',
'3',
'3',
'3',
'3',
'3',
'3',
0N/A '4',
'4',
'4',
'4',
'4',
'4',
'4',
'4',
'4',
'4',
0N/A '5',
'5',
'5',
'5',
'5',
'5',
'5',
'5',
'5',
'5',
0N/A '6',
'6',
'6',
'6',
'6',
'6',
'6',
'6',
'6',
'6',
0N/A '7',
'7',
'7',
'7',
'7',
'7',
'7',
'7',
'7',
'7',
0N/A '8',
'8',
'8',
'8',
'8',
'8',
'8',
'8',
'8',
'8',
0N/A '9',
'9',
'9',
'9',
'9',
'9',
'9',
'9',
'9',
'9',
0N/A '0',
'1',
'2',
'3',
'4',
'5',
'6',
'7',
'8',
'9',
0N/A '0',
'1',
'2',
'3',
'4',
'5',
'6',
'7',
'8',
'9',
0N/A '0',
'1',
'2',
'3',
'4',
'5',
'6',
'7',
'8',
'9',
0N/A '0',
'1',
'2',
'3',
'4',
'5',
'6',
'7',
'8',
'9',
0N/A '0',
'1',
'2',
'3',
'4',
'5',
'6',
'7',
'8',
'9',
0N/A '0',
'1',
'2',
'3',
'4',
'5',
'6',
'7',
'8',
'9',
0N/A '0',
'1',
'2',
'3',
'4',
'5',
'6',
'7',
'8',
'9',
0N/A '0',
'1',
'2',
'3',
'4',
'5',
'6',
'7',
'8',
'9',
0N/A '0',
'1',
'2',
'3',
'4',
'5',
'6',
'7',
'8',
'9',
0N/A '0',
'1',
'2',
'3',
'4',
'5',
'6',
'7',
'8',
'9',
0N/A // I use the "invariant division by multiplication" trick to 0N/A // accelerate Integer.toString. In particular we want to 0N/A // avoid division by 10. 0N/A // The "trick" has roughly the same performance characteristics 0N/A // as the "classic" Integer.toString code on a non-JIT VM. 0N/A // The trick avoids .rem and .div calls but has a longer code 0N/A // path and is thus dominated by dispatch overhead. In the 0N/A // JIT case the dispatch overhead doesn't exist and the 0N/A // "trick" is considerably faster than the classic code. 0N/A // TODO-FIXME: convert (x * 52429) into the equiv shift-add 0N/A // RE: Division by Invariant Integers using Multiplication 0N/A // T Gralund, P Montgomery 0N/A * Returns a {@code String} object representing the 0N/A * specified integer. The argument is converted to signed decimal 0N/A * representation and returned as a string, exactly as if the 0N/A * argument and radix 10 were given as arguments to the {@link 0N/A * #toString(int, int)} method. 0N/A * @param i an integer to be converted. 0N/A * @return a string representation of the argument in base 10. 0N/A return "-2147483648";
0N/A * Places characters representing the integer i into the 0N/A * character array buf. The characters are placed into 0N/A * the buffer backwards starting with the least significant 0N/A * digit at the specified index (exclusive), and working 0N/A * backwards from there. 0N/A * Will fail if i == Integer.MIN_VALUE 0N/A // Generate two digits per iteration 0N/A while (i >=
65536) {
0N/A // really: r = i - (q * 100); 0N/A r = i - ((q <<
6) + (q <<
5) + (q <<
2));
0N/A // Fall thru to fast mode for smaller numbers 0N/A // assert(i <= 65536, i); 0N/A q = (i *
52429) >>> (
16+
3);
0N/A r = i - ((q <<
3) + (q <<
1));
// r = i-(q*10) ... 0N/A final static int []
sizeTable = {
9,
99,
999,
9999,
99999,
999999,
9999999,
0N/A // Requires positive x 0N/A for (
int i=
0; ; i++)
0N/A * Parses the string argument as a signed integer in the radix 0N/A * specified by the second argument. The characters in the string 0N/A * must all be digits of the specified radix (as determined by 0N/A * whether {@link java.lang.Character#digit(char, int)} returns a 0N/A * nonnegative value), except that the first character may be an 0N/A * ASCII minus sign {@code '-'} (<code>'\u002D'</code>) to 0N/A * indicate a negative value or an ASCII plus sign {@code '+'} 0N/A * (<code>'\u002B'</code>) to indicate a positive value. The 0N/A * resulting integer value is returned. 0N/A * <p>An exception of type {@code NumberFormatException} is 0N/A * thrown if any of the following situations occurs: 0N/A * <li>The first argument is {@code null} or is a string of 0N/A * <li>The radix is either smaller than 0N/A * {@link java.lang.Character#MIN_RADIX} or 0N/A * larger than {@link java.lang.Character#MAX_RADIX}. 0N/A * <li>Any character of the string is not a digit of the specified 0N/A * radix, except that the first character may be a minus sign 0N/A * {@code '-'} (<code>'\u002D'</code>) or plus sign 0N/A * {@code '+'} (<code>'\u002B'</code>) provided that the 0N/A * string is longer than length 1. 0N/A * <li>The value represented by the string is not a value of type 0N/A * parseInt("0", 10) returns 0 0N/A * parseInt("473", 10) returns 473 0N/A * parseInt("+42", 10) returns 42 0N/A * parseInt("-0", 10) returns 0 0N/A * parseInt("-FF", 16) returns -255 0N/A * parseInt("1100110", 2) returns 102 0N/A * parseInt("2147483647", 10) returns 2147483647 0N/A * parseInt("-2147483648", 10) returns -2147483648 0N/A * parseInt("2147483648", 10) throws a NumberFormatException 0N/A * parseInt("99", 8) throws a NumberFormatException 0N/A * parseInt("Kona", 10) throws a NumberFormatException 0N/A * parseInt("Kona", 27) returns 411787 0N/A * </pre></blockquote> 0N/A * @param s the {@code String} containing the integer 0N/A * representation to be parsed 0N/A * @param radix the radix to be used while parsing {@code s}. 0N/A * @return the integer represented by the string argument in the 0N/A * @exception NumberFormatException if the {@code String} 0N/A * does not contain a parsable {@code int}. 1019N/A * WARNING: This method may be invoked early during VM initialization 1019N/A * before IntegerCache is initialized. Care must be taken to not use 0N/A " less than Character.MIN_RADIX");
0N/A " greater than Character.MAX_RADIX");
0N/A if (
len ==
1)
// Cannot have lone "+" or "-" 0N/A // Accumulating negatively avoids surprises near MAX_VALUE 0N/A * Parses the string argument as a signed decimal integer. The 0N/A * characters in the string must all be decimal digits, except 0N/A * that the first character may be an ASCII minus sign {@code '-'} 0N/A * (<code>'\u002D'</code>) to indicate a negative value or an 0N/A * ASCII plus sign {@code '+'} (<code>'\u002B'</code>) to 0N/A * indicate a positive value. The resulting integer value is 0N/A * returned, exactly as if the argument and the radix 10 were 0N/A * given as arguments to the {@link #parseInt(java.lang.String, 0N/A * @param s a {@code String} containing the {@code int} 0N/A * representation to be parsed 0N/A * @return the integer value represented by the argument in decimal. 0N/A * @exception NumberFormatException if the string does not contain a 0N/A * Returns an {@code Integer} object holding the value 0N/A * extracted from the specified {@code String} when parsed 0N/A * with the radix given by the second argument. The first argument 0N/A * is interpreted as representing a signed integer in the radix 0N/A * specified by the second argument, exactly as if the arguments 0N/A * were given to the {@link #parseInt(java.lang.String, int)} 0N/A * method. The result is an {@code Integer} object that 0N/A * represents the integer value specified by the string. 0N/A * <p>In other words, this method returns an {@code Integer} 0N/A * object equal to the value of: 0N/A * {@code new Integer(Integer.parseInt(s, radix))} 0N/A * @param s the string to be parsed. 0N/A * @param radix the radix to be used in interpreting {@code s} 0N/A * @return an {@code Integer} object holding the value 0N/A * represented by the string argument in the specified 0N/A * @exception NumberFormatException if the {@code String} 0N/A * does not contain a parsable {@code int}. 0N/A * Returns an {@code Integer} object holding the 0N/A * value of the specified {@code String}. The argument is 0N/A * interpreted as representing a signed decimal integer, exactly 0N/A * as if the argument were given to the {@link 0N/A * #parseInt(java.lang.String)} method. The result is an 0N/A * {@code Integer} object that represents the integer value 0N/A * specified by the string. 0N/A * <p>In other words, this method returns an {@code Integer} 0N/A * object equal to the value of: 0N/A * {@code new Integer(Integer.parseInt(s))} 0N/A * @param s the string to be parsed. 0N/A * @return an {@code Integer} object holding the value 0N/A * represented by the string argument. 0N/A * @exception NumberFormatException if the string cannot be parsed 1019N/A * Cache to support the object identity semantics of autoboxing for values between 1019N/A * -128 and 127 (inclusive) as required by JLS. 1019N/A * The cache is initialized on first usage. During VM initialization the 1019N/A * getAndRemoveCacheProperties method may be used to get and remove any system 1019N/A * properites that configure the cache size. At this time, the size of the 1019N/A * cache may be controlled by the -XX:AutoBoxCacheMax=<size> option. 1019N/A // value of java.lang.Integer.IntegerCache.high property (obtained during VM init) 1019N/A // high value may be configured by property 1019N/A // Maximum array size is Integer.MAX_VALUE 0N/A * Returns an {@code Integer} instance representing the specified 0N/A * {@code int} value. If a new {@code Integer} instance is not 0N/A * required, this method should generally be used in preference to 0N/A * the constructor {@link #Integer(int)}, as this method is likely 0N/A * to yield significantly better space and time performance by 0N/A * caching frequently requested values. 1390N/A * This method will always cache values in the range -128 to 127, 1390N/A * inclusive, and may cache other values outside of this range. 0N/A * @param i an {@code int} value. 0N/A * @return an {@code Integer} instance representing {@code i}. 0N/A * The value of the {@code Integer}. 0N/A * Constructs a newly allocated {@code Integer} object that 0N/A * represents the specified {@code int} value. 0N/A * @param value the value to be represented by the 0N/A * {@code Integer} object. 0N/A * Constructs a newly allocated {@code Integer} object that 0N/A * represents the {@code int} value indicated by the 0N/A * {@code String} parameter. The string is converted to an 0N/A * {@code int} value in exactly the manner used by the 0N/A * {@code parseInt} method for radix 10. 0N/A * @param s the {@code String} to be converted to an 0N/A * @exception NumberFormatException if the {@code String} does not 0N/A * contain a parsable integer. 0N/A * @see java.lang.Integer#parseInt(java.lang.String, int) 0N/A * Returns the value of this {@code Integer} as a 0N/A * Returns the value of this {@code Integer} as a 0N/A * Returns the value of this {@code Integer} as an 0N/A * Returns the value of this {@code Integer} as a 0N/A * Returns the value of this {@code Integer} as a 0N/A * Returns the value of this {@code Integer} as a 0N/A * Returns a {@code String} object representing this 0N/A * {@code Integer}'s value. The value is converted to signed 0N/A * decimal representation and returned as a string, exactly as if 0N/A * the integer value were given as an argument to the {@link 0N/A * java.lang.Integer#toString(int)} method. 0N/A * @return a string representation of the value of this object in 0N/A * Returns a hash code for this {@code Integer}. 0N/A * @return a hash code value for this object, equal to the 0N/A * primitive {@code int} value represented by this 0N/A * {@code Integer} object. 0N/A * Compares this object to the specified object. The result is 0N/A * {@code true} if and only if the argument is not 0N/A * {@code null} and is an {@code Integer} object that 0N/A * contains the same {@code int} value as this object. 0N/A * @param obj the object to compare with. 0N/A * @return {@code true} if the objects are the same; 0N/A * {@code false} otherwise. 0N/A * Determines the integer value of the system property with the 0N/A * <p>The first argument is treated as the name of a system property. 0N/A * System properties are accessible through the 0N/A * {@link java.lang.System#getProperty(java.lang.String)} method. The 0N/A * string value of this property is then interpreted as an integer 0N/A * value and an {@code Integer} object representing this value is 0N/A * returned. Details of possible numeric formats can be found with 0N/A * the definition of {@code getProperty}. 0N/A * <p>If there is no property with the specified name, if the specified name 0N/A * is empty or {@code null}, or if the property does not have 0N/A * the correct numeric format, then {@code null} is returned. 0N/A * <p>In other words, this method returns an {@code Integer} 0N/A * object equal to the value of: 0N/A * {@code getInteger(nm, null)} 0N/A * @param nm property name. 0N/A * @return the {@code Integer} value of the property. 0N/A * @see java.lang.System#getProperty(java.lang.String) 0N/A * @see java.lang.System#getProperty(java.lang.String, java.lang.String) 0N/A * Determines the integer value of the system property with the 0N/A * <p>The first argument is treated as the name of a system property. 0N/A * System properties are accessible through the {@link 0N/A * java.lang.System#getProperty(java.lang.String)} method. The 0N/A * string value of this property is then interpreted as an integer 0N/A * value and an {@code Integer} object representing this value is 0N/A * returned. Details of possible numeric formats can be found with 0N/A * the definition of {@code getProperty}. 0N/A * <p>The second argument is the default value. An {@code Integer} object 0N/A * that represents the value of the second argument is returned if there 0N/A * is no property of the specified name, if the property does not have 0N/A * the correct numeric format, or if the specified name is empty or 0N/A * <p>In other words, this method returns an {@code Integer} object 0N/A * equal to the value of: 0N/A * {@code getInteger(nm, new Integer(val))} 0N/A * but in practice it may be implemented in a manner such as: 0N/A * Integer result = getInteger(nm, null); 0N/A * return (result == null) ? new Integer(val) : result; 0N/A * </pre></blockquote> 0N/A * to avoid the unnecessary allocation of an {@code Integer} 0N/A * object when the default value is not needed. 0N/A * @param nm property name. 0N/A * @param val default value. 0N/A * @return the {@code Integer} value of the property. 0N/A * @see java.lang.System#getProperty(java.lang.String) 0N/A * @see java.lang.System#getProperty(java.lang.String, java.lang.String) 0N/A * Returns the integer value of the system property with the 0N/A * specified name. The first argument is treated as the name of a 0N/A * system property. System properties are accessible through the 0N/A * {@link java.lang.System#getProperty(java.lang.String)} method. 0N/A * The string value of this property is then interpreted as an 0N/A * integer value, as per the {@code Integer.decode} method, 0N/A * and an {@code Integer} object representing this value is 0N/A * <ul><li>If the property value begins with the two ASCII characters 0N/A * {@code 0x} or the ASCII character {@code #}, not 0N/A * followed by a minus sign, then the rest of it is parsed as a 0N/A * hexadecimal integer exactly as by the method 0N/A * {@link #valueOf(java.lang.String, int)} with radix 16. 0N/A * <li>If the property value begins with the ASCII character 0N/A * {@code 0} followed by another character, it is parsed as an 0N/A * octal integer exactly as by the method 0N/A * {@link #valueOf(java.lang.String, int)} with radix 8. 0N/A * <li>Otherwise, the property value is parsed as a decimal integer 0N/A * exactly as by the method {@link #valueOf(java.lang.String, int)} 0N/A * <p>The second argument is the default value. The default value is 0N/A * returned if there is no property of the specified name, if the 0N/A * property does not have the correct numeric format, or if the 0N/A * specified name is empty or {@code null}. 0N/A * @param nm property name. 0N/A * @param val default value. 0N/A * @return the {@code Integer} value of the property. 0N/A * @see java.lang.System#getProperty(java.lang.String) 0N/A * @see java.lang.System#getProperty(java.lang.String, java.lang.String) 0N/A * @see java.lang.Integer#decode 0N/A * Decodes a {@code String} into an {@code Integer}. 0N/A * Accepts decimal, hexadecimal, and octal numbers given 0N/A * by the following grammar: 0N/A * <dt><i>DecodableString:</i> 0N/A * <dd><i>Sign<sub>opt</sub> DecimalNumeral</i> 0N/A * <dd><i>Sign<sub>opt</sub></i> {@code 0x} <i>HexDigits</i> 0N/A * <dd><i>Sign<sub>opt</sub></i> {@code 0X} <i>HexDigits</i> 0N/A * <dd><i>Sign<sub>opt</sub></i> {@code #} <i>HexDigits</i> 0N/A * <dd><i>Sign<sub>opt</sub></i> {@code 0} <i>OctalDigits</i> 0N/A * <i>DecimalNumeral</i>, <i>HexDigits</i>, and <i>OctalDigits</i> 0N/A * Language Specification</a>. 0N/A * <p>The sequence of characters following an optional 0N/A * sign and/or radix specifier ("{@code 0x}", "{@code 0X}", 0N/A * "{@code #}", or leading zero) is parsed as by the {@code 0N/A * Integer.parseInt} method with the indicated radix (10, 16, or 0N/A * 8). This sequence of characters must represent a positive 0N/A * value or a {@link NumberFormatException} will be thrown. The 0N/A * result is negated if first character of the specified {@code 0N/A * String} is the minus sign. No whitespace characters are 0N/A * permitted in the {@code String}. 0N/A * @param nm the {@code String} to decode. 0N/A * @return an {@code Integer} object holding the {@code int} 0N/A * value represented by {@code nm} 0N/A * @exception NumberFormatException if the {@code String} does not 0N/A * contain a parsable integer. 0N/A * @see java.lang.Integer#parseInt(java.lang.String, int) 0N/A // Handle sign, if present 0N/A // Handle radix specifier, if present 0N/A // If number is Integer.MIN_VALUE, we'll end up here. The next line 0N/A // handles this case, and causes any genuine format error to be 0N/A * Compares two {@code Integer} objects numerically. 0N/A * @param anotherInteger the {@code Integer} to be compared. 0N/A * @return the value {@code 0} if this {@code Integer} is 0N/A * equal to the argument {@code Integer}; a value less than 0N/A * {@code 0} if this {@code Integer} is numerically less 0N/A * than the argument {@code Integer}; and a value greater 0N/A * than {@code 0} if this {@code Integer} is numerically 0N/A * greater than the argument {@code Integer} (signed 0N/A * The number of bits used to represent an {@code int} value in two's 0N/A * complement binary form. 0N/A * Returns an {@code int} value with at most a single one-bit, in the 0N/A * position of the highest-order ("leftmost") one-bit in the specified 0N/A * {@code int} value. Returns zero if the specified value has no 0N/A * one-bits in its two's complement binary representation, that is, if it 0N/A * @return an {@code int} value with a single one-bit, in the position 0N/A * of the highest-order one-bit in the specified value, or zero if 0N/A * the specified value is itself equal to zero. 0N/A return i - (i >>>
1);
0N/A * Returns an {@code int} value with at most a single one-bit, in the 0N/A * position of the lowest-order ("rightmost") one-bit in the specified 0N/A * {@code int} value. Returns zero if the specified value has no 0N/A * one-bits in its two's complement binary representation, that is, if it 0N/A * @return an {@code int} value with a single one-bit, in the position 0N/A * of the lowest-order one-bit in the specified value, or zero if 0N/A * the specified value is itself equal to zero. 0N/A * Returns the number of zero bits preceding the highest-order 0N/A * ("leftmost") one-bit in the two's complement binary representation 0N/A * of the specified {@code int} value. Returns 32 if the 0N/A * specified value has no one-bits in its two's complement representation, 0N/A * in other words if it is equal to zero. 0N/A * <p>Note that this method is closely related to the logarithm base 2. 0N/A * For all positive {@code int} values x: 0N/A * <li>floor(log<sub>2</sub>(x)) = {@code 31 - numberOfLeadingZeros(x)} 0N/A * <li>ceil(log<sub>2</sub>(x)) = {@code 32 - numberOfLeadingZeros(x - 1)} 0N/A * @return the number of zero bits preceding the highest-order 0N/A * ("leftmost") one-bit in the two's complement binary representation 0N/A * of the specified {@code int} value, or 32 if the value 0N/A if (i >>>
16 ==
0) { n +=
16; i <<=
16; }
0N/A if (i >>>
24 ==
0) { n +=
8; i <<=
8; }
0N/A if (i >>>
28 ==
0) { n +=
4; i <<=
4; }
0N/A if (i >>>
30 ==
0) { n +=
2; i <<=
2; }
0N/A * Returns the number of zero bits following the lowest-order ("rightmost") 0N/A * one-bit in the two's complement binary representation of the specified 0N/A * {@code int} value. Returns 32 if the specified value has no 0N/A * one-bits in its two's complement representation, in other words if it is 0N/A * @return the number of zero bits following the lowest-order ("rightmost") 0N/A * one-bit in the two's complement binary representation of the 0N/A * specified {@code int} value, or 32 if the value is equal 0N/A if (i ==
0)
return 32;
0N/A y = i <<
16;
if (y !=
0) { n = n -
16; i = y; }
0N/A y = i <<
8;
if (y !=
0) { n = n -
8; i = y; }
0N/A y = i <<
4;
if (y !=
0) { n = n -
4; i = y; }
0N/A y = i <<
2;
if (y !=
0) { n = n -
2; i = y; }
0N/A return n - ((i <<
1) >>>
31);
0N/A * Returns the number of one-bits in the two's complement binary 0N/A * representation of the specified {@code int} value. This function is 0N/A * sometimes referred to as the <i>population count</i>. 0N/A * @return the number of one-bits in the two's complement binary 0N/A * representation of the specified {@code int} value. 0N/A i = i - ((i >>>
1) &
0x55555555);
0N/A i = (i &
0x33333333) + ((i >>>
2) &
0x33333333);
0N/A i = (i + (i >>>
4)) &
0x0f0f0f0f;
0N/A * Returns the value obtained by rotating the two's complement binary 0N/A * representation of the specified {@code int} value left by the 0N/A * specified number of bits. (Bits shifted out of the left hand, or 0N/A * high-order, side reenter on the right, or low-order.) 0N/A * <p>Note that left rotation with a negative distance is equivalent to 0N/A * right rotation: {@code rotateLeft(val, -distance) == rotateRight(val, 0N/A * distance)}. Note also that rotation by any multiple of 32 is a 0N/A * no-op, so all but the last five bits of the rotation distance can be 0N/A * ignored, even if the distance is negative: {@code rotateLeft(val, 0N/A * distance) == rotateLeft(val, distance & 0x1F)}. 0N/A * @return the value obtained by rotating the two's complement binary 0N/A * representation of the specified {@code int} value left by the 0N/A * specified number of bits. 0N/A * Returns the value obtained by rotating the two's complement binary 0N/A * representation of the specified {@code int} value right by the 0N/A * specified number of bits. (Bits shifted out of the right hand, or 0N/A * low-order, side reenter on the left, or high-order.) 0N/A * <p>Note that right rotation with a negative distance is equivalent to 0N/A * left rotation: {@code rotateRight(val, -distance) == rotateLeft(val, 0N/A * distance)}. Note also that rotation by any multiple of 32 is a 0N/A * no-op, so all but the last five bits of the rotation distance can be 0N/A * ignored, even if the distance is negative: {@code rotateRight(val, 0N/A * distance) == rotateRight(val, distance & 0x1F)}. 0N/A * @return the value obtained by rotating the two's complement binary 0N/A * representation of the specified {@code int} value right by the 0N/A * specified number of bits. 0N/A * Returns the value obtained by reversing the order of the bits in the 0N/A * two's complement binary representation of the specified {@code int} 0N/A * @return the value obtained by reversing order of the bits in the 0N/A * specified {@code int} value. 0N/A i = (i &
0x55555555) <<
1 | (i >>>
1) &
0x55555555;
0N/A i = (i &
0x33333333) <<
2 | (i >>>
2) &
0x33333333;
0N/A i = (i &
0x0f0f0f0f) <<
4 | (i >>>
4) &
0x0f0f0f0f;
0N/A i = (i <<
24) | ((i &
0xff00) <<
8) |
0N/A ((i >>>
8) &
0xff00) | (i >>>
24);
0N/A * Returns the signum function of the specified {@code int} value. (The 0N/A * return value is -1 if the specified value is negative; 0 if the 0N/A * specified value is zero; and 1 if the specified value is positive.) 0N/A * @return the signum function of the specified {@code int} value. 0N/A return (i >>
31) | (-i >>>
31);
0N/A * Returns the value obtained by reversing the order of the bytes in the 0N/A * two's complement representation of the specified {@code int} value. 0N/A * @return the value obtained by reversing the bytes in the specified 0N/A * {@code int} value. 0N/A return ((i >>>
24) ) |
0N/A ((i >>
8) &
0xFF00) |
0N/A ((i <<
8) &
0xFF0000) |
0N/A /** use serialVersionUID from JDK 1.0.2 for interoperability */