Merge branch 'master' of https://source.jalview.org/git/jalviewjs.git
[jalviewjs.git] / site / j2s / java / lang / Double.js
1 Clazz.load (["java.lang.Comparable", "$.Number"], "java.lang.Double", null, function () {
2 java.lang.Double = Double = function () {
3 Clazz.instantialize (this, arguments);
4 };
5 Clazz.decorateAsType (Double, "Double", Number, Comparable, null, true);
6 Double.prototype.valueOf = function () { return 0; };
7 Double.toString = Double.prototype.toString = function () {
8         if (arguments.length != 0) {
9                 return "" + arguments[0];
10         } else if (this === Double) {
11                 return "class java.lang.Double"; // Double.class.toString
12         }
13         return "" + this.valueOf ();
14 };
15 Clazz.makeConstructor (Double, 
16 function () {
17 this.valueOf = function () {
18         return 0.0;
19 };
20 });
21 Clazz.makeConstructor (Double, 
22 function (value) {
23 this.valueOf = function () {
24         return value;
25 };
26 }, "Number");
27 Clazz.makeConstructor (Double, 
28 function (s) {
29 var value = Double.parseDouble (s);
30 this.valueOf = function () {
31         return value;
32 };
33 }, "String");
34
35 Double.serialVersionUID = Double.prototype.serialVersionUID = -9172774392245257468;
36 Double.MIN_VALUE = Double.prototype.MIN_VALUE = 4.9e-324;
37 Double.MAX_VALUE = Double.prototype.MAX_VALUE = 1.7976931348623157e+308;
38 Double.NEGATIVE_INFINITY = Number.NEGATIVE_INFINITY;
39 Double.POSITIVE_INFINITY = Number.POSITIVE_INFINITY;
40 Double.NaN = Number.NaN;
41 Double.TYPE = Double.prototype.TYPE = Double;
42
43 Clazz.defineMethod (Double, "isNaN", 
44 function (num) {
45 return isNaN (num);
46 }, "Number");
47 Double.isNaN = Double.prototype.isNaN;
48 Clazz.defineMethod (Double, "isInfinite", 
49 function (num) {
50 return !isFinite (num);
51 }, "Number");
52 Double.isInfinite = Double.prototype.isInfinite;
53
54 Clazz.defineMethod (Double, "parseDouble", 
55 function (s) {
56 if (s == null) {
57 throw  new NumberFormatException ("null");
58 }
59 var doubleVal = parseFloat (s);
60 if(isNaN(doubleVal)){
61 throw  new NumberFormatException ("Not a Number : " + s);
62 }
63 return doubleVal;
64 }, "String");
65 Double.parseDouble = Double.prototype.parseDouble;
66
67 Clazz.defineMethod (Double, "$valueOf", 
68 function (s) {
69 return new Double(this.parseDouble(s));
70 }, "String");
71
72 Clazz.defineMethod (Double, "$valueOf", 
73 function (v) {
74 return new Double(v);
75 }, "Number");
76
77 Double.$valueOf = Double.prototype.$valueOf;
78
79 Clazz.overrideMethod(Double, "equals", 
80 function (s) {
81 if(s == null || ! Clazz.instanceOf(s, Double) ){
82         return false;
83 }
84 return s.valueOf()  == this.valueOf();
85 }, "Object");
86 });
87