File: java.lang.Integer

package info (click to toggle)
bock 0.20.2.1
  • links: PTS
  • area: main
  • in suites: woody
  • size: 1,228 kB
  • ctags: 1,370
  • sloc: ansic: 7,367; java: 5,553; yacc: 963; lex: 392; makefile: 243; sh: 90; perl: 42
file content (114 lines) | stat: -rw-r--r-- 3,057 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
// java.lang.Integer
// An implementation of the Java Language Specification section 20.7
// Written by Charles Briscoe-Smith; refer to the file LEGAL for details.

package java.lang;

public final class Integer extends Number {
	public static final int MIN_VALUE = 0x80000000;
	public static final int MAX_VALUE = 0x7fffffff;

	private int myvalue;

	public Integer(int value) {
		myvalue=value;
	}
//	public Integer(String s) throws NumberFormatException {
//		myvalue=parseInt(s);
//	}

	public String toString() {
		return toString(myvalue);
	}
	public boolean equals(Object obj) {
		try {
			return ((Integer) obj).myvalue==myvalue;
		} catch (NullPointerException e) {
			return false;
		} catch (ClassCastException e) {
			return false;
		}
	}
	public int hashCode() {
		return myvalue;
	}

	public int intValue() {
		return myvalue;
	}
	public long longValue() {
		return (long) myvalue;
	}
	public float floatValue() {
		return (float) myvalue;
	}
	public double doubleValue() {
		return (double) myvalue;
	}

	private static String digit="0123456789abcdefghijklmnopqrstuvwxyz";

	public static String toString(int i) {
		return toString(i, 10);
	}
	public static String toString(int i, int radix) {
		if (radix<Character.MIN_RADIX || radix>Character.MAX_RADIX)
			radix=10;
		if (i==0) return "0";
		if (i<0) return "-"+toString(-i, radix);
		if (i<radix) return new Character(digit.charAt(i)).toString();
		return toString(i/radix, radix)+digit.charAt(i%radix);
	}
	public static String toHexString(int i) {
		if (i>=0 && i<16) return new Character(digit.charAt(i)).toString();
		return toHexString(i>>>4) + digit.charAt(i&15);
	}
	public static String toOctalString(int i) {
		if (i>=0 && i<8) return new Character(digit.charAt(i)).toString();
		return toHexString(i>>>3) + digit.charAt(i&7);
	}
	public static String toBinaryString(int i) {
		if (i>=0 && i<2) return new Character(digit.charAt(i)).toString();
		return toHexString(i>>>1) + digit.charAt(i&1);
	}

	public static int parseInt(String s) throws NumberFormatException
	{
		return parseInt(s, 10);
	}

	public static int parseInt(String s, int radix)
			throws NumberFormatException
	{
		if (s==null || s.length()==0)
			throw new NumberFormatException();
		int pos=0;
		boolean neg=false;
		if (s.charAt(0)=='-') {
			neg=true;
			pos++;
		}
		if (pos==s.length())
			throw new NumberFormatException();
		int val=0;
		while (pos<s.length()) {
			int digit=Character.digit(s.charAt(pos), radix);
			if (digit==-1)
				throw new NumberFormatException();
			if (neg ? (-val*radix-digit)/radix != -val
			        : (val*radix+digit)/radix != val)
				throw new NumberFormatException();
			val=val*radix+digit;
			pos++;
		}
		return neg ? -val : val;
	}

//	public static Integer valueOf(String s) throws NumberFormatException;
//	public static Integer valueOf(String s, int radix)
//			throws NumberFormatException;

//	public static Integer getInteger(String nm);
//	public static Integer getInteger(String nm, int val);
//	public static Integer getInteger(String nm, Integer val);
}