diff --git a/sources/net.sf.j2s.core/dist/swingjs/SwingJS-site.zip b/sources/net.sf.j2s.core/dist/swingjs/SwingJS-site.zip index 08b1c3366..871b9d25d 100644 Binary files a/sources/net.sf.j2s.core/dist/swingjs/SwingJS-site.zip and b/sources/net.sf.j2s.core/dist/swingjs/SwingJS-site.zip differ diff --git a/sources/net.sf.j2s.core/dist/swingjs/j2s.core.jar b/sources/net.sf.j2s.core/dist/swingjs/j2s.core.jar index e7c60f269..e6f92de1b 100644 Binary files a/sources/net.sf.j2s.core/dist/swingjs/j2s.core.jar and b/sources/net.sf.j2s.core/dist/swingjs/j2s.core.jar differ diff --git a/sources/net.sf.j2s.core/dist/swingjs/timestamp b/sources/net.sf.j2s.core/dist/swingjs/timestamp index c1bb5f603..b6ad9d051 100644 --- a/sources/net.sf.j2s.core/dist/swingjs/timestamp +++ b/sources/net.sf.j2s.core/dist/swingjs/timestamp @@ -1 +1 @@ -20240114215407 +20240225103130 diff --git a/sources/net.sf.j2s.core/dist/swingjs/ver/5.0.1/SwingJS-site.zip b/sources/net.sf.j2s.core/dist/swingjs/ver/5.0.1/SwingJS-site.zip index 1d0251882..871b9d25d 100644 Binary files a/sources/net.sf.j2s.core/dist/swingjs/ver/5.0.1/SwingJS-site.zip and b/sources/net.sf.j2s.core/dist/swingjs/ver/5.0.1/SwingJS-site.zip differ diff --git a/sources/net.sf.j2s.core/dist/swingjs/ver/5.0.1/timestamp b/sources/net.sf.j2s.core/dist/swingjs/ver/5.0.1/timestamp index c1bb5f603..b6ad9d051 100644 --- a/sources/net.sf.j2s.core/dist/swingjs/ver/5.0.1/timestamp +++ b/sources/net.sf.j2s.core/dist/swingjs/ver/5.0.1/timestamp @@ -1 +1 @@ -20240114215407 +20240225103130 diff --git a/sources/net.sf.j2s.core/src/j2s/swingjs/Java2ScriptVisitor.java b/sources/net.sf.j2s.core/src/j2s/swingjs/Java2ScriptVisitor.java index d701f0f3d..0874ed417 100644 --- a/sources/net.sf.j2s.core/src/j2s/swingjs/Java2ScriptVisitor.java +++ b/sources/net.sf.j2s.core/src/j2s/swingjs/Java2ScriptVisitor.java @@ -31,6 +31,7 @@ // TODO: superclass inheritance for JAXB XmlAccessorType // TODO: Transpiler bug allows static String name, but JavaScript function().name is read-only and will be "clazz" +//BH 2024.02.22 -- 3.3.1-v7 fixes long extension issue causing MutableBitInteger to miscalculate subtraction(no change in version #) //BH 2023.03.29 -- 3.3.1-v7 fixes outer static method call from within lambda expression. //BH 2023.02.09 -- 3.3.1.v6 fixes j2s.excluded.paths needing /src/xxxx //BH 2022.06.27 -- 3.3.1-v5 fixes missing method annotations @@ -4313,11 +4314,10 @@ && boxType(exp) == NO_BOX) { private void addExtendedOperands(List extendedOperands, String op, char pre, char post, boolean isToString, boolean isLongCall) { buffer.append(' '); + if (isLongCall) + op = ","; for (Iterator iter = extendedOperands.iterator(); iter.hasNext();) { Expression exp = (Expression) iter.next(); - // op may be int for a while, but after that it changes to long - if (isLongCall && exp.resolveTypeBinding().getName().equals("long")) - op = ","; buffer.append(op); buffer.append(pre); addOperand(exp, isToString); diff --git a/sources/net.sf.j2s.java.core/dist/SwingJS-site.zip b/sources/net.sf.j2s.java.core/dist/SwingJS-site.zip index 35ba2d10d..871b9d25d 100644 Binary files a/sources/net.sf.j2s.java.core/dist/SwingJS-site.zip and b/sources/net.sf.j2s.java.core/dist/SwingJS-site.zip differ diff --git a/sources/net.sf.j2s.java.core/dist_to_jsmol/Jmol-j2s-site.zip b/sources/net.sf.j2s.java.core/dist_to_jsmol/Jmol-j2s-site.zip index 6f3d52612..1b3a6c9ce 100644 Binary files a/sources/net.sf.j2s.java.core/dist_to_jsmol/Jmol-j2s-site.zip and b/sources/net.sf.j2s.java.core/dist_to_jsmol/Jmol-j2s-site.zip differ diff --git a/sources/net.sf.j2s.java.core/site-resources/test-raf.txt b/sources/net.sf.j2s.java.core/site-resources/test-raf.txt deleted file mode 100644 index 7c9353e5e..000000000 --- a/sources/net.sf.j2s.java.core/site-resources/test-raf.txt +++ /dev/null @@ -1,2 +0,0 @@ -this is a test -it is a RandomAccessFile diff --git a/sources/net.sf.j2s.java.core/site-resources_4.2/jsmol/js/j2sjmol.js b/sources/net.sf.j2s.java.core/site-resources_4.2/jsmol/js/j2sjmol.js index e7018008b..b0dc902ee 100644 --- a/sources/net.sf.j2s.java.core/site-resources_4.2/jsmol/js/j2sjmol.js +++ b/sources/net.sf.j2s.java.core/site-resources_4.2/jsmol/js/j2sjmol.js @@ -894,7 +894,7 @@ Clazz.defineMethod = function (clazzThis, funName, funBody, funParams) { if (!f$.stacks || f$.claxxReference !== clazzThis) { //Generate a new delegating method for the class var id = ++SAEMid; - console.log("SAEM " + clazzThis.__CLASS_NAME__ + "." + funName); + //console.log("SAEM " + clazzThis.__CLASS_NAME__ + "." + funName); var delegate = function () { return searchAndExecuteMethod(id, this, arguments.callee.claxxReference, arguments.callee.methodName, arguments); }; diff --git a/sources/net.sf.j2s.java.core/src/java/math/MutableBigInteger.java b/sources/net.sf.j2s.java.core/src/java/math/MutableBigInteger.java index 09279ae2a..2f33a5534 100644 --- a/sources/net.sf.j2s.java.core/src/java/math/MutableBigInteger.java +++ b/sources/net.sf.j2s.java.core/src/java/math/MutableBigInteger.java @@ -1,4 +1,6 @@ /* + * 2024.02.21 BH modified for SwingJS with a few (more!) (x + 0x80000000)|0 adjustments + * * Copyright (c) 1999, 2013, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * @@ -25,7 +27,7 @@ package java.math; -/** +/** * A class used to represent multiprecision integers that makes efficient * use of allocated space by allowing a number to occupy only part of * an array so that the arrays do not have to be reallocated as often. @@ -294,8 +296,8 @@ private int compareShifted(MutableBigInteger b, int ints) { // comparison. int[] bval = b.value; for (int i = offset, j = b.offset; i < alen + offset; i++, j++) { - int b1 = value[i] + 0x80000000; - int b2 = bval[j] + 0x80000000; + int b1 = (value[i] + 0x80000000)| 0; + int b2 = (bval[j] + 0x80000000)| 0; if (b1 < b2) return -1; if (b1 > b2) @@ -339,7 +341,7 @@ final int compareHalf(MutableBigInteger b) { long v = val[i++] & LONG_MASK; if (v != hb) return v < hb ? -1 : 1; - carry = (bv & 1) << 31; // carray will be either 0x80000000 or 0 + carry = ((bv & 1) << 31)|0; // carray will be either 0x80000000 or 0 } return carry == 0 ? 0 : -1; } @@ -1131,7 +1133,6 @@ int divideOneWord(int divisor, MutableBigInteger quotient) { quotient.value[intLen - xlen] = q; remLong = rem & LONG_MASK; } - quotient.normalize(); // Unnormalize if (shift > 0) @@ -1362,8 +1363,7 @@ private MutableBigInteger divide3n2n(MutableBigInteger b, MutableBigInteger quot if (compareShifted(b, n) < 0) { // step 3a: if a1=b1, let quotient=beta^n-1 and r=a12-b1*2^n+b1 @@ -1378,7 +1378,7 @@ private MutableBigInteger divide3n2n(MutableBigInteger b, MutableBigInteger quot d.leftShift(32 * n); d.subtract(new MutableBigInteger(b2)); } - + // step 5: r = r*beta^n + a3 - d (paper says a4) // However, don't subtract d until after the while loop so r doesn't become negative r.leftShift(32 * n); @@ -1548,13 +1548,13 @@ private MutableBigInteger divideMagnitude(MutableBigInteger div, int qrem = 0; boolean skipCorrection = false; int nh = rem.value[j+rem.offset]; - int nh2 = nh + 0x80000000; + int nh2 = (nh + 0x80000000)| 0; int nm = rem.value[j+1+rem.offset]; if (nh == dh) { qhat = ~0; qrem = nh + nm; - skipCorrection = qrem + 0x80000000 < nh2; + skipCorrection = ((qrem + 0x80000000)| 0) < nh2; } else { long nChunk = (((long)nh) << 32) | (nm & LONG_MASK); if (nChunk >= 0) { @@ -1607,13 +1607,13 @@ private MutableBigInteger divideMagnitude(MutableBigInteger div, int qrem = 0; boolean skipCorrection = false; int nh = rem.value[limit - 1 + rem.offset]; - int nh2 = nh + 0x80000000; + int nh2 = (nh + 0x80000000)|0; int nm = rem.value[limit + rem.offset]; if (nh == dh) { qhat = ~0; qrem = nh + nm; - skipCorrection = qrem + 0x80000000 < nh2; + skipCorrection = ((qrem + 0x80000000)|0) < nh2; } else { long nChunk = (((long) nh) << 32) | (nm & LONG_MASK); if (nChunk >= 0) { @@ -1653,7 +1653,7 @@ private MutableBigInteger divideMagnitude(MutableBigInteger div, borrow = mulsubBorrow(rem.value, divisor, qhat, dlen, limit - 1 + rem.offset); // D5 Test remainder - if (borrow + 0x80000000 > nh2) { + if (((borrow + 0x80000000)|0) > nh2) { // D6 Add back if(needRemainder) divadd(divisor, rem.value, limit - 1 + 1 + rem.offset); @@ -1723,13 +1723,13 @@ private MutableBigInteger divideLongMagnitude(long ldivisor, MutableBigInteger q int qrem = 0; boolean skipCorrection = false; int nh = rem.value[j + rem.offset]; - int nh2 = nh + 0x80000000; + int nh2 = (nh + 0x80000000)|0; int nm = rem.value[j + 1 + rem.offset]; if (nh == dh) { qhat = ~0; qrem = nh + nm; - skipCorrection = qrem + 0x80000000 < nh2; + skipCorrection = ((qrem + 0x80000000)|0) < nh2; } else { long nChunk = (((long) nh) << 32) | (nm & LONG_MASK); if (nChunk >= 0) { @@ -1767,7 +1767,7 @@ private MutableBigInteger divideLongMagnitude(long ldivisor, MutableBigInteger q int borrow = mulsubLong(rem.value, dh, dl, qhat, j + rem.offset); // D5 Test remainder - if (borrow + 0x80000000 > nh2) { + if (((borrow + 0x80000000)|0) > nh2) { // D6 Add back divaddLong(dh,dl, rem.value, j + 1 + rem.offset); qhat--; @@ -1963,7 +1963,7 @@ static int binaryGcd(int a, int b) { int t = (aZeros < bZeros ? aZeros : bZeros); while (a != b) { - if ((a+0x80000000) > (b+0x80000000)) { // a > b as unsigned + if (((a + 0x80000000)|0) > ((b + 0x80000000)|0)) { // a > b as unsigned a -= b; a >>>= Integer.numberOfTrailingZeros(a); } else { @@ -2246,4 +2246,20 @@ MutableBigInteger euclidModInverse(int k) { mod.subtract(t1); return mod; } + +// static { +// int a = 100; +// int b = a + 0x80000000; +// System.out.println(b); +// System.out.println((a + 0x80000000) | 0); +// System.out.println(a + 0x80000000L); // NOT in Java +// System.out.println((int) (a + 0x80000000L)); +// a = -100; +// b = a + 0x80000000; +// System.out.println("?"); +// System.out.println(b); //NOT in JS +// System.out.println((a + 0x80000000) | 0); +// System.out.println(a + 0x80000000L); +// System.out.println((int) (a + 0x80000000L)); +// } } diff --git a/sources/net.sf.j2s.java.core/src/java/util/Hashtable.java b/sources/net.sf.j2s.java.core/src/java/util/Hashtable.java index 66d5f8091..359d77334 100644 --- a/sources/net.sf.j2s.java.core/src/java/util/Hashtable.java +++ b/sources/net.sf.j2s.java.core/src/java/util/Hashtable.java @@ -1893,7 +1893,10 @@ public T nextElement() { @Override public V setValue(V value) { - return Hashtable.this.put(getKey(), value); + int m = modCount; + V v = put(getKey(), value); + modCount = m; + return v; } }; } diff --git a/sources/net.sf.j2s.java.core/src/javajs/util/A4d.java b/sources/net.sf.j2s.java.core/src/javajs/util/A4d.java index afd0abace..cb2852a2d 100644 --- a/sources/net.sf.j2s.java.core/src/javajs/util/A4d.java +++ b/sources/net.sf.j2s.java.core/src/javajs/util/A4d.java @@ -35,26 +35,7 @@ conforming to the Java(TM) 3D API specification by Sun Microsystems. * for unique constructor and method names * for the optimization of compiled JavaScript using Java2Script */ -public class A4d implements JSONEncodable, Serializable { - - /* - * I assumed that the length of the axis vector is not significant. - */ - - /** - * The x coordinate. - */ - public double x; - - /** - * The y coordinate. - */ - public double y; - - /** - * The z coordinate. - */ - public double z; +public class A4d extends P3d { /** * The angle. diff --git a/sources/net.sf.j2s.java.core/src/javajs/util/MessagePackReader.java b/sources/net.sf.j2s.java.core/src/javajs/util/MessagePackReader.java index 1ff564cb9..1f1b1a02b 100644 --- a/sources/net.sf.j2s.java.core/src/javajs/util/MessagePackReader.java +++ b/sources/net.sf.j2s.java.core/src/javajs/util/MessagePackReader.java @@ -181,9 +181,9 @@ public Object getNext(Object array, int pt) throws Exception { if (array == null) { switch (b) { case FLOAT32: - return Float.valueOf(doc.readFloat()); + return Double.valueOf(doc.readFloat()); case FLOAT64: - return Float.valueOf((float) doc.readDouble()); + return Double.valueOf(doc.readDouble()); case UINT8: return Integer.valueOf(doc.readUInt8()); case UINT16: @@ -203,17 +203,17 @@ public Object getNext(Object array, int pt) throws Exception { case STR8: return doc.readString(doc.readUInt8()); case STR16: - return doc.readString(doc.readShort()); + return doc.readString(doc.readUnsignedShort()); case STR32: return doc.readString(doc.readInt()); } } else { switch (b) { case FLOAT32: - ((float[]) array)[pt] = doc.readFloat(); + ((double[]) array)[pt] = doc.readFloat(); break; case FLOAT64: - ((float[]) array)[pt] = (float) doc.readDouble(); + ((double[]) array)[pt] = doc.readDouble(); break; case UINT8: ((int[]) array)[pt] = doc.readUInt8(); @@ -243,10 +243,10 @@ public Object getNext(Object array, int pt) throws Exception { ((String[]) array)[pt] = doc.readString(doc.readUInt8()); break; case STR16: - ((String[]) array)[pt] = doc.readString(doc.readShort()); + ((String[]) array)[pt] = doc.readString(doc.readUnsignedShort()); break; case STR32: - ((String[]) array)[pt] = doc.readString(doc.readInt()); + ((String[]) array)[pt] = doc.readString(doc.readInt()); // technically shoild be unsigned int break; } } @@ -267,9 +267,9 @@ private Object getArray(int n) throws Exception { int[] a = new int[n]; a[0] = ((Integer) v).intValue(); v = a; - } else if (v instanceof Float) { - float[] a = new float[n]; - a[0] = ((Float) v).floatValue(); + } else if (v instanceof Number) { + double[] a = new double[n]; + a[0] = ((Number) v).doubleValue(); v = a; } else if (v instanceof String) { String[] a = new String[n]; @@ -296,8 +296,6 @@ private Object getMap(int n) throws Exception { Map map = new Hashtable(); for (int i = 0; i < n; i++) { String key = getNext(null, 0).toString(); - //Logger.info(key); - Object value = getNext(null, 0); if (value == null) { //Logger.info("null value for " + key); @@ -366,10 +364,10 @@ public static Object decode(byte[] b) { * @param divisor * @return array of floats */ - public static float[] getFloats(byte[] b, int n, float divisor) { + public static double[] getFloats(byte[] b, int n, float divisor) { if (b == null) return null; - float[] a = new float[n]; + double[] a = new double[n]; try { switch ((b.length - 12) / n) { case 2: @@ -522,10 +520,10 @@ public static int[] rldecode32Delta(byte[] b, int n) { * @param divisor * @return array of floats */ - public static float[] rldecodef(byte[] b, int n, float divisor) { + public static double[] rldecodef(byte[] b, int n, float divisor) { if (b == null) return null; - float[] ret = new float[n]; + double[] ret = new double[n]; for (int i = 0, pt = 3; i < n;) { int val = BC.bytesToInt(b, (pt++) << 2, true); for (int j = BC.bytesToInt(b, (pt++) << 2, true); --j >= 0;) @@ -545,10 +543,10 @@ public static float[] rldecodef(byte[] b, int n, float divisor) { * @param divisor * @return array of floats */ - public static float[] unpack16Deltaf(byte[] b, int n, float divisor) { + public static double[] unpack16Deltaf(byte[] b, int n, float divisor) { if (b == null) return null; - float[] ret = new float[n]; + double[] ret = new double[n]; for (int i = 0, pt = 6, val = 0, buf = 0; i < n;) { int diff = BC.bytesToShort(b, (pt++) << 1, true); if (diff == Short.MAX_VALUE || diff == Short.MIN_VALUE) { @@ -575,10 +573,10 @@ public static float[] unpack16Deltaf(byte[] b, int n, float divisor) { * @param divisor * @return array of floats */ - public static float[] unpackf(byte[] b, int nBytes, int n, float divisor) { + public static double[] unpackf(byte[] b, int nBytes, int n, float divisor) { if (b == null) return null; - float[] ret = new float[n]; + double[] ret = new double[n]; switch (nBytes) { case 1: for (int i = 0, pt = 12, offset = 0; i < n;) { diff --git a/sources/net.sf.j2s.java.core/src/test/Test_BigDec.java b/sources/net.sf.j2s.java.core/src/test/Test_BigDec.java index 5b8c4bacc..5f56b77a5 100644 --- a/sources/net.sf.j2s.java.core/src/test/Test_BigDec.java +++ b/sources/net.sf.j2s.java.core/src/test/Test_BigDec.java @@ -1,8 +1,8 @@ package test; -import test.math.BigDecimal; +import java.math.BigDecimal; -import test.math.MathContext; +import java.math.MathContext; //import test.math.BigInteger; //import test.math.MutableBigInteger; //import java.util.GregorianCalendar; @@ -12,7 +12,33 @@ public class Test_BigDec extends Test_ { public static void main(String[] args) { + + int precision = 1000; + + + BigDecimal factor1 = new BigDecimal("1"); + factor1 = factor1.setScale(precision); + BigDecimal five = new BigDecimal("5"); + five = five.setScale(precision); + + factor1 = factor1.divide(five, BigDecimal.ROUND_FLOOR); + System.out.println(chopText(factor1.toString())); + assert(factor1.toString().equals("0.2000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000")); + + + factor1 = new BigDecimal("1"); + BigDecimal di = factor1.divideToIntegralValue(five); + System.out.println(di); + assert(di.toString().equals("0E+1000")); + + BigDecimal[] dr = factor1.divideAndRemainder(five); + System.out.println(dr[0]); + assert(dr[0].toString().equals("0E+1000")); + System.out.println(dr[1]); + assert(dr[1].toString().equals("1")); + + testBDDiv(); testBDMul(); @@ -20,6 +46,17 @@ public static void main(String[] args) { } + private static String chopText(String s) { + int nd = 50; + String c = ""; + int n = s.length() / nd; + int p = 0; + for (int i = 0; i < n; i++) + c += s.substring(i*nd, p = (i+1)*nd) + "\n"; + s = c + s.substring(p); + return s; + } + // failing testBDDiv(); diff --git a/sources/net.sf.j2s.java.core/src/test/Test_Long.java b/sources/net.sf.j2s.java.core/src/test/Test_Long.java index c32d17ffd..1e1998ce2 100644 --- a/sources/net.sf.j2s.java.core/src/test/Test_Long.java +++ b/sources/net.sf.j2s.java.core/src/test/Test_Long.java @@ -30,6 +30,82 @@ public class Test_Long extends Test_ { public static void main(String[] args) { + long m1 = -1L; + long m2 = -2L; + long p2 = 2L; + assert(Long.compare(m1, m2) == 1); + assert(Long.compare(m2, m1) == -1); + assert(Long.compareUnsigned(m1, m2) == 1); + assert(Long.compareUnsigned(m2, m1) == -1); + assert(Long.compareUnsigned(m1, p2) == 1); + assert(Long.compareUnsigned(p2, m1) == -1); + System.out.println("Long.compareUnsigned OK"); + + long a = 0x11111111111001L; + long b = 0x11111111100000L; + + long c = -(int) (a-b) + a - b; + System.out.println(c); + assert(c == 0); + long e = a - b; + System.out.println("a-b=" + (a-b)); + assert(e == 69633); + + + // next two fail to wrap second operator + + a = 10; + b = 12; + + c = a - b - (int) (a-b); + // var c=Long.$sub(a,b - Long.$ival((Long.$sub(a,b))) ); + System.out.println(c); + assert(c == 0); + + e = a - b - 1; + System.out.println("10-12-1=" + e ); + assert(e == -3); + // var e=Long.$sub(a,b-1); + // gives -4 ?? + + // something wrong here + a = 10; + b = 3; + c = 12; + + a = 0x11111111111001L; + b = 0x11111111100000L; + + c = -(int) (a-b) + a - b; + + long d = a + b - (int) (a-b) - c; // 13 - 7 - 12 == -6 + // var d=Long.$sub( + // Long.$sub( + // Long.$add(a,b), + // Long.$ival((Long.$sub(a,b))) + // ), + // c + // ); + System.out.println(d); + // gives 9607679204777982 + assert(d == 9607679204917248L); + + // something wrong here + a = 10; + b = 3; + c = 12; + + d = a + b - (int) (a-b) - c; // 13 - 7 - 12 == -6 + // var d=Long.$sub( + // Long.$sub( + // Long.$add(a,b), + // Long.$ival((Long.$sub(a,b))) + // ), + // c + // ); + System.out.println(d); + // gives 9607679204777982 + assert(d == -6); long j = Long.parseLong("2"), k = 10, l = 1, m = 12; Long J = Long.valueOf(j); @@ -390,6 +466,10 @@ private static void testExtended(long j, long k, long l, long m) { m = 12; j = k + l + l; assert(j == 12); + + j = k - l - m; + assert(j == -3); + j = k | l | 0xFL; assert(j == 15); m = 2; diff --git a/sources/net.sf.j2s.java.core/src/test/Test_String.java b/sources/net.sf.j2s.java.core/src/test/Test_String.java index b39b04ace..59e0e156e 100644 --- a/sources/net.sf.j2s.java.core/src/test/Test_String.java +++ b/sources/net.sf.j2s.java.core/src/test/Test_String.java @@ -2,6 +2,7 @@ import java.io.UnsupportedEncodingException; import java.nio.CharBuffer; +import java.util.HashMap; import javajs.util.Rdr; import javajs.util.SB; @@ -12,6 +13,10 @@ public static void main(String[] args) { String s, sb; byte[] b; + HashMap map = new HashMap(); + map.put("test", "value"); + System.out.println("test=" + map.get("test")); + sb = new String(new byte[] { 97, 98, 99 }); System.out.println(sb); assert (sb.equals("abc")); diff --git a/sources/net.sf.j2s.java.core/src/test/math/MutableBigInteger.java b/sources/net.sf.j2s.java.core/src/test/math/MutableBigInteger.java index f32053da1..65e9a3e90 100644 --- a/sources/net.sf.j2s.java.core/src/test/math/MutableBigInteger.java +++ b/sources/net.sf.j2s.java.core/src/test/math/MutableBigInteger.java @@ -294,8 +294,8 @@ private int compareShifted(MutableBigInteger b, int ints) { // comparison. int[] bval = b.value; for (int i = offset, j = b.offset; i < alen + offset; i++, j++) { - int b1 = value[i] + 0x80000000; - int b2 = bval[j] + 0x80000000; + int b1 = (value[i] + 0x80000000)|0; + int b2 = (bval[j] + 0x80000000)|0; if (b1 < b2) return -1; if (b1 > b2) @@ -889,9 +889,11 @@ void addDisjoint(MutableBigInteger addend, int n) { for (int i=rstart+1-y+len; i < rstart+1; i++) result[i] = 0; - value = result; intLen = resultLen; offset = result.length - resultLen; + + value = result; + } /** @@ -939,18 +941,17 @@ int subtract(MutableBigInteger b) { // Subtract common parts of both numbers while (y > 0) { x--; y--; - - diff = (a.value[x+a.offset] & LONG_MASK) - - (b.value[y+b.offset] & LONG_MASK) - ((int)-(diff>>32)); + // 2024.02.22 BH long-long-int fails, now (long-long)-int + diff = ((a.value[x+a.offset] & LONG_MASK) + - (b.value[y+b.offset] & LONG_MASK)) - (int)-(diff>>32); result[rstart--] = (int)diff; } - // Subtract remainder of longer number + // Subtract remainder of longer number while (x > 0) { x--; - diff = (a.value[x+a.offset] & LONG_MASK) - ((int)-(diff>>32)); + diff = (a.value[x+a.offset] & LONG_MASK) - (int)-(diff>>32); result[rstart--] = (int)diff; } - value = result; intLen = resultLen; offset = value.length - resultLen; @@ -1261,6 +1262,8 @@ MutableBigInteger divideAndRemainderBurnikelZiegler(MutableBigInteger b, Mutable int n = j * m; // step 2b: block length in 32-bit units long n32 = 32L * n; // block length in bits int sigma = (int) Math.max(0, n32 - b.bitLength()); // step 3: sigma = max{T | (2^T)*B < beta^n} + + MutableBigInteger bShifted = new MutableBigInteger(b); bShifted.safeLeftShift(sigma); // step 4a: shift b so its length is a multiple of n MutableBigInteger aShifted = new MutableBigInteger (this); @@ -1278,7 +1281,6 @@ MutableBigInteger divideAndRemainderBurnikelZiegler(MutableBigInteger b, Mutable // step 7: z[t-2] = [a[t-1], a[t-2]] MutableBigInteger z = aShifted.getBlock(t-2, t, n); // the second to most significant block z.addDisjoint(a1, n); // z[t-2] - // do schoolbook division on blocks, dividing 2-block numbers by 1-block numbers MutableBigInteger qi = new MutableBigInteger(); MutableBigInteger ri; @@ -1356,7 +1358,6 @@ private MutableBigInteger divide3n2n(MutableBigInteger b, MutableBigInteger quot MutableBigInteger b1 = new MutableBigInteger(b); b1.safeRightShift(n * 32); BigInteger b2 = b.getLower(n); - MutableBigInteger r; MutableBigInteger d; if (compareShifted(b, n) < 0) { @@ -1381,6 +1382,7 @@ private MutableBigInteger divide3n2n(MutableBigInteger b, MutableBigInteger quot // step 5: r = r*beta^n + a3 - d (paper says a4) // However, don't subtract d until after the while loop so r doesn't become negative + r.leftShift(32 * n); r.addLower(this, n); @@ -1390,7 +1392,6 @@ private MutableBigInteger divide3n2n(MutableBigInteger b, MutableBigInteger quot quotient.subtract(MutableBigInteger.ONE); } r.subtract(d); - return r; } @@ -1548,13 +1549,13 @@ private MutableBigInteger divideMagnitude(MutableBigInteger div, int qrem = 0; boolean skipCorrection = false; int nh = rem.value[j+rem.offset]; - int nh2 = nh + 0x80000000; + int nh2 = (nh + 0x80000000)|0; int nm = rem.value[j+1+rem.offset]; if (nh == dh) { qhat = ~0; qrem = nh + nm; - skipCorrection = qrem + 0x80000000 < nh2; + skipCorrection = ((qrem + 0x80000000)|0) < nh2; } else { long nChunk = (((long)nh) << 32) | (nm & LONG_MASK); if (nChunk >= 0) { @@ -1592,7 +1593,7 @@ private MutableBigInteger divideMagnitude(MutableBigInteger div, int borrow = mulsub(rem.value, divisor, qhat, dlen, j+rem.offset); // D5 Test remainder - if (borrow + 0x80000000 > nh2) { + if (((borrow + 0x80000000)|0) > nh2) { // D6 Add back divadd(divisor, rem.value, j+1+rem.offset); qhat--; @@ -1607,13 +1608,13 @@ private MutableBigInteger divideMagnitude(MutableBigInteger div, int qrem = 0; boolean skipCorrection = false; int nh = rem.value[limit - 1 + rem.offset]; - int nh2 = nh + 0x80000000; + int nh2 = (nh + 0x80000000)|0; int nm = rem.value[limit + rem.offset]; if (nh == dh) { qhat = ~0; qrem = nh + nm; - skipCorrection = qrem + 0x80000000 < nh2; + skipCorrection = ((qrem + 0x80000000)|0) < nh2; } else { long nChunk = (((long) nh) << 32) | (nm & LONG_MASK); if (nChunk >= 0) { @@ -1653,7 +1654,7 @@ private MutableBigInteger divideMagnitude(MutableBigInteger div, borrow = mulsubBorrow(rem.value, divisor, qhat, dlen, limit - 1 + rem.offset); // D5 Test remainder - if (borrow + 0x80000000 > nh2) { + if (((borrow + 0x80000000)|0) > nh2) { // D6 Add back if(needRemainder) divadd(divisor, rem.value, limit - 1 + 1 + rem.offset); @@ -1723,13 +1724,13 @@ private MutableBigInteger divideLongMagnitude(long ldivisor, MutableBigInteger q int qrem = 0; boolean skipCorrection = false; int nh = rem.value[j + rem.offset]; - int nh2 = nh + 0x80000000; + int nh2 = (nh + 0x80000000)|0; int nm = rem.value[j + 1 + rem.offset]; if (nh == dh) { qhat = ~0; qrem = nh + nm; - skipCorrection = qrem + 0x80000000 < nh2; + skipCorrection = ((qrem + 0x80000000)|0) < nh2; } else { long nChunk = (((long) nh) << 32) | (nm & LONG_MASK); if (nChunk >= 0) { @@ -1767,7 +1768,7 @@ private MutableBigInteger divideLongMagnitude(long ldivisor, MutableBigInteger q int borrow = mulsubLong(rem.value, dh, dl, qhat, j + rem.offset); // D5 Test remainder - if (borrow + 0x80000000 > nh2) { + if (((borrow + 0x80000000)|0) > nh2) { // D6 Add back divaddLong(dh,dl, rem.value, j + 1 + rem.offset); qhat--; @@ -1963,7 +1964,7 @@ static int binaryGcd(int a, int b) { int t = (aZeros < bZeros ? aZeros : bZeros); while (a != b) { - if ((a+0x80000000) > (b+0x80000000)) { // a > b as unsigned + if (((a+0x80000000)|0) > ((b+0x80000000)|0)) { // a > b as unsigned a -= b; a >>>= Integer.numberOfTrailingZeros(a); } else { diff --git a/sources/net.sf.j2s.java.core/src_4.2/com/jcraft/jzlib/InflaterInputStream.java b/sources/net.sf.j2s.java.core/src_4.2/com/jcraft/jzlib/InflaterInputStream.java index 74980de13..3dc53e75b 100644 --- a/sources/net.sf.j2s.java.core/src_4.2/com/jcraft/jzlib/InflaterInputStream.java +++ b/sources/net.sf.j2s.java.core/src_4.2/com/jcraft/jzlib/InflaterInputStream.java @@ -84,6 +84,9 @@ public int readByteAsInt() throws IOException { return read(byte1, 0, 1) == -1 ? -1 : byte1[0] & 0xff; } + /** + * @j2sOverride + */ @Override public int read(byte[] b, int off, int len) throws IOException { return readInf(b, off, len); diff --git a/sources/net.sf.j2s.java.core/src_4.2/java/io/BufferedInputStream.java b/sources/net.sf.j2s.java.core/src_4.2/java/io/BufferedInputStream.java index 2934c9dcb..eece8e17b 100644 --- a/sources/net.sf.j2s.java.core/src_4.2/java/io/BufferedInputStream.java +++ b/sources/net.sf.j2s.java.core/src_4.2/java/io/BufferedInputStream.java @@ -235,7 +235,7 @@ else if (pos >= buffer.length) /* no room left in buffer */ buffer = buf = nbuf; } count = pos; - int n = getInIfOpen().read(buffer, pos, buffer.length - pos); + int n = isRead(buffer, pos, buffer.length - pos); if (n > 0) count = n + pos; } @@ -262,6 +262,8 @@ public synchronized int readByteAsInt() throws IOException { return getBufIfOpen()[pos++] & 0xff; } + + /** * Read characters into a portion of an array, reading from the underlying * stream at most once if necessary. @@ -279,7 +281,7 @@ private int read1(byte[] b, int off, int len) throws IOException { bytes into the local buffer. In this way buffered streams will cascade harmlessly. */ if (len >= getBufIfOpen().length && markpos < 0) { - return getInIfOpen().read(b, off, len); + return isRead(b, off, len); } fill(); avail = count - pos; @@ -291,7 +293,20 @@ private int read1(byte[] b, int off, int len) throws IOException { return cnt; } - /** + private int isRead(byte[] b, int off, int len) throws IOException { + InputStream is = getInIfOpen(); + /** + * @j2sNative + * if (is.readBAIS) return is.readBAIS(b, off, len); + */ + {} + return is.read(b, off, len); + } + + /** + * + * @j2sOverride + * * Reads bytes from this byte-input stream into the specified byte array, * starting at the given offset. * @@ -332,6 +347,10 @@ private int read1(byte[] b, int off, int len) throws IOException { public synchronized int read(byte b[], int off, int len) throws IOException { + return readBIS(b, off, len); + } + + public int readBIS(byte[] b, int off, int len) throws IOException { getBufIfOpen(); // Check for closed stream if ((off | len | (off + len) | (b.length - (off + len))) < 0) { throw new IndexOutOfBoundsException(); @@ -352,9 +371,9 @@ public synchronized int read(byte b[], int off, int len) if (input != null && input.available() <= 0) return n; } - } + } - /** + /** * See the general contract of the skip * method of InputStream. * diff --git a/sources/net.sf.j2s.java.core/src_4.2/java/io/ByteArrayInputStream.java b/sources/net.sf.j2s.java.core/src_4.2/java/io/ByteArrayInputStream.java index 9ba76bcc6..4fb8d78e3 100644 --- a/sources/net.sf.j2s.java.core/src_4.2/java/io/ByteArrayInputStream.java +++ b/sources/net.sf.j2s.java.core/src_4.2/java/io/ByteArrayInputStream.java @@ -148,6 +148,8 @@ public synchronized int readByteAsInt() { } /** + * @j2sOverride + * Reads up to len bytes of data into an array of bytes * from this input stream. * If pos equals count, @@ -178,6 +180,10 @@ public synchronized int readByteAsInt() { */ @Override public synchronized int read(byte b[], int off, int len) { + return readBAIS(b, off, len); + } + + public int readBAIS(byte[] b, int off, int len) { if (b == null) { throw new NullPointerException(); } else if (off < 0 || len < 0 || len > b.length - off) { @@ -198,9 +204,9 @@ public synchronized int read(byte b[], int off, int len) { System.arraycopy(buf, pos, b, off, len); pos += len; return len; - } + } - /** + /** * Skips n bytes of input from this input stream. Fewer * bytes might be skipped if the end of the input stream is reached. * The actual number k diff --git a/sources/net.sf.j2s.java.core/src_4.2/java/io/DataInputStream.java b/sources/net.sf.j2s.java.core/src_4.2/java/io/DataInputStream.java index 8ddb771f0..24f4508c5 100644 --- a/sources/net.sf.j2s.java.core/src_4.2/java/io/DataInputStream.java +++ b/sources/net.sf.j2s.java.core/src_4.2/java/io/DataInputStream.java @@ -104,6 +104,8 @@ public DataInputStream(InputStream in) { // } /** + * @j2sOverride + * * Reads up to len bytes of data from the contained input stream * into an array of bytes. An attempt is made to read as many as * len bytes, but a smaller number may be read, possibly zero. @@ -161,6 +163,20 @@ public final int read(byte b[], int off, int len) throws IOException { return in.read(b, off, len); } + public final int readDIS(byte b[], int off, int len) throws IOException { + InputStream is = this.in; + /** + * @j2sNative + * + * if (is.readBIS) return is.readBIS(b, off, len); + * if (is.readBAIS) + * return is.readBAIS(b, off, len); + */ + { + } + return is.read(b, off, len); + } + // /** // * See the general contract of the readFully method of // * DataInput. diff --git a/sources/net.sf.j2s.java.core/src_4.2/java/io/FilterInputStream.java b/sources/net.sf.j2s.java.core/src_4.2/java/io/FilterInputStream.java index 9a5eaf1fb..6a3b68dc0 100644 --- a/sources/net.sf.j2s.java.core/src_4.2/java/io/FilterInputStream.java +++ b/sources/net.sf.j2s.java.core/src_4.2/java/io/FilterInputStream.java @@ -111,6 +111,8 @@ public int readByteAsInt() throws IOException { // } /** + * @j2sOverride + * * Reads up to len bytes of data from this input stream * into an array of bytes. If len is not zero, the method * blocks until some input is available; otherwise, no diff --git a/sources/net.sf.j2s.java.core/src_4.2/java/lang/Thread.java b/sources/net.sf.j2s.java.core/src_4.2/java/lang/Thread.java index 3154bbeeb..376d28aef 100644 --- a/sources/net.sf.j2s.java.core/src_4.2/java/lang/Thread.java +++ b/sources/net.sf.j2s.java.core/src_4.2/java/lang/Thread.java @@ -295,18 +295,24 @@ private void init(ThreadGroup g, Runnable target, String name, * @see java.lang.Thread#run() * @see java.lang.Thread#stop() * - * @j2sNative - * window.setTimeout ((function (runnable) { - * return function () { - * runnable.run (); - * }; - * }) (this), 0); */ public synchronized void start() { - // ; + startT(); } - /** + public void startT() { + /** + * + * @j2sNative + * window.setTimeout ((function (runnable) { + * return function () { + * runnable.run (); + * }; + * }) (this), 0); + */ + {} + } + /** * If this thread was constructed using a separate * Runnable run object, then that * Runnable object's run method is called; diff --git a/sources/net.sf.j2s.java.core/src_4.2/java/util/ArrayList.java b/sources/net.sf.j2s.java.core/src_4.2/java/util/ArrayList.java index 772e816fd..b9e2addfd 100644 --- a/sources/net.sf.j2s.java.core/src_4.2/java/util/ArrayList.java +++ b/sources/net.sf.j2s.java.core/src_4.2/java/util/ArrayList.java @@ -45,6 +45,8 @@ public class ArrayList extends AbstractList implements List, Cloneable, private transient E[] array; /** + * @j2sIgnore + * * Constructs a new instance of ArrayList with zero capacity. */ public ArrayList() { @@ -52,21 +54,27 @@ public ArrayList() { } /** + * @j2sIgnore * Constructs a new instance of ArrayList with the specified capacity. * * @param capacity * the initial capacity of this ArrayList */ public ArrayList(int capacity) { - firstIndex = lastIndex = 0; + setCapacity(capacity); + } + + private void setCapacity(int capacity) { try { array = newElementArray(capacity); } catch (NegativeArraySizeException e) { throw new IllegalArgumentException(); } - } + } /** + * @j2sIgnoreSuperConstructor + * * Constructs a new instance of ArrayList containing the elements in the * specified collection. The ArrayList will have an initial capacity which * is 110% of the size of the collection. The order of the elements in this @@ -76,8 +84,25 @@ public ArrayList(int capacity) { * the collection of elements to add */ public ArrayList(Collection collection) { - int size = collection.size(); firstIndex = lastIndex = 0; + int n = -1; + /** + * @j2sNative + * if (!collection) { + * n = 0; + * } else if (typeof collection == "number") { + * n = collection; + * } + * + * + * + */ + {} + if (n >= 0) { + setCapacity(n); + return; + } + int size = collection.size(); array = newElementArray(size + (size / 10)); addAll(collection); } @@ -103,6 +128,10 @@ private E[] newElementArray(int size) { */ @Override public void add(int location, E object) { + add2(location, object); + } + + public void add2(int location, E object) { int size = size(); if (0 < location && location < size) { if (firstIndex == 0 && lastIndex == array.length) { @@ -131,7 +160,6 @@ public void add(int location, E object) { } else { throw new IndexOutOfBoundsException(); } - modCount++; } @@ -639,6 +667,8 @@ public Object[] toArray() { } /** + * @j2sOverride + * * Answers an array containing all elements contained in this ArrayList. If * the specified array is large enough to hold the elements, the specified * array is used, otherwise an array of the same type is created. If the diff --git a/sources/net.sf.j2s.java.core/src_4.2/java/util/Arrays.java b/sources/net.sf.j2s.java.core/src_4.2/java/util/Arrays.java index 2cef95f81..731c33dc7 100644 --- a/sources/net.sf.j2s.java.core/src_4.2/java/util/Arrays.java +++ b/sources/net.sf.j2s.java.core/src_4.2/java/util/Arrays.java @@ -43,6 +43,8 @@ private Arrays() { /** + * @j2sIgnore + * * Assigns the specified Object reference to each element of the specified * array of Objects. * @@ -71,6 +73,15 @@ public static void fill(Object[] a, Object val) { * toIndex > a.length */ public static void fill(Object[] a, int fromIndex, int toIndex,Object val){ + /** + * @j2sNative + * if (arguments.length == 2) { + * val = arguments[1]; + * fromIndex = 0; + * toIndex = a.length; + * } + */ + {} rangeCheck(a.length, fromIndex, toIndex); for (int i=fromIndex; i implements Iterator { type = value; expectedModCount = hm.modCount; lastEntry = entry = null; - isSimple = 秘isSimple(associatedMap); + isSimple = __isSimple(associatedMap); if (isSimple) { - @SuppressWarnings("unused") Map m = associatedMap.秘m; + @SuppressWarnings("unused") Map m = associatedMap.__m; /** * @j2sNative * @@ -226,7 +226,7 @@ public boolean contains(Object object) { Object key = ((Map.Entry) object).getKey(); if (!associatedMap.containsKey(key)) return false; - if (秘isSimple(associatedMap)) { + if (__isSimple(associatedMap)) { Object value = ((Map.Entry) object).getValue(); Object v = associatedMap.get(key); return (value == v || value != null && value.equals(v)); @@ -241,7 +241,7 @@ public Iterator> iterator() { return new HashMapIterator, KT, VT>(new MapEntry.Type, KT, VT>() { @Override public Map.Entry get(MapEntry entry) { - if (秘isSimple(associatedMap)) { + if (__isSimple(associatedMap)) { KT key = null; VT value = null; /** @@ -327,9 +327,9 @@ private void initHM(int capacity, float loadFactor) { /** * @j2sNative * - * if (typeof capacity == "object") { map = capacity; this.秘allowJS = - * map.秘allowJS; capacity = (map.size() < 6 ? 11 : map.size() * 2); } - * else { this.秘allowJS = true; } !capacity && (capacity = 0); + * if (typeof capacity == "object") { map = capacity; this.__allowJS = + * map.__allowJS; capacity = (map.size() < 6 ? 11 : map.size() * 2); } + * else { this.__allowJS = true; } !capacity && (capacity = 0); * !loadFactor && (loadFactor = 0.75); */ { @@ -344,7 +344,7 @@ private void initHM(int capacity, float loadFactor) { } else { throw new IllegalArgumentException(); } - 秘setJS(); + __setJS(); if (map != null) { putAll(map); } @@ -369,12 +369,12 @@ void putMapEntries(Map mOriginal, boolean evict) { return; K key = null; V value = null; - if (秘isSimple(this) && 秘isSimple(mOriginal)) { + if (__isSimple(this) && __isSimple(mOriginal)) { HashMap me = this; int hash = NO_RETURN; - int mode = 秘hasKey(me, key); + int mode = __hasKey(me, key); /** - * @j2sNative mOriginal.秘m.forEach(function(value, key) { + * @j2sNative mOriginal.__m.forEach(function(value, key) { * me.putJSVal(hash, key, value, false, evict, mode); * }); */ @@ -382,10 +382,10 @@ void putMapEntries(Map mOriginal, boolean evict) { } return; } - if (秘isSimple(mOriginal)) { + if (__isSimple(mOriginal)) { HashMap me = this; /** - * @j2sNative mOriginal.秘m.forEach(function(value, key) { + * @j2sNative mOriginal.__m.forEach(function(value, key) { * me.putJavaValue(key, value); * }); */ @@ -393,7 +393,7 @@ void putMapEntries(Map mOriginal, boolean evict) { } return; } - 秘m = null; + __m = null; for (Map.Entry e : mOriginal.entrySet()) { key = e.getKey(); value = e.getValue(); @@ -412,7 +412,7 @@ void reinitialize() { modCount = 0; threshold = 0; elementCount = 0; - 秘setJS(); + __setJS(); } /** @@ -424,17 +424,17 @@ void reinitialize() { @Override public void clear() { modCount++; - if (秘isSimple(this)) { + if (__isSimple(this)) { /** * @j2sNative * - * this.秘m.clear(); + * this.__m.clear(); * */ { } } - 秘setJS(); + __setJS(); if (elementCount > 0) { elementCount = 0; Arrays.fill(elementData, null); @@ -475,11 +475,11 @@ private void computeMaxSize() { */ @Override public boolean containsKey(Object key) { - switch (秘hasKey(this, key)) { + switch (__hasKey(this, key)) { case NOT_SIMPLE: break; case INVALID_KEY: - 秘ensureJavaMap(this); + __ensureJavaMap(this); break; case NO_SUCH_KEY: return false; @@ -518,9 +518,9 @@ boolean keysEqual(Object k1, Entry entry) { */ @Override public boolean containsValue(Object value) { - if (秘isSimple(this)) { + if (__isSimple(this)) { @SuppressWarnings("unused") - Map m = 秘m; + Map m = __m; /** * @j2sNative * @@ -580,11 +580,11 @@ public Set> entrySet() { @Override public V get(Object key) { - switch (秘hasKey(this, key)) { + switch (__hasKey(this, key)) { case NOT_SIMPLE: break; case INVALID_KEY: - 秘ensureJavaMap(this); + __ensureJavaMap(this); break; case NO_SUCH_KEY: return null; @@ -593,7 +593,7 @@ public V get(Object key) { /** * @j2sNative * - * v = this.秘m.get(key); + * v = this.__m.get(key); */ {} return v; @@ -681,7 +681,7 @@ public Iterator iterator() { return new HashMapIterator(new MapEntry.Type() { @Override public K get(MapEntry entry) { - if (秘isSimple(HashMap.this)) { + if (__isSimple(HashMap.this)) { /** * @j2sNative * return (entry == null ? null : entry.value[0]); @@ -707,12 +707,12 @@ public K get(MapEntry entry) { */ @Override public V put(K key, V value) { - int type = 秘hasKey(this, key); + int type = __hasKey(this, key); switch (type) { case NOT_SIMPLE: break; case INVALID_KEY: - 秘ensureJavaMap(this); + __ensureJavaMap(this); break; case NO_SUCH_KEY: case HAS_KEY: @@ -782,7 +782,7 @@ V putJSVal(int hash, K key, V value, boolean onlyIfAbsent, boolean evict, int mo /** * @j2sNative * - * this.秘m.set(key, value); + * this.__m.set(key, value); */ { } @@ -791,7 +791,7 @@ V putJSVal(int hash, K key, V value, boolean onlyIfAbsent, boolean evict, int mo case HAS_KEY: if (hash != NO_RETURN) { /** - * @j2sNative v0 = this.秘m.get(key) || null; + * @j2sNative v0 = this.__m.get(key) || null; */ { } @@ -800,7 +800,7 @@ V putJSVal(int hash, K key, V value, boolean onlyIfAbsent, boolean evict, int mo /** * @j2sNative * - * this.秘m.set(key, value); + * this.__m.set(key, value); */ { } @@ -842,11 +842,11 @@ void rehash() { */ @Override public V remove(Object key) { - switch (秘hasKey(this, key)) { + switch (__hasKey(this, key)) { case NOT_SIMPLE: break; case INVALID_KEY: - 秘ensureJavaMap(this); + __ensureJavaMap(this); break; case NO_SUCH_KEY: return null; @@ -861,7 +861,7 @@ final Object removeJSNode(int hash, Object key, Object value, boolean matchValue V v = null; if (hash == RET_VALUE || matchValue) { /** - * @j2sNative v = this.秘m.get(key) || null; + * @j2sNative v = this.__m.get(key) || null; * */ { @@ -871,7 +871,7 @@ final Object removeJSNode(int hash, Object key, Object value, boolean matchValue /** * @j2sNative * - * this.秘m["delete"](key); + * this.__m["delete"](key); */ { } @@ -925,8 +925,8 @@ Entry removeJavaEntry(Object key) { @Override public int size() { /** @j2sNative - * if (this.秘m) - * return this.秘m.size; + * if (this.__m) + * return this.__m.size; */ {} return elementCount; @@ -963,7 +963,7 @@ public Iterator iterator() { return new HashMapIterator(new MapEntry.Type() { @Override public V get(MapEntry entry) { - if (秘isSimple(HashMap.this)) { + if (__isSimple(HashMap.this)) { /** * @j2sNative * return (entry == null ? null : entry.value[1]); @@ -979,8 +979,8 @@ public V get(MapEntry entry) { return values; } - protected void 秘setJS() { - if (秘allowJS && USE_SIMPLE) { + protected void __setJS() { + if (__allowJS && USE_SIMPLE) { Map m = null; /** * @j2sNative @@ -989,28 +989,28 @@ public V get(MapEntry entry) { */ { } - 秘m = m; + __m = m; } else { - 秘m = null; + __m = null; } } - static Object 秘get(Object map, Object key) { + static Object __get(Object map, Object key) { /** * @j2sNative * - * return map.秘m.get(key == null ? null : key + ""); + * return map.__m.get(key == null ? null : key + ""); */ { return null; } } - static void 秘set(Map map, Object key, Object value) { + static void __set(Map map, Object key, Object value) { /** * @j2sNative * - * map.秘m.set(key == null ? null : key + "", value); + * map.__m.set(key == null ? null : key + "", value); */ { } @@ -1027,7 +1027,7 @@ public V get(MapEntry entry) { * @param key * @return 0 (NOT_SIMPLE), 1 (INVALID_KEY), 2 (NO_SUCH_KEY), or 3 (HAS_KEY) */ - static int 秘hasKey(Map map, Object key) { + static int __hasKey(Map map, Object key) { /** * @@ -1037,8 +1037,8 @@ public V get(MapEntry entry) { * * @j2sNative * - * return (!map.秘m ? 0 : key != null && typeof key != "string" ? 1 : - * map.秘m.has(key) ? 3 : 2); + * return (!map.__m ? 0 : key != null && typeof key != "string" ? 1 : + * map.__m.has(key) ? 3 : 2); * */ { @@ -1046,11 +1046,11 @@ public V get(MapEntry entry) { } } - static boolean 秘isSimple(Map map) { + static boolean __isSimple(Map map) { /** * @j2sNative * - * return !!map.秘m; + * return !!map.__m; */ { return false; @@ -1062,11 +1062,11 @@ public V get(MapEntry entry) { * We've had our fun, now we have to go back to Java... * */ - static void 秘ensureJavaMap(Map map) { + static void __ensureJavaMap(Map map) { /** * @j2sNative * - * if (map.秘m) { var m = map.秘m; map.秘m = null; + * if (map.__m) { var m = map.__m; map.__m = null; * m.forEach(function(value, key){map.put(key, value);}); m.clear(); * } */ @@ -1082,8 +1082,8 @@ public V get(MapEntry entry) { */ public static boolean USE_SIMPLE = true; - Map 秘m; - boolean 秘allowJS = false; + Map __m; + boolean __allowJS = false; static final int NO_RETURN = 0; static final int RET_VALUE = 1; diff --git a/sources/net.sf.j2s.java.core/src_4.2/java/util/Hashtable.java b/sources/net.sf.j2s.java.core/src_4.2/java/util/Hashtable.java index b681a78e1..1c6ffeba0 100644 --- a/sources/net.sf.j2s.java.core/src_4.2/java/util/Hashtable.java +++ b/sources/net.sf.j2s.java.core/src_4.2/java/util/Hashtable.java @@ -161,6 +161,8 @@ public class Hashtable private transient int modCount; /** + * @j2sIgnore + * * SwingJS note: This constructor DOES NOT allow JavaScript Map object for * Hashtable. * @@ -173,7 +175,6 @@ public class Hashtable * zero, or if the load factor is * nonpositive. * - * @j2sIgnore */ public Hashtable(int capacity, float loadFactor) { super(); @@ -212,9 +213,12 @@ public Hashtable(int initialCapacity) { * * @j2sIgnoreSuperConstructor */ - @SuppressWarnings("unused") public Hashtable() { - super(); + initHT(); + } + + @SuppressWarnings("unused") + protected void initHT() { Hashtable map = null; int capacity = 11; float loadFactor = 0.75f; @@ -226,9 +230,9 @@ public Hashtable() { * if (typeof capacity == "object") { * map = capacity; * capacity = Math.max(2*t.size(), 11); - * this.秘allowJS = map.秘allowJS; + * this.__allowJS = map.__allowJS; * } else { - * this.秘allowJS = true; + * this.__allowJS = true; * } * capacity = (capacity || 11); * loadFactor = (loadFactor || 0.75); @@ -245,12 +249,12 @@ public Hashtable() { this.loadFactor = loadFactor; table = new Entry[capacity]; threshold = (int) Math.min(capacity * loadFactor, MAX_ARRAY_SIZE + 1); - 秘setJS(); + __setJS(); if (map != null) putAll(map); - } + } - /** + /** * Constructs a new hashtable with the same mappings as the given * Map. The hashtable is created with an initial capacity sufficient to * hold the mappings in the given Map and a default load factor (0.75). @@ -268,7 +272,7 @@ public Hashtable(Map t) { * b = t.allowJS; */ {} - 秘allowJS = b; + __allowJS = b; putAll(t); } @@ -281,7 +285,7 @@ public Hashtable(Map t) { public synchronized int size() { int c = count; /** @j2sNative - * c = this.秘m && this.秘m.size || c; + * c = this.__m && this.__m.size || c; */ {} return c; @@ -352,9 +356,9 @@ public synchronized boolean contains(Object value) { if (size() == 0) return false; - if (秘isSimple(this)) { + if (__isSimple(this)) { @SuppressWarnings("unused") - Map m = this.秘m; + Map m = this.__m; /** * @j2sNative * @@ -411,11 +415,11 @@ public boolean containsValue(Object value) { @Override public synchronized boolean containsKey(Object key) { - switch (秘hasKey(this, key)) { + switch (__hasKey(this, key)) { case NOT_SIMPLE: break; case INVALID_KEY: - 秘ensureJavaMap(this); + __ensureJavaMap(this); break; case NO_SUCH_KEY: return false; @@ -452,11 +456,11 @@ public synchronized boolean containsKey(Object key) { public synchronized V get(Object key) { if (key == null) return null; - switch (秘hasKey(this, key)) { + switch (__hasKey(this, key)) { case NOT_SIMPLE: break; case INVALID_KEY: - 秘ensureJavaMap(this); + __ensureJavaMap(this); break; case NO_SUCH_KEY: return null; @@ -465,7 +469,7 @@ public synchronized V get(Object key) { /** * @j2sNative * - * v = this.秘m.get(key); + * v = this.__m.get(key); */ {} return v; @@ -571,17 +575,17 @@ public synchronized V put(K key, V value) { throw new NullPointerException(); } - switch (秘hasKey(this, key)) { + switch (__hasKey(this, key)) { case NOT_SIMPLE: break; case INVALID_KEY: - 秘ensureJavaMap(this); + __ensureJavaMap(this); break; case NO_SUCH_KEY: /** * @j2sNative * - * this.秘m.set(key, value); + * this.__m.set(key, value); */ {} ++modCount; @@ -591,8 +595,8 @@ public synchronized V put(K key, V value) { /** * @j2sNative * - * v0 = this.秘m.get(key); - * this.秘m.set(key, value); + * v0 = this.__m.get(key); + * this.__m.set(key, value); */ {} ++modCount; @@ -631,11 +635,11 @@ public synchronized V remove(Object key) { if (key == null) throw new NullPointerException("Hashtable key may not be null"); - switch (秘hasKey(this, key)) { + switch (__hasKey(this, key)) { case NOT_SIMPLE: break; case INVALID_KEY: - 秘ensureJavaMap(this); + __ensureJavaMap(this); break; case NO_SUCH_KEY: return null; @@ -644,7 +648,7 @@ public synchronized V remove(Object key) { /** * @j2sNative * - * v0 = this.秘m.get(key); this.秘m["delete"](key); + * v0 = this.__m.get(key); this.__m["delete"](key); */ {} ++modCount; @@ -686,10 +690,10 @@ public synchronized V remove(Object key) { public synchronized void putAll(Map t) { K key = null; V value = null; - if (秘isSimple(t)) { + if (__isSimple(t)) { Hashtable me = this; /** - * @j2sNative t.秘m.forEach(function(value, key) { me.put(key, value); }) + * @j2sNative t.__m.forEach(function(value, key) { me.put(key, value); }) */ {} return; @@ -705,16 +709,16 @@ public synchronized void putAll(Map t) { public synchronized void clear() { Entry tab[] = table; modCount++; - if (秘isSimple(this)) { + if (__isSimple(this)) { /** * @j2sNative * - * this.秘m.clear(); + * this.__m.clear(); * */ {} } - 秘setJS(); + __setJS(); for (int index = tab.length; --index >= 0;) tab[index] = null; count = 0; @@ -739,20 +743,20 @@ public synchronized Object clone() { t.entrySet = null; t.values = null; t.modCount = 0; - if (秘isSimple(this)) { - t.秘setJS(); + if (__isSimple(this)) { + t.__setJS(); @SuppressWarnings("unused") Hashtable me = this; // evict is for afterNodeAccess, which is not public /** * @j2sNative - * me.秘m.forEach(function(value, key) { - * t.秘m.set(key, value); t.modCount++; + * me.__m.forEach(function(value, key) { + * t.__m.set(key, value); t.modCount++; * }); */ {} } else { - t.秘m = null; + t.__m = null; } return t; } catch (CloneNotSupportedException e) { @@ -762,6 +766,8 @@ public synchronized Object clone() { } /** + * @j2sOverride + * * Returns a string representation of this Hashtable object * in the form of a set of entries, enclosed in braces and separated * by the ASCII characters "" (comma and space). Each @@ -777,21 +783,20 @@ public synchronized String toString() { if (max == -1) return "{}"; - StringBuilder sb = new StringBuilder(); Iterator> it = entrySet().iterator(); - sb.append('{'); + String sb = "{"; for (int i = 0; ; i++) { Map.Entry e = it.next(); K key = e.getKey(); V value = e.getValue(); - sb.append(key == this ? "(this Map)" : key.toString()); - sb.append('='); - sb.append(value == this ? "(this Map)" : value.toString()); + sb += (key == this ? "(this Map)" : key.toString()); + sb += "="; + sb += (value == this ? "(this Map)" : value.toString()); if (i == max) - return sb.append('}').toString(); - sb.append(", "); + return sb + '}'; + sb += ", "; } } @@ -1068,11 +1073,11 @@ public boolean contains(Object o) { Map.Entry entry = (Map.Entry)o; Object key = entry.getKey(); - switch (秘hasKey(ht, key)) { + switch (__hasKey(ht, key)) { case NOT_SIMPLE: break; case INVALID_KEY: - 秘ensureJavaMap(ht); + __ensureJavaMap(ht); break; case HAS_KEY: Object value = entry.getValue(); @@ -1099,11 +1104,11 @@ public boolean remove(Object o) { Map.Entry entry = (Map.Entry) o; Object key = entry.getKey(); - switch (秘hasKey(ht, key)) { + switch (__hasKey(ht, key)) { case NOT_SIMPLE: break; case INVALID_KEY: - 秘ensureJavaMap(ht); + __ensureJavaMap(ht); break; case HAS_KEY: Object value = entry.getValue(); @@ -1241,10 +1246,10 @@ private static class Enumerator implements Enumeration, Iterator { this.type = type; this.isIterator = iterator; expectedModCount = ht.modCount; - if(秘isSimple(ht)) { + if(__isSimple(ht)) { // note that unlike HashMap, this implementation // initializes with the next element in place - @SuppressWarnings("unused") Map m = ht.秘m; + @SuppressWarnings("unused") Map m = ht.__m; /** * @j2sNative * @@ -1258,7 +1263,7 @@ private static class Enumerator implements Enumeration, Iterator { @Override public boolean hasMoreElements() { - if(秘isSimple(ht)) { + if(__isSimple(ht)) { boolean b = false; /** * @j2sNative @@ -1284,7 +1289,7 @@ public boolean hasMoreElements() { @Override public T nextElement() { Entry node = next_; - if (秘isSimple(ht)) { + if (__isSimple(ht)) { @SuppressWarnings("unused") int t = type; current = node; @@ -1315,7 +1320,10 @@ public T nextElement() { @Override public Object setValue(Object value) { - return ht.put(getKey(), value); + int m = ht.modCount; + Object v = ht.put(getKey(), value); + ht.modCount = m; + return (T) v; } }; } @@ -1361,7 +1369,7 @@ public void remove() { if (ht.modCount != expectedModCount) throw new ConcurrentModificationException(); - if (秘isSimple(ht)) { + if (__isSimple(ht)) { Object key = null; /** * @j2sNative @@ -1397,38 +1405,39 @@ public void remove() { } } - protected void 秘setJS() { - if (秘allowJS && USE_SIMPLE) { + protected void __setJS() { + if (__allowJS && USE_SIMPLE) { Map m = null; /** @j2sNative * * m = new Map(); */ {} - 秘m = m; + __m = m; } else { - 秘m = null; + __m = null; } } - static Object 秘get(Object map, Object key) { + static Object __get(Object map, Object key) { /** * @j2sNative * - * return map.秘m.get(key == null ? null : key + "") + * return map.__m.get(key == null ? null : key + "") */ { return null; } } - static void 秘set(Map map, Object key, Object value) { + static void __set(Map map, Object key, Object value) { /** * @j2sNative * - * map.秘m.set(key == null ? null : key + "", value) + * map.__m.set(key == null ? null : key + "", value) */ + {} } /** @@ -1442,7 +1451,7 @@ public void remove() { * @param key * @return 0 (NOT_SIMPLE), 1 (INVALID_KEY), 2 (NO_SUCH_KEY), or 3 (HAS_KEY) */ - static int 秘hasKey(Map map, Object key) { + static int __hasKey(Map map, Object key) { /** * @@ -1452,8 +1461,8 @@ public void remove() { * * @j2sNative * - * return (!map.秘m ? 0 : key != null && typeof key != "string" - * ? 1 : map.秘m.has(key) ? 3 : 2); + * return (!map.__m ? 0 : key != null && typeof key != "string" + * ? 1 : map.__m.has(key) ? 3 : 2); * */ { @@ -1461,11 +1470,11 @@ public void remove() { } } - static boolean 秘isSimple(Map map) { + static boolean __isSimple(Map map) { /** * @j2sNative * - * return !!map.秘m; + * return !!map.__m; */ { return false; @@ -1477,17 +1486,18 @@ public void remove() { * We've had our fun, now we have to go back to Java... * */ - static void 秘ensureJavaMap(Map map) { + static void __ensureJavaMap(Map map) { /** * @j2sNative * - * if (map.秘m) { - * var m = map.秘m; - * map.秘m = null; + * if (map.__m) { + * var m = map.__m; + * map.__m = null; * m.forEach(function(value, key){map.put(key, value);}); * m.clear(); * } */ + {} } /** @@ -1498,8 +1508,8 @@ public void remove() { public static boolean USE_SIMPLE = true; - Map 秘m; - boolean 秘allowJS = false; + Map __m; + boolean __allowJS = false; } diff --git a/sources/net.sf.j2s.java.core/src_4.2/java/util/LinkedHashMap.java b/sources/net.sf.j2s.java.core/src_4.2/java/util/LinkedHashMap.java index 18e10cd73..1778b4f2c 100644 --- a/sources/net.sf.j2s.java.core/src_4.2/java/util/LinkedHashMap.java +++ b/sources/net.sf.j2s.java.core/src_4.2/java/util/LinkedHashMap.java @@ -535,9 +535,9 @@ public Object clone() { @Override - protected void 秘setJS() { + protected void __setJS() { // not implemented in JavaScript.map - 秘m = null; + __m = null; } diff --git a/sources/net.sf.j2s.java.core/src_4.2/java/util/Properties.java b/sources/net.sf.j2s.java.core/src_4.2/java/util/Properties.java index c5d718e9c..1404bdce9 100644 --- a/sources/net.sf.j2s.java.core/src_4.2/java/util/Properties.java +++ b/sources/net.sf.j2s.java.core/src_4.2/java/util/Properties.java @@ -78,13 +78,15 @@ public class Properties extends Hashtable { KEY_DONE = 4, IGNORE = 5; /** + * @j2sIgnore; * Constructs a new Properties object. */ public Properties() { - super(); } /** + * @j2sIgnoreSuperConstructor + * * Constructs a new Properties object using the specified default * properties. * @@ -92,7 +94,9 @@ public Properties() { * the default properties */ public Properties(Properties properties) { - defaults = properties; + initHT(); + // check null just for JavaScript undefined + defaults = (properties == null ? null : properties); } private String dumpString(String buffer, String string, boolean key) { diff --git a/sources/net.sf.j2s.java.core/src_4.2/java/util/StringTokenizer.java b/sources/net.sf.j2s.java.core/src_4.2/java/util/StringTokenizer.java index b4572d37d..0c44aa4f3 100644 --- a/sources/net.sf.j2s.java.core/src_4.2/java/util/StringTokenizer.java +++ b/sources/net.sf.j2s.java.core/src_4.2/java/util/StringTokenizer.java @@ -39,6 +39,8 @@ public class StringTokenizer implements Enumeration { private int position; /** + * @j2sIgnore + * * Constructs a new StringTokenizer for string using whitespace as the * delimiter, returnDelimiters is false. * @@ -50,6 +52,8 @@ public StringTokenizer(String string) { } /** + * @j2sIgnore + * * Constructs a new StringTokenizer for string using the specified * delimiters, returnDelimiters is false. * @@ -63,25 +67,29 @@ public StringTokenizer(String string, String delimiters) { } /** - * Constructs a new StringTokenizer for string using the specified - * delimiters and returning delimiters as tokens when specified. + * Constructs a new StringTokenizer for string using the specified delimiters + * and returning delimiters as tokens when specified. * - * @param string - * the string to be tokenized - * @param delimiters - * the delimiters to use - * @param returnDelimiters - * true to return each delimiter as a token + * @param string the string to be tokenized + * @param delimiters the delimiters to use + * @param returnDelimiters true to return each delimiter as a token */ - public StringTokenizer(String string, String delimiters, - boolean returnDelimiters) { - if (string != null) { - this.string = string; - this.delimiters = delimiters; - this.returnDelimiters = returnDelimiters; - this.position = 0; - } else + public StringTokenizer(String string, String delimiters, boolean returnDelimiters) { + /** + * @j2sNative + * + * switch (arguments.length) { + * case 1: delimiters = " \t\n\r\f"; + * case 2: returnDelimiters = false; + * } + */ + {} + if (string == null) throw new NullPointerException(); + this.string = string; + this.delimiters = delimiters; + this.returnDelimiters = returnDelimiters; + this.position = 0; } /** @@ -160,6 +168,11 @@ public Object nextElement() { * if no tokens remain */ public String nextToken() { + /** + * @j2sNative + * (arguments.length == 1) && (this.delimiters = arguments[0]); + */ + {} int i = position; int length = string.length(); @@ -187,6 +200,7 @@ public String nextToken() { } /** + * @j2sIgnore * Returns the next token in the string as a String. The delimiters used are * changed to the specified delimiters. * diff --git a/sources/net.sf.j2s.java.core/src_4.2/test/Test.java b/sources/net.sf.j2s.java.core/src_4.2/test/Test.java index 07e4b177b..f0f1f032d 100644 --- a/sources/net.sf.j2s.java.core/src_4.2/test/Test.java +++ b/sources/net.sf.j2s.java.core/src_4.2/test/Test.java @@ -3,6 +3,9 @@ import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; import java.awt.event.MouseListener; +import java.io.ByteArrayInputStream; +import java.io.DataInputStream; +import java.io.IOException; public class Test implements ITest { @@ -59,7 +62,17 @@ public Test(){ public final static void main(String[] args) { new javax.swing.JButton(); - + + ByteArrayInputStream bis = new ByteArrayInputStream(new byte[] {'t','e','s','t'}); + DataInputStream dis = new DataInputStream(bis); + byte[] bytes = new byte[4]; + try { + dis.read(bytes, 0, 4); + } catch (IOException e1) { + // TODO Auto-generated catch block + e1.printStackTrace(); + } + char ch = '1'; switch (ch) { case 0b111111: diff --git a/sources/net.sf.j2s.java.core/srcjs/js/j2sClazz.js b/sources/net.sf.j2s.java.core/srcjs/js/j2sClazz.js index 36a1ef9ed..0cd124654 100644 --- a/sources/net.sf.j2s.java.core/srcjs/js/j2sClazz.js +++ b/sources/net.sf.j2s.java.core/srcjs/js/j2sClazz.js @@ -7,6 +7,7 @@ // Google closure compiler cannot handle Clazz.new or Clazz.super +// BH 2024.02.23 fixes missing Long.signum // BH 2023.04.30 fixes issues when Info.console == window.console // BH 2023.03.01 upgrade for Java11 String, including String.isBlank() and CharSequence.lines(String) (in Java11 this is StringRoman1.lines(byte[]) // BH 2023.02.12 upgrade for (asynchronous?) packaging @@ -4453,66 +4454,54 @@ var fixLongAB = function(a,b) { } -Long.$eq=function(a,b){ +Long.$cmp=function(a,b, unsigned){ if (fixLongAB(a,b)) { - return a == b; + return (a < b ? -1 : a > b ? 1 : 0); } a = ab[0];b = ab[1]; - return (a[0] == b[0] && a[1] == b[1] && a[2]== b[2]); -} - -Long.$ne=function(a,b){ - if (fixLongAB(a,b)) { - return a != b; + if (unsigned) { + a = toLongRLH(a); + b = toLongRLH(b); + for (let i = 2; i >= 0; i--) { + if (a[i] < b[i]) return -1; + if (a[i] > b[i]) return 1; + } + return 0; } - a = ab[0];b = ab[1]; - return (a[0] != b[0] || a[1] != b[1] || a[2]!= b[2]); + return ( + a[2] < b[2] ? -1 + : a[2] > b[2] ? 1 + : a[2] == 0 ? 0 + : a[1] < b[1] ? -a[2] + : a[1] > b[1] ? a[2] + : a[0] < b[0] ? -a[2] + : a[0] > b[0] ? a[2] + : 0 + ); } -Long.$gt=function(a,b){ - if (fixLongAB(a,b)) { - return a > b; - } - a = ab[0];b = ab[1]; - return (a[2] > b[2] || a[2] == b[2] && (a[1] > b[1] || a[1] == b[1] && a[0] > b[0])); +Long.$eq=function(a,b){ + return Long.$cmp(a, b) == 0; } -Long.$cmp=function(a,b, unsigned){ - if (fixLongAB(a,b)) { - return (a < b ? -1 : a > b ? 1 : 0); - } - a = ab[0];b = ab[1]; - if (unsigned) { - a = toLongRLH(a); - b = toLongRLH(b); - } - return (a[2] < b[2] ? -1 : a[2] > b[2] ? 1 - : a[2] == 0 ? 0 : a[1] < b[1] ? -1 : a[1] > b[1] ? 1 - : a[0] < b[0] ? -1 : a[0] > b[0] ? 1 : 0); +Long.$ne=function(a,b){ + return Long.$cmp(a, b) != 0; } Long.$ge=function(a,b){ - if (fixLongAB(a,b)) { - return a >= b; - } - a = ab[0];b = ab[1]; - return (a[2] > b[2] || a[2] == b[2] && (a[1] > b[1] || a[1] == b[1] && a[0] >= b[0])); + return Long.$cmp(a, b) >= 0; +} + +Long.$gt=function(a,b){ + return Long.$cmp(a, b) > 0; } Long.$le=function(a,b){ - if (fixLongAB(a,b)) { - return a <= b; - } - a = ab[0];b = ab[1]; - return (a[2] < b[2] || a[2] == b[2] && (a[1] < b[1] || a[1] == b[1] && a[0] <= b[0])); + return Long.$cmp(a, b) <= 0; } Long.$lt=function(a,b){ - if (fixLongAB(a,b)) { - return a < b; - } - a = ab[0];b = ab[1]; - return (a[2] < b[2] || a[2] == b[2] && (a[1] < b[1] || a[1] == b[1] && a[0] < b[0])); + return Long.$cmp(a, b) < 0; } @@ -5096,7 +5085,8 @@ return i; }, 1); m$(C$, 'signum$J', function (i) { -return Long.$ival((Long.$or((Long.$sr(i,63)),(Long.$usr((Long.$neg(i)),63))))); +return Long.$sign(i); +//Long.$ival((Long.$or((Long.$sr(i,63)),(Long.$usr((Long.$neg(i)),63))))); }, 1); m$(C$, 'reverseBytes$J', function (i) { @@ -5204,10 +5194,7 @@ Long.toUnsignedBigInteger$J = function(i) { bi || (bi=(Clazz.load("java.math.BigInteger"), Clazz.new_(java.math.BigInteger.c$$S,["18446744073709551616"]))); return (i >= 0 ? bi.valueOf$J(i) : bi.valueOf$J(i).add$java_math_BigInteger(bi)); } - -m$(Long,"signum$J", function(i){ return i < 0 ? -1 : i > 0 ? 1 : 0; }, 1); - Clazz._setDeclared("java.lang.Short", java.lang.Short = Short = function(){ if (arguments[0] === null || typeof arguments[0] != "object")this.c$(arguments[0]); }); diff --git a/sources/net.sf.j2s.java.core/srcjs/php/jsmol.php b/sources/net.sf.j2s.java.core/srcjs/php/jsmol.php index d4b8bc1ac..cdb11a5a4 100644 --- a/sources/net.sf.j2s.java.core/srcjs/php/jsmol.php +++ b/sources/net.sf.j2s.java.core/srcjs/php/jsmol.php @@ -3,6 +3,8 @@ // jsmol.php // Bob Hanson hansonr@stolaf.edu 1/11/2013 // +// 2024.02.05 fixing missing utf-8 header +// 10 NOV 2018 -- print($output) should be echo($output) to prevent trailing \r\n // 27 MAR 2018 -- security upgrade // 31 MAR 2016 -- https://cactus -> https://cactus // 09 Nov 2015 -- bug fix for www.pdb --> www.rcsb @@ -99,6 +101,7 @@ function getValueSimple($json, $key, $default) { $contentType = ""; $output = ""; $isBinary = false; +$isJS = false; $filename = ""; if ($call == "getInfoFromDatabase") { @@ -136,12 +139,13 @@ function getValueSimple($json, $key, $default) { } } else if ($call == "getRawDataFromDatabase") { - $isBinary = (strpos($query, ".gz") >= 0); - if ($database != "_") - $query = $database.$query; - if (strpos(strtolower($query), 'https://') !== 0 && strpos(strtolower($query), 'http://') !== 0) { - $output = "invalid url"; - } else if (strpos($query, '?POST?') > 0) { + $isBinary = (strpos($query, ".gz") !== false); + $isJS = (strpos($query, '.js') !== false); + if ($database != "_") + $query = $database.$query; + if (strpos(strtolower($query), 'https://') !== 0 && strpos(strtolower($query), 'http://') !== 0) { + $output = "invalid url"; + } else if (strpos($query, '?POST?') > 0) { list($query,$data) = explode('?POST?', $query, 2); $context = stream_context_create(array('http' => array( 'method' => 'POST', @@ -149,12 +153,12 @@ function getValueSimple($json, $key, $default) { 'content' => $data)) ); $output = file_get_contents($query, false, $context); - } else { + } else { $output = file_get_contents($query); - if ($test != "") { - $output = $query."
".$output; - } - } + if ($test != "") { + $output = $query."
".$output; + } + } } else if ($call == "saveFile") { $imagedata = $_REQUEST["data"];//getValueSimple($values, "data", ""); don't want to convert " to _ here $filename = getValueSimple($values, "filename", ""); @@ -187,9 +191,11 @@ function getValueSimple($json, $key, $default) { header('Access-Control-Allow-Origin: *'); if ($isBinary) { header('Content-Type: text/plain; charset=x-user-defined'); - } else if (strpos($output, ' 0) { - header('Content-type: text/html; charset=utf-8'); - } else { + } else if ($isJS) { + header('Content-Type: text/javascript; charset=utf-8'); + } else if (strpos($output, ' b ? 1 : 0); } a = ab[0];b = ab[1]; - return (a[0] == b[0] && a[1] == b[1] && a[2]== b[2]); -} - -Long.$ne=function(a,b){ - if (fixLongAB(a,b)) { - return a != b; + if (unsigned) { + a = toLongRLH(a); + b = toLongRLH(b); + for (let i = 2; i >= 0; i--) { + if (a[i] < b[i]) return -1; + if (a[i] > b[i]) return 1; + } + return 0; } - a = ab[0];b = ab[1]; - return (a[0] != b[0] || a[1] != b[1] || a[2]!= b[2]); + return ( + a[2] < b[2] ? -1 + : a[2] > b[2] ? 1 + : a[2] == 0 ? 0 + : a[1] < b[1] ? -a[2] + : a[1] > b[1] ? a[2] + : a[0] < b[0] ? -a[2] + : a[0] > b[0] ? a[2] + : 0 + ); } -Long.$gt=function(a,b){ - if (fixLongAB(a,b)) { - return a > b; - } - a = ab[0];b = ab[1]; - return (a[2] > b[2] || a[2] == b[2] && (a[1] > b[1] || a[1] == b[1] && a[0] > b[0])); +Long.$eq=function(a,b){ + return Long.$cmp(a, b) == 0; } -Long.$cmp=function(a,b, unsigned){ - if (fixLongAB(a,b)) { - return (a < b ? -1 : a > b ? 1 : 0); - } - a = ab[0];b = ab[1]; - if (unsigned) { - a = toLongRLH(a); - b = toLongRLH(b); - } - return (a[2] < b[2] ? -1 : a[2] > b[2] ? 1 - : a[2] == 0 ? 0 : a[1] < b[1] ? -1 : a[1] > b[1] ? 1 - : a[0] < b[0] ? -1 : a[0] > b[0] ? 1 : 0); +Long.$ne=function(a,b){ + return Long.$cmp(a, b) != 0; } Long.$ge=function(a,b){ - if (fixLongAB(a,b)) { - return a >= b; - } - a = ab[0];b = ab[1]; - return (a[2] > b[2] || a[2] == b[2] && (a[1] > b[1] || a[1] == b[1] && a[0] >= b[0])); + return Long.$cmp(a, b) >= 0; +} + +Long.$gt=function(a,b){ + return Long.$cmp(a, b) > 0; } Long.$le=function(a,b){ - if (fixLongAB(a,b)) { - return a <= b; - } - a = ab[0];b = ab[1]; - return (a[2] < b[2] || a[2] == b[2] && (a[1] < b[1] || a[1] == b[1] && a[0] <= b[0])); + return Long.$cmp(a, b) <= 0; } Long.$lt=function(a,b){ - if (fixLongAB(a,b)) { - return a < b; - } - a = ab[0];b = ab[1]; - return (a[2] < b[2] || a[2] == b[2] && (a[1] < b[1] || a[1] == b[1] && a[0] < b[0])); + return Long.$cmp(a, b) < 0; } @@ -19210,7 +19199,8 @@ return i; }, 1); m$(C$, 'signum$J', function (i) { -return Long.$ival((Long.$or((Long.$sr(i,63)),(Long.$usr((Long.$neg(i)),63))))); +return Long.$sign(i); +//Long.$ival((Long.$or((Long.$sr(i,63)),(Long.$usr((Long.$neg(i)),63))))); }, 1); m$(C$, 'reverseBytes$J', function (i) { @@ -19318,10 +19308,7 @@ Long.toUnsignedBigInteger$J = function(i) { bi || (bi=(Clazz.load("java.math.BigInteger"), Clazz.new_(java.math.BigInteger.c$$S,["18446744073709551616"]))); return (i >= 0 ? bi.valueOf$J(i) : bi.valueOf$J(i).add$java_math_BigInteger(bi)); } - -m$(Long,"signum$J", function(i){ return i < 0 ? -1 : i > 0 ? 1 : 0; }, 1); - Clazz._setDeclared("java.lang.Short", java.lang.Short = Short = function(){ if (arguments[0] === null || typeof arguments[0] != "object")this.c$(arguments[0]); });