< prev index next >

src/java.base/share/classes/java/lang/Integer.java

Print this page
rev 52865 : [mq]: 8210031


   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package java.lang;
  27 
  28 import java.lang.annotation.Native;



  29 import java.util.Objects;


  30 import jdk.internal.HotSpotIntrinsicCandidate;
  31 import jdk.internal.misc.VM;
  32 
  33 import static java.lang.String.COMPACT_STRINGS;
  34 import static java.lang.String.LATIN1;
  35 import static java.lang.String.UTF16;
  36 
  37 /**
  38  * The {@code Integer} class wraps a value of the primitive type
  39  * {@code int} in an object. An object of type {@code Integer}
  40  * contains a single field whose type is {@code int}.
  41  *
  42  * <p>In addition, this class provides several methods for converting
  43  * an {@code int} to a {@code String} and a {@code String} to an
  44  * {@code int}, as well as other constants and methods useful when
  45  * dealing with an {@code int}.
  46  *
  47  * <p>Implementation note: The implementations of the "bit twiddling"
  48  * methods (such as {@link #highestOneBit(int) highestOneBit} and
  49  * {@link #numberOfTrailingZeros(int) numberOfTrailingZeros}) are
  50  * based on material from Henry S. Warren, Jr.'s <i>Hacker's
  51  * Delight</i>, (Addison Wesley, 2002).
  52  *
  53  * @author  Lee Boynton
  54  * @author  Arthur van Hoff
  55  * @author  Josh Bloch
  56  * @author  Joseph D. Darcy
  57  * @since 1.0
  58  */
  59 public final class Integer extends Number implements Comparable<Integer> {

  60     /**
  61      * A constant holding the minimum value an {@code int} can
  62      * have, -2<sup>31</sup>.
  63      */
  64     @Native public static final int   MIN_VALUE = 0x80000000;
  65 
  66     /**
  67      * A constant holding the maximum value an {@code int} can
  68      * have, 2<sup>31</sup>-1.
  69      */
  70     @Native public static final int   MAX_VALUE = 0x7fffffff;
  71 
  72     /**
  73      * The {@code Class} instance representing the primitive type
  74      * {@code int}.
  75      *
  76      * @since   1.1
  77      */
  78     @SuppressWarnings("unchecked")
  79     public static final Class<Integer>  TYPE = (Class<Integer>) Class.getPrimitiveClass("int");


1812      * @return the greater of {@code a} and {@code b}
1813      * @see java.util.function.BinaryOperator
1814      * @since 1.8
1815      */
1816     public static int max(int a, int b) {
1817         return Math.max(a, b);
1818     }
1819 
1820     /**
1821      * Returns the smaller of two {@code int} values
1822      * as if by calling {@link Math#min(int, int) Math.min}.
1823      *
1824      * @param a the first operand
1825      * @param b the second operand
1826      * @return the smaller of {@code a} and {@code b}
1827      * @see java.util.function.BinaryOperator
1828      * @since 1.8
1829      */
1830     public static int min(int a, int b) {
1831         return Math.min(a, b);

























1832     }
1833 
1834     /** use serialVersionUID from JDK 1.0.2 for interoperability */
1835     @Native private static final long serialVersionUID = 1360826667806852920L;
1836 }


   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package java.lang;
  27 
  28 import java.lang.annotation.Native;
  29 import java.lang.invoke.MethodHandles;
  30 import java.lang.constant.Constable;
  31 import java.lang.constant.ConstantDesc;
  32 import java.util.Objects;
  33 import java.util.Optional;
  34 
  35 import jdk.internal.HotSpotIntrinsicCandidate;
  36 import jdk.internal.misc.VM;
  37 
  38 import static java.lang.String.COMPACT_STRINGS;
  39 import static java.lang.String.LATIN1;
  40 import static java.lang.String.UTF16;
  41 
  42 /**
  43  * The {@code Integer} class wraps a value of the primitive type
  44  * {@code int} in an object. An object of type {@code Integer}
  45  * contains a single field whose type is {@code int}.
  46  *
  47  * <p>In addition, this class provides several methods for converting
  48  * an {@code int} to a {@code String} and a {@code String} to an
  49  * {@code int}, as well as other constants and methods useful when
  50  * dealing with an {@code int}.
  51  *
  52  * <p>Implementation note: The implementations of the "bit twiddling"
  53  * methods (such as {@link #highestOneBit(int) highestOneBit} and
  54  * {@link #numberOfTrailingZeros(int) numberOfTrailingZeros}) are
  55  * based on material from Henry S. Warren, Jr.'s <i>Hacker's
  56  * Delight</i>, (Addison Wesley, 2002).
  57  *
  58  * @author  Lee Boynton
  59  * @author  Arthur van Hoff
  60  * @author  Josh Bloch
  61  * @author  Joseph D. Darcy
  62  * @since 1.0
  63  */
  64 public final class Integer extends Number
  65         implements Comparable<Integer>, ConstantDesc, Constable {
  66     /**
  67      * A constant holding the minimum value an {@code int} can
  68      * have, -2<sup>31</sup>.
  69      */
  70     @Native public static final int   MIN_VALUE = 0x80000000;
  71 
  72     /**
  73      * A constant holding the maximum value an {@code int} can
  74      * have, 2<sup>31</sup>-1.
  75      */
  76     @Native public static final int   MAX_VALUE = 0x7fffffff;
  77 
  78     /**
  79      * The {@code Class} instance representing the primitive type
  80      * {@code int}.
  81      *
  82      * @since   1.1
  83      */
  84     @SuppressWarnings("unchecked")
  85     public static final Class<Integer>  TYPE = (Class<Integer>) Class.getPrimitiveClass("int");


1818      * @return the greater of {@code a} and {@code b}
1819      * @see java.util.function.BinaryOperator
1820      * @since 1.8
1821      */
1822     public static int max(int a, int b) {
1823         return Math.max(a, b);
1824     }
1825 
1826     /**
1827      * Returns the smaller of two {@code int} values
1828      * as if by calling {@link Math#min(int, int) Math.min}.
1829      *
1830      * @param a the first operand
1831      * @param b the second operand
1832      * @return the smaller of {@code a} and {@code b}
1833      * @see java.util.function.BinaryOperator
1834      * @since 1.8
1835      */
1836     public static int min(int a, int b) {
1837         return Math.min(a, b);
1838     }
1839 
1840     /**
1841      * Returns a nominal descriptor for this instance, which is the instance
1842      * itself.
1843      *
1844      * @return an {@link Optional} describing the {@linkplain Integer} instance
1845      * @since 12
1846      */
1847     @Override
1848     public Optional<Integer> describeConstable() {
1849         return Optional.of(this);
1850     }
1851 
1852     /**
1853      * Resolves this instance as a {@link ConstantDesc}, the result of which is
1854      * the instance itself.
1855      *
1856      * @param lookup ignored
1857      * @return the {@linkplain Integer} instance
1858      * @since 12
1859      */
1860     @Override
1861     public Integer resolveConstantDesc(MethodHandles.Lookup lookup) {
1862         return this;
1863     }
1864 
1865     /** use serialVersionUID from JDK 1.0.2 for interoperability */
1866     @Native private static final long serialVersionUID = 1360826667806852920L;
1867 }
< prev index next >