Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitc80b63f

Browse files
author
zhourenjian
committed
Add more supports about numbers
1 parent41a4321 commitc80b63f

File tree

10 files changed

+551
-4
lines changed

10 files changed

+551
-4
lines changed

‎sources/net.sf.j2s.java.core/src/java/lang/Boolean.js‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ Boolean.prototype.parseBoolean = function(val){
1212

1313
Boolean.$valueOf=Boolean.parseBoolean=Boolean.prototype.parseBoolean;
1414

15-
Boolean.TRUE=Boolean.prototype.TRUE=newBoolean(true);
16-
Boolean.FALSE=Boolean.prototype.FALSE=newBoolean(false);
17-
15+
Boolean.TRUE=Boolean.prototype.TRUE=newBoolean(true);
16+
Boolean.FALSE=Boolean.prototype.FALSE=newBoolean(false);
17+
Boolean.TYPE=Boolean.prototype.TYPE=Boolean;
1818

1919

Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
Clazz.load(["java.lang.Comparable","$.Number"],"java.lang.Byte",null,function(){
2+
java.lang.Byte=Byte=function(){
3+
Clazz.instantialize(this,arguments);
4+
};
5+
Clazz.decorateAsType(Byte,"Byte",Number,Comparable);
6+
Byte.prototype.valueOf=function(){return0;};
7+
Byte.toString=Byte.prototype.toString=function(){
8+
if(arguments.length!=0){
9+
return""+arguments[0];
10+
}
11+
return""+this.valueOf();
12+
};
13+
Clazz.makeConstructor(Byte,
14+
function(){
15+
this.valueOf=function(){
16+
return0;
17+
};
18+
});
19+
Clazz.makeConstructor(Byte,
20+
function(value){
21+
varv=Math.round(value)&0xffffffff;
22+
this.valueOf=function(){
23+
returnv;
24+
};
25+
},"Number");
26+
Clazz.makeConstructor(Byte,
27+
function(s){
28+
varvalue=Byte.parseByte(s,10);
29+
this.valueOf=function(){
30+
returnvalue;
31+
};
32+
},"String");
33+
Byte.serialVersionUID=Byte.prototype.serialVersionUID=-7183698231559129828;
34+
Byte.MIN_VALUE=Byte.prototype.MIN_VALUE=-128;
35+
Byte.MAX_VALUE=Byte.prototype.MAX_VALUE=127;
36+
Byte.SIZE=Byte.prototype.SIZE=8;
37+
Byte.TYPE=Byte.prototype.TYPE=Byte;
38+
39+
Clazz.defineMethod(Byte,"parseByte",
40+
function(s,radix){
41+
if(s==null){
42+
thrownewNumberFormatException("null");
43+
}if(radix<2){
44+
thrownewNumberFormatException("radix "+radix+" less than Character.MIN_RADIX");
45+
}if(radix>36){
46+
thrownewNumberFormatException("radix "+radix+" greater than Character.MAX_RADIX");
47+
}
48+
varinteger=parseInt(s,radix);
49+
if(isNaN(integer)){
50+
thrownewNumberFormatException("Not a Number : "+s);
51+
}
52+
returninteger;
53+
},"String, Number");
54+
Byte.parseByte=Byte.prototype.parseByte;
55+
Clazz.defineMethod(Byte,"parseByte",
56+
function(s){
57+
returnByte.parseByte(s,10);
58+
},"String");
59+
60+
Byte.parseByte=Byte.prototype.parseByte;
61+
62+
Clazz.defineMethod(Byte,"$valueOf",
63+
function(s){
64+
returnnewByte(Byte.parseByte(s,10));
65+
},"String");
66+
67+
Clazz.defineMethod(Byte,"$valueOf",
68+
function(s){
69+
returnnewByte(s);
70+
},"Number");
71+
72+
Clazz.defineMethod(Byte,"$valueOf",
73+
function(s,r){
74+
returnnewByte(Byte.parseByte(s,r));
75+
},"String, Number");
76+
77+
Byte.$valueOf=Byte.prototype.$valueOf;
78+
Clazz.defineMethod(Byte,"equals",
79+
function(s){
80+
if(s==null||!Clazz.instanceOf(s,Byte)){
81+
returnfalse;
82+
}
83+
returns.valueOf()==this.valueOf();
84+
},"Object");
85+
Byte.toHexString=Byte.prototype.toHexString=function(i){
86+
returni.toString(16);
87+
};
88+
Byte.toOctalString=Byte.prototype.toOctalString=function(i){
89+
returni.toString(8);
90+
};
91+
Byte.toBinaryString=Byte.prototype.toBinaryString=function(i){
92+
returni.toString(2);
93+
};
94+
Byte.decode=Clazz.defineMethod(Byte,"decode",
95+
function(nm){
96+
varradix=10;
97+
varindex=0;
98+
varnegative=false;
99+
varresult;
100+
if(nm.startsWith("-")){
101+
negative=true;
102+
index++;
103+
}if(nm.startsWith("0x",index)||nm.startsWith("0X",index)){
104+
index+=2;
105+
radix=16;
106+
}elseif(nm.startsWith("#",index)){
107+
index++;
108+
radix=16;
109+
}elseif(nm.startsWith("0",index)&&nm.length>1+index){
110+
index++;
111+
radix=8;
112+
}if(nm.startsWith("-",index))thrownewNumberFormatException("Negative sign in wrong position");
113+
try{
114+
result=Byte.$valueOf(nm.substring(index),radix);
115+
result=negative ?newByte(-result.byteValue()) :result;
116+
}catch(e){
117+
if(Clazz.instanceOf(e,NumberFormatException)){
118+
varconstant=negative ?String.instantialize("-"+nm.substring(index)) :nm.substring(index);
119+
result=Byte.$valueOf(constant,radix);
120+
}else{
121+
throwe;
122+
}
123+
}
124+
returnresult;
125+
},"~S");
126+
});
127+

‎sources/net.sf.j2s.java.core/src/java/lang/Character.java‎

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,40 @@
5151
* </p>
5252
*
5353
* @since 1.0
54+
*
55+
* @j2sSuffix java.lang.Character.TYPE=java.lang.Character.prototype.TYPE=java.lang.Character;
5456
*/
5557
publicfinalclassCharacterimplementsSerializable,Comparable<Character> {
5658
privatestaticfinallongserialVersionUID =3786198910865385080L;
5759

60+
/**
61+
* The minimum possible Character value.
62+
*/
63+
publicstaticfinalcharMIN_VALUE ='\u0000';
64+
65+
/**
66+
* The maximum possible Character value.
67+
*/
68+
publicstaticfinalcharMAX_VALUE ='\uffff';
69+
70+
/**
71+
* The minimum possible radix used for conversions between Characters and
72+
* integers.
73+
*/
74+
publicstaticfinalintMIN_RADIX =2;
75+
76+
/**
77+
* The maximum possible radix used for conversions between Characters and
78+
* integers.
79+
*/
80+
publicstaticfinalintMAX_RADIX =36;
81+
82+
/**
83+
* The <code>char</code> {@link Class} object.
84+
*/
85+
@SuppressWarnings("unchecked")
86+
publicstaticfinalClass<Character>TYPE =null;
87+
5888
privatefinalcharvalue;
5989

6090
/**
@@ -236,6 +266,64 @@ public static int offsetByCodePoints(char[] chs, int begin, int offset, int end,
236266
return0;
237267
}
238268

269+
/**
270+
* Convenient method to determine the value of character <code>c</code> in
271+
* the supplied radix. The value of <code>radix</code> must be between
272+
* MIN_RADIX and MAX_RADIX.
273+
*
274+
* @param c
275+
* the character
276+
* @param radix
277+
* the radix
278+
* @return if <code>radix</code> lies between {@link #MIN_RADIX} and
279+
* {@link #MAX_RADIX} then the value of the character in the radix,
280+
* otherwise -1.
281+
*/
282+
publicstaticintdigit(charc,intradix) {
283+
if (radix >=MIN_RADIX &&radix <=MAX_RADIX) {
284+
if (c <128) {
285+
// Optimized for ASCII
286+
intresult = -1;
287+
if ('0' <=c &&c <='9') {
288+
result =c -'0';
289+
}elseif ('a' <=c &&c <='z') {
290+
result =c - ('a' -10);
291+
}elseif ('A' <=c &&c <='Z') {
292+
result =c - ('A' -10);
293+
}
294+
returnresult <radix ?result : -1;
295+
}
296+
// int result = BinarySearch.binarySearchRange(digitKeys, c);
297+
// if (result >= 0 && c <= digitValues[result * 2]) {
298+
// int value = (char) (c - digitValues[result * 2 + 1]);
299+
// if (value >= radix) {
300+
// return -1;
301+
// }
302+
// return value;
303+
// }
304+
}
305+
return -1;
306+
}
307+
308+
/**
309+
* Convenient method to determine the value of character
310+
* <code>codePoint</code> in the supplied radix. The value of
311+
* <code>radix</code> must be between MIN_RADIX and MAX_RADIX.
312+
*
313+
* @param codePoint
314+
* the character, including supplementary characters
315+
* @param radix
316+
* the radix
317+
* @return if <code>radix</code> lies between {@link #MIN_RADIX} and
318+
* {@link #MAX_RADIX} then the value of the character in the radix,
319+
* otherwise -1.
320+
* @j2sIgnore
321+
*/
322+
publicstaticintdigit(intcodePoint,intradix) {
323+
//return UCharacter.digit(codePoint, radix);
324+
return -1;
325+
}
326+
239327
/**
240328
* @j2sIgnore
241329
*/

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1404,6 +1404,11 @@ Clazz.instantialize = function (objThis, args) {
14041404
objThis.construct.apply (objThis, args);
14051405
}
14061406
*/
1407+
if(objThisinstanceofNumber){
1408+
objThis.valueOf=function(){
1409+
returnthis;
1410+
};
1411+
}
14071412
varc=objThis.construct;
14081413
if(c!=null){
14091414
if(objThis.con$truct==null){// no need to init fields
@@ -1473,6 +1478,9 @@ Clazz.innerFunctions = {
14731478

14741479
getResourceAsStream :function(name){
14751480
varis=null;
1481+
if(name==null){
1482+
returnis;
1483+
}
14761484
if(java.io.InputStream!=null){
14771485
is=newjava.io.InputStream();
14781486
}else{

‎sources/net.sf.j2s.java.core/src/java/lang/ClassExt.js‎

Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -734,6 +734,127 @@ Thread.currentThread = Thread.prototype.currentThread = function () {
734734
returnthis.J2S_THREAD;
735735
};
736736

737+
/* public */
738+
Clazz.intCast=function(n){// 32bit
739+
varb1=(n&0xff000000)>>24;
740+
varb2=(n&0xff0000)>>16;
741+
varb3=(n&0xff00)>>8;
742+
varb4=n&0xff;
743+
if((b1&0x80)!=0){
744+
return-(((b1&0x7f)<<24)+(b2<<16)+(b3<<8)+b4+1);
745+
}else{
746+
return(b1<<24)+(b2<<16)+(b3<<8)+b4;
747+
}
748+
};
749+
750+
/* public */
751+
Clazz.shortCast=function(s){// 16bit
752+
varb1=(n&0xff00)>>8;
753+
varb2=n&0xff;
754+
if((b1&0x80)!=0){
755+
return-(((b1&0x7f)<<8)+b2+1);
756+
}else{
757+
return(b1<<8)+b4;
758+
}
759+
};
760+
761+
/* public */
762+
Clazz.byteCast=function(b){// 8bit
763+
if((b&0x80)!=0){
764+
return-((b&0x7f)+1);
765+
}else{
766+
returnb&0xff;
767+
}
768+
};
769+
770+
/* public */
771+
Clazz.charCast=function(c){// 8bit
772+
returnString.fromCharCode(c&0xff).charAt(0);
773+
};
774+
775+
/**
776+
* Warning: Unsafe conversion!
777+
*/
778+
/* public */
779+
Clazz.floatCast=function(f){// 32bit
780+
returnf;
781+
};
782+
783+
/*
784+
* Try to fix JavaScript's shift operator defects on long type numbers.
785+
*/
786+
787+
Clazz.longMasks=[];
788+
789+
Clazz.longReverseMasks=[];
790+
791+
Clazz.longBits=[];
792+
793+
(function(){
794+
vararr=[1];
795+
for(vari=1;i<53;i++){
796+
arr[i]=arr[i-1]+arr[i-1];// * 2 or << 1
797+
}
798+
Clazz.longBits=arr;
799+
Clazz.longMasks[52]=arr[52];
800+
for(vari=51;i>=0;i--){
801+
Clazz.longMasks[i]=Clazz.longMasks[i+1]+arr[i];
802+
}
803+
Clazz.longReverseMasks[0]=arr[0];
804+
for(vari=1;i<52;i++){
805+
Clazz.longReverseMasks[i]=Clazz.longReverseMasks[i-1]+arr[i];
806+
}
807+
})();
808+
809+
/* public */
810+
Clazz.longLeftShift=function(l,o){// 64bit
811+
if(o==0)returnl;
812+
if(o>=64)return0;
813+
if(o>52){
814+
error("[Java2Script] Error : JavaScript does not support long shift!");
815+
returnl;
816+
}
817+
if((l&Clazz.longMasks[o-1])!=0){
818+
error("[Java2Script] Error : Such shift operator results in wrong calculation!");
819+
returnl;
820+
}
821+
varhigh=l&Clazz.longMasks[52-32+o];
822+
if(high!=0){
823+
returnhigh*Clazz.longBits[o]+(l&Clazz.longReverseMasks[32-o])<<0;
824+
}else{
825+
returnl<<o;
826+
}
827+
};
828+
829+
/* public */
830+
Clazz.intLeftShift=function(n,o){// 32bit
831+
return(n<<o)&0xffffffff;
832+
};
833+
834+
/* public */
835+
Clazz.longRightShift=function(l,o){// 64bit
836+
if((l&Clazz.longMasks[52-32])!=0){
837+
returnMath.round((l&Clazz.longMasks[52-32])/Clazz.longBits[32-o])+(l&Clazz.longReverseMasks[o])>>o;
838+
}else{
839+
returnl>>o;
840+
}
841+
};
842+
843+
/* public */
844+
Clazz.intRightShift=function(n,o){// 32bit
845+
returnn>>o;// no needs for this shifting wrapper
846+
};
847+
848+
/* public */
849+
Clazz.long0RightShift=function(l,o){// 64bit
850+
returnl>>>o;
851+
};
852+
853+
/* public */
854+
Clazz.int0RightShift=function(n,o){// 64bit
855+
returnn>>>o;// no needs for this shifting wrapper
856+
};
857+
737858
// Compress the common public API method in shorter name
738859
$_L=Clazz.load;$_W=Clazz.declareAnonymous;$_T=Clazz.declareType;$_J=Clazz.declarePackage;$_C=Clazz.decorateAsClass;$_Z=Clazz.instantialize;$_I=Clazz.declareInterface;$_D=Clazz.isClassDefined;$_H=Clazz.pu$h;$_P=Clazz.p0p;$_B=Clazz.prepareCallback;$_N=Clazz.innerTypeInstance;$_K=Clazz.makeConstructor;$_U=Clazz.superCall;$_R=Clazz.superConstructor;$_M=Clazz.defineMethod;$_V=Clazz.overrideMethod;$_S=Clazz.defineStatics;$_E=Clazz.defineEnumConstant;$_F=Clazz.cloneFinals;$_Y=Clazz.prepareFields;$_A=Clazz.newArray;$_O=Clazz.instanceOf;$_G=Clazz.inheritArgs;$_X=Clazz.checkPrivateMethod;$_Q=Clazz.makeFunction;$_s=Clazz.registerSerializableFields;
739860

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp