emul/mini/src/main/java/java/lang/Number.java
author Jaroslav Tulach <jaroslav.tulach@apidesign.org>
Sat, 26 Jan 2013 08:47:05 +0100
changeset 592 5e13b1ac2886
parent 554 05224402145d
permissions -rw-r--r--
In order to support fields of the same name in subclasses we are now prefixing them with name of the class that defines them. To provide convenient way to access them from generated bytecode and also directly from JavaScript, there is a getter/setter function for each field. It starts with _ followed by the field name. If called with a parameter, it sets the field, with a parameter it just returns it.
jaroslav@49
     1
/*
jaroslav@49
     2
 * Copyright (c) 1994, 2001, Oracle and/or its affiliates. All rights reserved.
jaroslav@49
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
jaroslav@49
     4
 *
jaroslav@49
     5
 * This code is free software; you can redistribute it and/or modify it
jaroslav@49
     6
 * under the terms of the GNU General Public License version 2 only, as
jaroslav@49
     7
 * published by the Free Software Foundation.  Oracle designates this
jaroslav@49
     8
 * particular file as subject to the "Classpath" exception as provided
jaroslav@49
     9
 * by Oracle in the LICENSE file that accompanied this code.
jaroslav@49
    10
 *
jaroslav@49
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
jaroslav@49
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
jaroslav@49
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
jaroslav@49
    14
 * version 2 for more details (a copy is included in the LICENSE file that
jaroslav@49
    15
 * accompanied this code).
jaroslav@49
    16
 *
jaroslav@49
    17
 * You should have received a copy of the GNU General Public License version
jaroslav@49
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
jaroslav@49
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
jaroslav@49
    20
 *
jaroslav@49
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
jaroslav@49
    22
 * or visit www.oracle.com if you need additional information or have any
jaroslav@49
    23
 * questions.
jaroslav@49
    24
 */
jaroslav@49
    25
jaroslav@49
    26
package java.lang;
jaroslav@49
    27
Martin@438
    28
import org.apidesign.bck2brwsr.core.ExtraJavaScript;
Martin@438
    29
jaroslav@49
    30
/**
jaroslav@49
    31
 * The abstract class <code>Number</code> is the superclass of classes
jaroslav@49
    32
 * <code>BigDecimal</code>, <code>BigInteger</code>,
jaroslav@49
    33
 * <code>Byte</code>, <code>Double</code>, <code>Float</code>,
jaroslav@49
    34
 * <code>Integer</code>, <code>Long</code>, and <code>Short</code>.
jaroslav@49
    35
 * <p>
jaroslav@49
    36
 * Subclasses of <code>Number</code> must provide methods to convert
jaroslav@49
    37
 * the represented numeric value to <code>byte</code>, <code>double</code>,
jaroslav@49
    38
 * <code>float</code>, <code>int</code>, <code>long</code>, and
jaroslav@49
    39
 * <code>short</code>.
jaroslav@49
    40
 *
jaroslav@49
    41
 * @author      Lee Boynton
jaroslav@49
    42
 * @author      Arthur van Hoff
jaroslav@49
    43
 * @see     java.lang.Byte
jaroslav@49
    44
 * @see     java.lang.Double
jaroslav@49
    45
 * @see     java.lang.Float
jaroslav@49
    46
 * @see     java.lang.Integer
jaroslav@49
    47
 * @see     java.lang.Long
jaroslav@49
    48
 * @see     java.lang.Short
jaroslav@49
    49
 * @since   JDK1.0
jaroslav@49
    50
 */
Martin@438
    51
@ExtraJavaScript(
jaroslav@555
    52
    resource="/org/apidesign/vm4brwsr/emul/lang/java_lang_Number.js",
Martin@438
    53
    processByteCode=true
Martin@438
    54
)
jaroslav@49
    55
public abstract class Number implements java.io.Serializable {
jaroslav@49
    56
    /**
jaroslav@49
    57
     * Returns the value of the specified number as an <code>int</code>.
jaroslav@49
    58
     * This may involve rounding or truncation.
jaroslav@49
    59
     *
jaroslav@49
    60
     * @return  the numeric value represented by this object after conversion
jaroslav@49
    61
     *          to type <code>int</code>.
jaroslav@49
    62
     */
jaroslav@49
    63
    public abstract int intValue();
jaroslav@49
    64
jaroslav@49
    65
    /**
jaroslav@49
    66
     * Returns the value of the specified number as a <code>long</code>.
jaroslav@49
    67
     * This may involve rounding or truncation.
jaroslav@49
    68
     *
jaroslav@49
    69
     * @return  the numeric value represented by this object after conversion
jaroslav@49
    70
     *          to type <code>long</code>.
jaroslav@49
    71
     */
jaroslav@49
    72
    public abstract long longValue();
jaroslav@49
    73
jaroslav@49
    74
    /**
jaroslav@49
    75
     * Returns the value of the specified number as a <code>float</code>.
jaroslav@49
    76
     * This may involve rounding.
jaroslav@49
    77
     *
jaroslav@49
    78
     * @return  the numeric value represented by this object after conversion
jaroslav@49
    79
     *          to type <code>float</code>.
jaroslav@49
    80
     */
jaroslav@49
    81
    public abstract float floatValue();
jaroslav@49
    82
jaroslav@49
    83
    /**
jaroslav@49
    84
     * Returns the value of the specified number as a <code>double</code>.
jaroslav@49
    85
     * This may involve rounding.
jaroslav@49
    86
     *
jaroslav@49
    87
     * @return  the numeric value represented by this object after conversion
jaroslav@49
    88
     *          to type <code>double</code>.
jaroslav@49
    89
     */
jaroslav@49
    90
    public abstract double doubleValue();
jaroslav@49
    91
jaroslav@49
    92
    /**
jaroslav@49
    93
     * Returns the value of the specified number as a <code>byte</code>.
jaroslav@49
    94
     * This may involve rounding or truncation.
jaroslav@49
    95
     *
jaroslav@49
    96
     * @return  the numeric value represented by this object after conversion
jaroslav@49
    97
     *          to type <code>byte</code>.
jaroslav@49
    98
     * @since   JDK1.1
jaroslav@49
    99
     */
jaroslav@49
   100
    public byte byteValue() {
jaroslav@49
   101
        return (byte)intValue();
jaroslav@49
   102
    }
jaroslav@49
   103
jaroslav@49
   104
    /**
jaroslav@49
   105
     * Returns the value of the specified number as a <code>short</code>.
jaroslav@49
   106
     * This may involve rounding or truncation.
jaroslav@49
   107
     *
jaroslav@49
   108
     * @return  the numeric value represented by this object after conversion
jaroslav@49
   109
     *          to type <code>short</code>.
jaroslav@49
   110
     * @since   JDK1.1
jaroslav@49
   111
     */
jaroslav@49
   112
    public short shortValue() {
jaroslav@49
   113
        return (short)intValue();
jaroslav@49
   114
    }
jaroslav@49
   115
jaroslav@49
   116
    /** use serialVersionUID from JDK 1.0.2 for interoperability */
jaroslav@49
   117
    private static final long serialVersionUID = -8742448824652078965L;
jaroslav@49
   118
}