OSDN Git Service

lejos_NXJ_win32_0_5_0beta.zip
[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 String toString(int i) {
50           synchronized(buf) {
51        int q, r, charPos = 12; 
52        char sign = 0 ; 
53
54        if (i == Integer.MIN_VALUE) return "-2147483648";
55
56        if (i < 0) { 
57           sign = '-' ; 
58           i = -i ; 
59        }
60
61        for (;;) { 
62           q = i/10; ; 
63           r = i-(q*10) ;
64           buf [--charPos] = (char) ((int) '0' + r) ; 
65           i = q ; 
66           if (i == 0) break ; 
67        }
68
69        if (sign != 0) {
70          buf [--charPos] = sign ; 
71        }
72
73        return new String ( buf, charPos, 12 - charPos) ; 
74      }
75    }
76
77    /**
78     * Returns a String object representing this Integer's value. The 
79     * value is converted to signed decimal representation and returned 
80     * as a string.
81     *
82     * @return  a string representation of the value of this object in
83     *          base&nbsp;10.
84     */
85     public String toString() {
86         return toString(value);
87     }
88 }
89
90