4 public Integer(int value) {
8 public Integer(String str) {
9 value=Integer.parseInt(str, 10);
12 public int intValue() {
16 public double doubleValue() {
20 public float floatValue() {
24 public byte[] intToByteArray() {
25 byte[] b = new byte[4];
26 for (int i = 0; i < 4; i++) {
27 int offset = (b.length - 1 - i) * 8;
28 b[i] = (byte) ((value >> offset) & 0xFF);
33 public int byteArrayToInt(byte [] b) {
35 for (int i = 0; i < 4; i++) {
36 int shift = (4 - 1 - i) * 8;
37 value += (b[i] & 0x000000FF) << shift;
43 public int byteArrayToInt(byte [] b) {
45 val = b[0] << 24 + ((b[1] & 0xFF) << 16) + ((b[2] & 0xFF) << 8) + (b[3] & 0xFF);
50 public static int parseInt(String str) {
51 return Integer.parseInt(str, 10);
54 public static int parseInt(String str, int radix) {
58 byte[] chars=str.getBytes();
60 while(chars[start]==' '||chars[start]=='\t')
63 if (chars[start]=='-') {
68 for(int i=start; cont&&i<str.length(); i++) {
73 else if (b>='a'&&b<='z')
75 else if (b>='A'&&b<='Z')
83 value=value*radix+val;
91 public String toString() {
92 return String.valueOf(value);
95 public static String toString(int i) {
96 Integer I = new Integer(i);
100 public int hashCode() {
104 public boolean equals(Object o) {
105 if (o.getType()!=getType())
107 Integer s=(Integer)o;
108 if (s.intValue()!=this.value)
113 public int compareTo(Integer i) {
114 if (value == i.value)
116 // Returns just -1 or 1 on inequality; doing math might overflow.
117 return value > i.value?1:-1;
120 public static int bitCount(int x) {
121 // Successively collapse alternating bit groups into a sum.
122 x = ((x >> 1) & 0x55555555) + (x & 0x55555555);
123 x = ((x >> 2) & 0x33333333) + (x & 0x33333333);
124 x = ((x >> 4) & 0x0f0f0f0f) + (x & 0x0f0f0f0f);
125 x = ((x >> 8) & 0x00ff00ff) + (x & 0x00ff00ff);
126 return ((x >> 16) & 0x0000ffff) + (x & 0x0000ffff);
129 public static int numberOfLeadingZeros(int value) {
130 value |= value >>> 1;
131 value |= value >>> 2;
132 value |= value >>> 4;
133 value |= value >>> 8;
134 value |= value >>> 16;
135 return bitCount(~value);