< prev index next >

src/java.base/share/classes/java/lang/Long.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.math.*;
  30 import java.util.Objects;


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

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


1941      * @return the greater of {@code a} and {@code b}
1942      * @see java.util.function.BinaryOperator
1943      * @since 1.8
1944      */
1945     public static long max(long a, long b) {
1946         return Math.max(a, b);
1947     }
1948 
1949     /**
1950      * Returns the smaller of two {@code long} values
1951      * as if by calling {@link Math#min(long, long) Math.min}.
1952      *
1953      * @param a the first operand
1954      * @param b the second operand
1955      * @return the smaller of {@code a} and {@code b}
1956      * @see java.util.function.BinaryOperator
1957      * @since 1.8
1958      */
1959     public static long min(long a, long b) {
1960         return Math.min(a, b);

























1961     }
1962 
1963     /** use serialVersionUID from JDK 1.0.2 for interoperability */
1964     @Native private static final long serialVersionUID = 4290774380558885855L;
1965 }


   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.math.*;
  33 import java.util.Objects;
  34 import java.util.Optional;
  35 
  36 import jdk.internal.HotSpotIntrinsicCandidate;
  37 import jdk.internal.misc.VM;
  38 
  39 import static java.lang.String.COMPACT_STRINGS;
  40 import static java.lang.String.LATIN1;
  41 import static java.lang.String.UTF16;
  42 
  43 /**
  44  * The {@code Long} class wraps a value of the primitive type {@code
  45  * long} in an object. An object of type {@code Long} contains a
  46  * single field whose type is {@code long}.
  47  *
  48  * <p> In addition, this class provides several methods for converting
  49  * a {@code long} to a {@code String} and a {@code String} to a {@code
  50  * long}, as well as other constants and methods useful when dealing
  51  * with a {@code long}.
  52  *
  53  * <p>Implementation note: The implementations of the "bit twiddling"
  54  * methods (such as {@link #highestOneBit(long) highestOneBit} and
  55  * {@link #numberOfTrailingZeros(long) numberOfTrailingZeros}) are
  56  * based on material from Henry S. Warren, Jr.'s <i>Hacker's
  57  * Delight</i>, (Addison Wesley, 2002).
  58  *
  59  * @author  Lee Boynton
  60  * @author  Arthur van Hoff
  61  * @author  Josh Bloch
  62  * @author  Joseph D. Darcy
  63  * @since   1.0
  64  */
  65 public final class Long extends Number
  66         implements Comparable<Long>, ConstantDesc, Constable {
  67     /**
  68      * A constant holding the minimum value a {@code long} can
  69      * have, -2<sup>63</sup>.
  70      */
  71     @Native public static final long MIN_VALUE = 0x8000000000000000L;
  72 
  73     /**
  74      * A constant holding the maximum value a {@code long} can
  75      * have, 2<sup>63</sup>-1.
  76      */
  77     @Native public static final long MAX_VALUE = 0x7fffffffffffffffL;
  78 
  79     /**
  80      * The {@code Class} instance representing the primitive type
  81      * {@code long}.
  82      *
  83      * @since   1.1
  84      */
  85     @SuppressWarnings("unchecked")
  86     public static final Class<Long>     TYPE = (Class<Long>) Class.getPrimitiveClass("long");


1947      * @return the greater of {@code a} and {@code b}
1948      * @see java.util.function.BinaryOperator
1949      * @since 1.8
1950      */
1951     public static long max(long a, long b) {
1952         return Math.max(a, b);
1953     }
1954 
1955     /**
1956      * Returns the smaller of two {@code long} values
1957      * as if by calling {@link Math#min(long, long) Math.min}.
1958      *
1959      * @param a the first operand
1960      * @param b the second operand
1961      * @return the smaller of {@code a} and {@code b}
1962      * @see java.util.function.BinaryOperator
1963      * @since 1.8
1964      */
1965     public static long min(long a, long b) {
1966         return Math.min(a, b);
1967     }
1968 
1969     /**
1970      * Returns a nominal descriptor for this instance, which is the instance
1971      * itself.
1972      *
1973      * @return an {@link Optional} describing the {@linkplain Long} instance
1974      * @since 12
1975      */
1976     @Override
1977     public Optional<Long> describeConstable() {
1978         return Optional.of(this);
1979     }
1980 
1981     /**
1982      * Resolves this instance as a {@link ConstantDesc}, the result of which is
1983      * the instance itself.
1984      *
1985      * @param lookup ignored
1986      * @return the {@linkplain Long} instance
1987      * @since 12
1988      */
1989     @Override
1990     public Long resolveConstantDesc(MethodHandles.Lookup lookup) {
1991         return this;
1992     }
1993 
1994     /** use serialVersionUID from JDK 1.0.2 for interoperability */
1995     @Native private static final long serialVersionUID = 4290774380558885855L;
1996 }
< prev index next >