File size: 3,675 Bytes
233f6d4 | 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 | Clazz.load (["java.lang.Comparable", "$.Number"], "java.lang.Byte", null, function () {
java.lang.Byte = Byte = function () {
Clazz.instantialize (this, arguments);
};
Clazz.decorateAsType (Byte, "Byte", Number, Comparable, null, true);
Byte.prototype.valueOf = function () { return 0; };
Byte.toString = Byte.prototype.toString = function () {
if (arguments.length != 0) {
return "" + arguments[0];
} else if (this === Byte) {
return "class java.lang.Byte"; // Byte.class.toString
}
return "" + this.valueOf ();
};
Clazz.makeConstructor (Byte,
function () {
this.valueOf = function () {
return 0;
};
});
Clazz.makeConstructor (Byte,
function (value) {
var v = Math.round (value) & 0xffffffff;
this.valueOf = function () {
return v;
};
}, "Number");
Clazz.makeConstructor (Byte,
function (s) {
var value = Byte.parseByte (s, 10);
this.valueOf = function () {
return value;
};
}, "String");
Byte.serialVersionUID = Byte.prototype.serialVersionUID = -7183698231559129828;
Byte.MIN_VALUE = Byte.prototype.MIN_VALUE = -128;
Byte.MAX_VALUE = Byte.prototype.MAX_VALUE = 127;
Byte.SIZE = Byte.prototype.SIZE = 8;
Byte.TYPE = Byte.prototype.TYPE = Byte;
Clazz.defineMethod (Byte, "parseByte",
function (s, radix) {
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");
Byte.parseByte = Byte.prototype.parseByte;
Clazz.defineMethod (Byte, "parseByte",
function (s) {
return Byte.parseByte (s, 10);
}, "String");
Byte.parseByte = Byte.prototype.parseByte;
Clazz.defineMethod (Byte, "$valueOf",
function (s) {
return new Byte(Byte.parseByte (s, 10));
}, "String");
Clazz.defineMethod (Byte, "$valueOf",
function (s) {
return new Byte(s);
}, "Number");
Clazz.defineMethod (Byte, "$valueOf",
function (s, r) {
return new Byte(Byte.parseByte (s, r));
}, "String, Number");
Byte.$valueOf = Byte.prototype.$valueOf;
Clazz.overrideMethod(Byte, "equals",
function (s) {
if(s == null || !Clazz.instanceOf(s, Byte) ){
return false;
}
return s.valueOf() == this.valueOf();
}, "Object");
Byte.toHexString = Byte.prototype.toHexString = function (i) {
return i.toString (16);
};
Byte.toOctalString = Byte.prototype.toOctalString = function (i) {
return i.toString (8);
};
Byte.toBinaryString = Byte.prototype.toBinaryString = function (i) {
return i.toString (2);
};
Byte.decode = Clazz.defineMethod (Byte, "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 = Byte.$valueOf (nm.substring (index), radix);
result = negative ? new Byte (-result.byteValue ()) : result;
} catch (e) {
if (Clazz.instanceOf (e, NumberFormatException)) {
var constant = negative ? String.instantialize ("-" + nm.substring (index)) : nm.substring (index);
result = Byte.$valueOf (constant, radix);
} else {
throw e;
}
}
return result;
}, "~S");
});
|