OSDN Git Service

7cab8354471af726726510c2c5d05f76aab2a8ea
[nxt-jsp/lejos_nxj.git] / nxtOSEK / lejos_nxj / src / java / classes / java / lang / Integer.java
1 package java.lang;
2
3 /**
4  * Minimal Integer implementation that supports converting an int to a String.
5  *
6  */
7
8   public final class Integer {
9     /**
10      * The smallest value of type <code>int</code>. The constant 
11      * value of this field is <tt>-2147483648</tt>.
12      */
13     public static final int   MIN_VALUE = 0x80000000;
14
15     /**
16      * The largest value of type <code>int</code>. The constant 
17      * value of this field is <tt>2147483647</tt>.
18      */
19     public static final int   MAX_VALUE = 0x7fffffff;
20
21     /**
22      * The value of the Integer.
23      *
24      * @serial
25      */
26     private int value;
27
28     /**
29      * Constructs a newly allocated <code>Integer</code> object that
30      * represents the primitive <code>int</code> argument.
31      *
32      * @param   value   the value to be represented by the <code>Integer</code>.
33      */
34     public Integer(int value) {
35         this.value = value;
36     }
37
38     static char buf [] = new char [12] ; 
39
40     /**
41      * Returns a new String object representing the specified integer. The 
42      * argument is converted to signed decimal representation and returned 
43      * as a string, exactly as if the argument and radix <tt>10</tt> were 
44      * given as arguments to the toString(int, int) method.
45      *
46      * @param   i   an integer to be converted.
47      * @return  a string representation of the argument in base&nbsp;10.
48      */
49     public static synchronized String toString(int i) {
50        int q, r, charPos = 12; 
51        char sign = 0 ; 
52
53        if (i == Integer.MIN_VALUE) return "-2147483648";
54
55        if (i < 0) { 
56           sign = '-' ; 
57           i = -i ; 
58        }
59
60        for (;;) { 
61           q = i/10; ; 
62           r = i-(q*10) ;
63           buf [--charPos] = (char) ((int) '0' + r) ; 
64           i = q ; 
65           if (i == 0) break ; 
66        }
67
68        if (sign != 0) {
69          buf [--charPos] = sign ; 
70        }
71
72        return new String ( buf, charPos, 12 - charPos) ; 
73    }
74
75    /**
76     * Returns a String object representing this Integer's value. The 
77     * value is converted to signed decimal representation and returned 
78     * as a string.
79     *
80     * @return  a string representation of the value of this object in
81     *          base&nbsp;10.
82     */
83     public String toString() {
84         return toString(value);
85     }
86 }
87
88