Skip to content

Commit 6e9e79f

Browse files
author
sebastigurin
committed
initial support for toHexString, toOctalString and toBinaryString in classes Integer and Long
1 parent bdd5967 commit 6e9e79f

File tree

3 files changed

+38
-16
lines changed

3 files changed

+38
-16
lines changed

sources/net.sf.j2s.java.core/src/java/lang/Class.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1948,7 +1948,10 @@ Clazz.exceptionOf=function(e, clazz) {
19481948
}
19491949
else
19501950
return false;
1951-
};
1951+
};
1952+
1953+
/* sgurin: preserve Number.prototype.toString */
1954+
Number.prototype._numberToString=Number.prototype.toString;
19521955

19531956
Clazz.declarePackage ("java.io");
19541957
//Clazz.declarePackage ("java.lang");

sources/net.sf.j2s.java.core/src/java/lang/Integer.js

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -83,14 +83,17 @@ if(s == null || ! Clazz.instanceOf(s, Integer) ){
8383
}
8484
return s.valueOf() == this.valueOf();
8585
}, "Object");
86-
Integer.toHexString = Integer.prototype.toHexString = function (i) {
87-
return i.toString (16);
86+
Integer.toHexString = Integer.prototype.toHexString = function (d) {
87+
if(d.valueOf)d=d.valueOf();
88+
return d._numberToString(16);
8889
};
89-
Integer.toOctalString = Integer.prototype.toOctalString = function (i) {
90-
return i.toString (8);
90+
Integer.toOctalString = Integer.prototype.toOctalString = function (d) {
91+
if(d.valueOf)d=d.valueOf();
92+
return d._numberToString(8);
9193
};
92-
Integer.toBinaryString = Integer.prototype.toBinaryString = function (i) {
93-
return i.toString (2);
94+
Integer.toBinaryString = Integer.prototype.toBinaryString = function (d) {
95+
if(d.valueOf)d=d.valueOf();
96+
return d._numberToString(2);
9497
};
9598
Integer.decode = Clazz.defineMethod (Integer, "decode",
9699
function (nm) {

sources/net.sf.j2s.java.core/src/java/lang/Long.js

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -83,15 +83,31 @@ if(s == null || !Clazz.instanceOf(s, Long) ){
8383
}
8484
return s.valueOf() == this.valueOf();
8585
}, "Object");
86-
Long.toHexString = Long.prototype.toHexString = function (i) {
87-
return i.toString (16);
88-
};
89-
Long.toOctalString = Long.prototype.toOctalString = function (i) {
90-
return i.toString (8);
91-
};
92-
Long.toBinaryString = Long.prototype.toBinaryString = function (i) {
93-
return i.toString (2);
94-
};
86+
87+
Clazz.defineMethod (Long, "toHexString",
88+
function (d) {
89+
if(d.valueOf)d=d.valueOf();
90+
var r = d._numberToString(16);
91+
return r;
92+
}, "Number");
93+
Long.toHexString = Long.prototype.toHexString;
94+
95+
Clazz.defineMethod (Long, "toOctalString",
96+
function (d) {
97+
if(d.valueOf)d=d.valueOf();
98+
var r = d._numberToString(8);
99+
return r;
100+
}, "Number");
101+
Long.toOctalString = Long.prototype.toOctalString;
102+
103+
Clazz.defineMethod (Long, "toBinaryString",
104+
function (d) {
105+
if(d.valueOf)d=d.valueOf();
106+
var r = d._numberToString(2);
107+
return r;
108+
}, "Number");
109+
Long.toBinaryString = Long.prototype.toBinaryString;
110+
95111
Long.decode = Clazz.defineMethod (Long, "decode",
96112
function (nm) {
97113
var radix = 10;

0 commit comments

Comments
 (0)