forked from BobHanson/java2script
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathShort.js0
More file actions
162 lines (154 loc) · 4.14 KB
/
Copy pathShort.js0
File metadata and controls
162 lines (154 loc) · 4.14 KB
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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
// DEPRECATED -- SEE J2SSwingJS.js
Clazz.load (["java.lang.Comparable", "$.Number"], "java.lang.Short", null, function () {
java.lang.Short = Short = function () {
Clazz.instantialize (this, arguments);
};
Clazz.decorateAsType (Short, "Short", Number, Comparable, null, true);
Short.prototype.valueOf = function () { return 0; };
Short.toString = Short.prototype.toString = function () {
if (arguments.length != 0) {
return "" + arguments[0];
} else if (this === Short) {
return "class java.lang.Short"; // Short.class.toString
}
return "" + this.valueOf ();
};
/*
Clazz.makeConstructor (Short,
function () {
this.valueOf = function () {
return 0;
};
});
Clazz.makeConstructor (Short,
function (value) {
var v = Math.round (value) & 0xffffffff;
this.valueOf = function () {
return v;
};
}, "Number");
Clazz.makeConstructor (Short,
function (s) {
var value = Short.parseShort (s, 10);
this.valueOf = function () {
return value;
};
}, "String");
// */
Clazz.makeConstructor (Short,
function (s) {
var v = 0;
if (arguments.length > 0) {
if (typeof s == "string") {
v = Short.parseShort (s, 10);
} else {
v = s;
}
}
this.valueOf = function () {
return v;
};
}, "Object");
Short.serialVersionUID = Short.prototype.serialVersionUID = 7515723908773894738;
Short.MIN_VALUE = Short.prototype.MIN_VALUE = -32768;
Short.MAX_VALUE = Short.prototype.MAX_VALUE = 32767;
Short.TYPE = Short.prototype.TYPE = Short;
Clazz.defineMethod (Short, "parseShort",
function (s, radix) {
if (arguments.length < 2 || radix == null) {
radix = 10;
}
if (s == null) {
throw new NumberFormatException ("null");
}if (radix < 2) {
throw new NumberFormatException ("radix " + radix + " less than Character.MIN_RADIX");
}if (radix > 36) {
throw new NumberFormatException ("radix " + radix + " greater than Character.MAX_RADIX");
}
var integer = parseInt (s, radix);
if(isNaN(integer)){
throw new NumberFormatException ("Not a Number : " + s);
}
return integer;
}, "String, Number");
/*
Short.parseShort = Short.prototype.parseShort;
Clazz.defineMethod (Short, "parseShort",
function (s) {
return Short.parseShort (s, 10);
}, "String");
// */
Short.parseShort = Short.prototype.parseShort;
/*
Clazz.defineMethod (Short, "$valueOf",
function (s) {
return new Short(Short.parseShort (s, 10));
}, "String");
Clazz.defineMethod (Short, "$valueOf",
function (s) {
return new Short(s);
}, "Number");
Clazz.defineMethod (Short, "$valueOf",
function (s, r) {
return new Short(Short.parseShort (s, r));
}, "String, Number");
Short.$valueOf = Short.prototype.$valueOf;
// */
Short.$valueOf = Short.prototype.$valueOf = function (s, r) {
if (arguments.length == 2) { // String, Number
return new Short(Short.parseShort (s, r));
} else if (typeof s == "string") { // String
return new Short(Short.parseShort (s, 10));
} else { // Number
return new Short(s);
}
};
Clazz.overrideMethod (Short, "equals",
function (s) {
if(s == null || !Clazz.instanceOf(s, Short) ){
return false;
}
return s.valueOf() == this.valueOf();
}, "Object");
Short.toHexString = Short.prototype.toHexString = function (i) {
return i.toString (16);
};
Short.toOctalString = Short.prototype.toOctalString = function (i) {
return i.toString (8);
};
Short.toBinaryString = Short.prototype.toBinaryString = function (i) {
return i.toString (2);
};
Short.decode = Clazz.defineMethod (Short, "decode",
function (nm) {
var radix = 10;
var index = 0;
var negative = false;
var result;
if (nm.startsWith ("-")) {
negative = true;
index++;
}if (nm.startsWith ("0x", index) || nm.startsWith ("0X", index)) {
index += 2;
radix = 16;
} else if (nm.startsWith ("#", index)) {
index++;
radix = 16;
} else if (nm.startsWith ("0", index) && nm.length > 1 + index) {
index++;
radix = 8;
}if (nm.startsWith ("-", index)) throw new NumberFormatException ("Negative sign in wrong position");
try {
result = Short.$valueOf (nm.substring (index), radix);
result = negative ? new Short (-result.shortValue ()) : result;
} catch (e) {
if (Clazz.instanceOf (e, NumberFormatException)) {
var constant = negative ? String.instantialize ("-" + nm.substring (index)) : nm.substring (index);
result = Short.$valueOf (constant, radix);
} else {
throw e;
}
}
return result;
}, "~S");
});