diff --git a/teavm-classlib/src/main/java/org/teavm/classlib/impl/report/JCLComparisonBuilder.java b/teavm-classlib/src/main/java/org/teavm/classlib/impl/report/JCLComparisonBuilder.java index 20232184b..38e78a6f0 100644 --- a/teavm-classlib/src/main/java/org/teavm/classlib/impl/report/JCLComparisonBuilder.java +++ b/teavm-classlib/src/main/java/org/teavm/classlib/impl/report/JCLComparisonBuilder.java @@ -166,7 +166,7 @@ public class JCLComparisonBuilder { return false; } int slashIndex = name.lastIndexOf('/'); - return packages.contains(name.substring(0, slashIndex)); + return slashIndex >= 0 && packages.contains(name.substring(0, slashIndex)); } private void compareClass(InputStream input) throws IOException { diff --git a/teavm-classlib/src/main/java/org/teavm/classlib/java/lang/TMath.java b/teavm-classlib/src/main/java/org/teavm/classlib/java/lang/TMath.java index 6c7f15d22..a74a6574c 100644 --- a/teavm-classlib/src/main/java/org/teavm/classlib/java/lang/TMath.java +++ b/teavm-classlib/src/main/java/org/teavm/classlib/java/lang/TMath.java @@ -283,9 +283,9 @@ public final class TMath extends TObject { return direction > start ? start + ulp(start) : start - ulp(start); } - public static float nextAfter(float start, float direction) { + public static float nextAfter(float start, double direction) { if (start == direction) { - return direction; + return start; } return direction > start ? start + ulp(start) : start - ulp(start); } diff --git a/teavm-classlib/src/main/java/org/teavm/classlib/java/lang/TStrictMath.java b/teavm-classlib/src/main/java/org/teavm/classlib/java/lang/TStrictMath.java new file mode 100644 index 000000000..c2060df50 --- /dev/null +++ b/teavm-classlib/src/main/java/org/teavm/classlib/java/lang/TStrictMath.java @@ -0,0 +1,236 @@ +/* + * Copyright 2014 Alexey Andreev. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.teavm.classlib.java.lang; + +/** + * + * @author Alexey Andreev + */ +public final class TStrictMath extends TObject { + public static double E = 2.71828182845904523536; + public static double PI = 3.14159265358979323846; + + private TStrictMath() { + } + + public static double sin(double a) { + return TMath.sin(a); + } + + public static double cos(double a) { + return TMath.cos(a); + } + + public static double tan(double a) { + return TMath.tan(a); + } + + public static double asin(double a) { + return TMath.asin(a); + } + + public static double acos(double a) { + return TMath.acos(a); + } + + public static double atan(double a) { + return TMath.atan(a); + } + + public static double toRadians(double angdeg) { + return TMath.toRadians(angdeg); + } + + public static double toDegrees(double angrad) { + return TMath.toDegrees(angrad); + } + + public static double exp(double a) { + return TMath.exp(a); + } + + public static double log(double a) { + return TMath.log(a); + } + + public static double log10(double a) { + return TMath.log10(a); + } + + public static double sqrt(double a) { + return TMath.sqrt(a); + } + + public static double cbrt(double a) { + return TMath.cbrt(a); + } + + public static double IEEEremainder(double f1, double f2) { + return TMath.IEEEremainder(f1, f2); + } + + public static double ceil(double a) { + return TMath.ceil(a); + } + + public static double floor(double a) { + return TMath.floor(a); + } + + public static double rint(double a) { + return TMath.rint(a); + } + + public static double atan2(double y, double x) { + return TMath.atan2(y, x); + } + + public static double pow(double a, double b) { + return TMath.pow(a, b); + } + + public static int round(float a) { + return TMath.round(a); + } + + public static long round(double a) { + return TMath.round(a); + } + + public static double random() { + return TMath.random(); + } + + public static int abs(int a) { + return TMath.abs(a); + } + + public static long abs(long a) { + return TMath.abs(a); + } + + public static float abs(float a) { + return TMath.abs(a); + } + + public static double abs(double a) { + return TMath.abs(a); + } + + public static int max(int a, int b) { + return TMath.max(a, b); + } + + public static long max(long a, long b) { + return TMath.max(a, b); + } + + public static float max(float a, float b) { + return TMath.max(a, b); + } + + public static double max(double a, double b) { + return TMath.max(a, b); + } + + public static int min(int a, int b) { + return TMath.min(a, b); + } + + public static long min(long a, long b) { + return TMath.min(a, b); + } + + public static float min(float a, float b) { + return TMath.min(a, b); + } + + public static double min(double a, double b) { + return TMath.min(a, b); + } + + public static double ulp(double d) { + return TMath.ulp(d); + } + + public static float ulp(float f) { + return TMath.ulp(f); + } + + public static double signum(double d) { + return TMath.signum(d); + } + + public static float signum(float f) { + return TMath.signum(f); + } + + public static double sinh(double x) { + return TMath.sinh(x); + } + + public static double cosh(double x) { + return TMath.cosh(x); + } + + public static double tanh(double x) { + return TMath.tanh(x); + } + + public static double hypot(double x, double y) { + return TMath.hypot(x, y); + } + + public static double expm1(double x) { + return TMath.expm1(x); + } + + public static double log1p(double x) { + return TMath.log1p(x); + } + + public static double copySign(double magnitude, double sign) { + return TMath.copySign(magnitude, sign); + } + + public static float copySign(float magnitude, float sign) { + return TMath.copySign(magnitude, sign); + } + + public static int getExponent(float f) { + return TMath.getExponent(f); + } + + public static int getExponent(double d) { + return TMath.getExponent(d); + } + + public static double nextAfter(double start, double direction) { + return TMath.nextAfter(start, direction); + } + + public static float nextAfter(float start, double direction) { + return TMath.nextAfter(start, direction); + } + + public static double nextUp(double d) { + return TMath.nextUp(d); + } + + public static float nextUp(float f) { + return TMath.nextUp(f); + } +} diff --git a/teavm-classlib/src/test/java/org/teavm/classlib/java/text/DateFormatTest.java b/teavm-classlib/src/test/java/org/teavm/classlib/java/text/DateFormatTest.java index a6f94de8c..30576e590 100644 --- a/teavm-classlib/src/test/java/org/teavm/classlib/java/text/DateFormatTest.java +++ b/teavm-classlib/src/test/java/org/teavm/classlib/java/text/DateFormatTest.java @@ -32,41 +32,41 @@ public class DateFormatTest { @Test public void shortDateFormatHandled() throws ParseException { DateFormat format = DateFormat.getDateInstance(DateFormat.SHORT, Locale.ENGLISH); - assertEquals("6/24/14", format.format(getDateWithZoneOffset(1403539200000L))); - assertEquals(1403539200000L, getTimeWithoutZoneOffset(format.parse("6/24/14"))); + assertEquals("6/23/14", format.format(getDateWithZoneOffset(1403481600000L))); + assertEquals(1403481600000L, getTimeWithoutZoneOffset(format.parse("6/23/14"))); } @Test public void mediumDateFormatHandled() throws ParseException { DateFormat format = DateFormat.getDateInstance(DateFormat.MEDIUM, Locale.ENGLISH); - assertEquals("Jun 24, 2014", format.format(getDateWithZoneOffset(1403539200000L))); - assertEquals(1403539200000L, getTimeWithoutZoneOffset(format.parse("Jun 24, 2014"))); + assertEquals("Jun 23, 2014", format.format(getDateWithZoneOffset(1403481600000L))); + assertEquals(1403481600000L, getTimeWithoutZoneOffset(format.parse("Jun 23, 2014"))); } @Test public void longDateFormatHandled() throws ParseException { DateFormat format = DateFormat.getDateInstance(DateFormat.LONG, Locale.ENGLISH); - assertEquals("June 24, 2014", format.format(getDateWithZoneOffset(1403539200000L))); - assertEquals(1403539200000L, getTimeWithoutZoneOffset(format.parse("June 24, 2014"))); + assertEquals("June 23, 2014", format.format(getDateWithZoneOffset(1403481600000L))); + assertEquals(1403481600000L, getTimeWithoutZoneOffset(format.parse("June 23, 2014"))); } @Test public void fullDateFormatHandled() throws ParseException { DateFormat format = DateFormat.getDateInstance(DateFormat.FULL, Locale.ENGLISH); - assertEquals("Tuesday, June 24, 2014", format.format(getDateWithZoneOffset(1403539200000L))); - assertEquals(1403539200000L, getTimeWithoutZoneOffset(format.parse("Tuesday, June 24, 2014"))); + assertEquals("Monday, June 23, 2014", format.format(getDateWithZoneOffset(1403481600000L))); + assertEquals(1403481600000L, getTimeWithoutZoneOffset(format.parse("Monday, June 23, 2014"))); } private Date getDateWithZoneOffset(long milliseconds) { Calendar calendar = new GregorianCalendar(Locale.ENGLISH); calendar.setTimeInMillis(milliseconds); - milliseconds += calendar.get(Calendar.ZONE_OFFSET); + milliseconds -= calendar.get(Calendar.ZONE_OFFSET); return new Date(milliseconds); } private long getTimeWithoutZoneOffset(Date date) { Calendar calendar = new GregorianCalendar(Locale.ENGLISH); calendar.setTime(date); - return calendar.getTimeInMillis() - calendar.get(Calendar.ZONE_OFFSET); + return calendar.getTimeInMillis() + calendar.get(Calendar.ZONE_OFFSET); } } diff --git a/teavm-classlib/src/test/java/org/teavm/classlib/java/text/SimpleDateFormatTest.java b/teavm-classlib/src/test/java/org/teavm/classlib/java/text/SimpleDateFormatTest.java index 8859ac4c0..f5ce9d4ae 100644 --- a/teavm-classlib/src/test/java/org/teavm/classlib/java/text/SimpleDateFormatTest.java +++ b/teavm-classlib/src/test/java/org/teavm/classlib/java/text/SimpleDateFormatTest.java @@ -18,10 +18,7 @@ package org.teavm.classlib.java.text; import static org.junit.Assert.assertEquals; import java.text.ParseException; import java.text.SimpleDateFormat; -import java.util.Calendar; -import java.util.Date; -import java.util.GregorianCalendar; -import java.util.Locale; +import java.util.*; import org.junit.Test; /** @@ -38,114 +35,114 @@ public class SimpleDateFormatTest { @Test public void fieldsFormatted() { SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.ENGLISH); - assertEquals("2014-06-24 17:33:49", format.format(getDateWithZoneOffset(1403602429504L))); + assertEquals("2014-06-24 09:33:49", format.format(getDateWithZoneOffset(1403602429504L))); } @Test public void fieldsParsed() throws ParseException { SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.ENGLISH); - assertEquals(1403602429000L, getTimeWithoutZoneOffset(format.parse("2014-06-24 17:33:49"))); + assertEquals(1403602429000L, getTimeWithoutZoneOffset(format.parse("2014-06-24 09:33:49"))); } @Test public void eraHandled() throws ParseException { SimpleDateFormat format = new SimpleDateFormat("G yyyy-MM-dd HH:mm:ss", Locale.ENGLISH); - assertEquals("AD 2014-06-24 17:33:49", format.format(getDateWithZoneOffset(1403602429504L))); - assertEquals(1403602429000L, getTimeWithoutZoneOffset(format.parse("AD 2014-06-24 17:33:49"))); + assertEquals("AD 2014-06-24 09:33:49", format.format(getDateWithZoneOffset(1403602429504L))); + assertEquals(1403602429000L, getTimeWithoutZoneOffset(format.parse("AD 2014-06-24 09:33:49"))); } @Test public void shortYearHandled() throws ParseException { SimpleDateFormat format = new SimpleDateFormat("yy-MM-dd HH:mm:ss", Locale.ENGLISH); - assertEquals("14-06-24 17:33:49", format.format(getDateWithZoneOffset(1403602429504L))); - assertEquals(1403602429000L, getTimeWithoutZoneOffset(format.parse("14-06-24 17:33:49"))); + assertEquals("14-06-24 09:33:49", format.format(getDateWithZoneOffset(1403602429504L))); + assertEquals(1403602429000L, getTimeWithoutZoneOffset(format.parse("14-06-24 09:33:49"))); } @Test public void weekInYearHandled() throws ParseException { long day = 24 * 3600 * 1000; SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss www", Locale.ENGLISH); - assertEquals("2014-06-24 17:33:49 026", format.format(getDateWithZoneOffset(1403602429504L))); - assertEquals("2014-06-28 17:33:49 026", format.format(getDateWithZoneOffset(1403602429504L + day * 4))); - assertEquals("2014-06-29 17:33:49 027", format.format(getDateWithZoneOffset(1403602429504L + day * 5))); - assertEquals(1403602429000L, getTimeWithoutZoneOffset(format.parse("2014-06-24 17:33:49 026"))); - assertEquals(1403602429000L + day * 4, getTimeWithoutZoneOffset(format.parse("2014-06-28 17:33:49 026"))); - assertEquals(1403602429000L + day * 5, getTimeWithoutZoneOffset(format.parse("2014-06-29 17:33:49 027"))); + assertEquals("2014-06-24 09:33:49 026", format.format(getDateWithZoneOffset(1403602429504L))); + assertEquals("2014-06-28 09:33:49 026", format.format(getDateWithZoneOffset(1403602429504L + day * 4))); + assertEquals("2014-06-29 09:33:49 027", format.format(getDateWithZoneOffset(1403602429504L + day * 5))); + assertEquals(1403602429000L, getTimeWithoutZoneOffset(format.parse("2014-06-24 09:33:49 026"))); + assertEquals(1403602429000L + day * 4, getTimeWithoutZoneOffset(format.parse("2014-06-28 09:33:49 026"))); + assertEquals(1403602429000L + day * 5, getTimeWithoutZoneOffset(format.parse("2014-06-29 09:33:49 027"))); } @Test public void weekInMonthHandled() throws ParseException { SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss WW", Locale.ENGLISH); - assertEquals("2014-06-24 17:33:49 04", format.format(getDateWithZoneOffset(1403602429504L))); - assertEquals(1403602429000L, getTimeWithoutZoneOffset(format.parse("2014-06-24 17:33:49 04"))); + assertEquals("2014-06-24 09:33:49 04", format.format(getDateWithZoneOffset(1403602429504L))); + assertEquals(1403602429000L, getTimeWithoutZoneOffset(format.parse("2014-06-24 09:33:49 04"))); } @Test public void dayInYearHandled() throws ParseException { SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss DD", Locale.ENGLISH); - assertEquals("2014-06-24 17:33:49 175", format.format(getDateWithZoneOffset(1403602429504L))); - assertEquals(1403602429000L, getTimeWithoutZoneOffset(format.parse("2014-06-24 17:33:49 175"))); + assertEquals("2014-06-24 09:33:49 175", format.format(getDateWithZoneOffset(1403602429504L))); + assertEquals(1403602429000L, getTimeWithoutZoneOffset(format.parse("2014-06-24 09:33:49 175"))); } @Test public void weekdayInMonthHandled() throws ParseException { SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss F", Locale.ENGLISH); - assertEquals("2014-06-24 17:33:49 4", format.format(getDateWithZoneOffset(1403602429504L))); - assertEquals(1403602429000L, getTimeWithoutZoneOffset(format.parse("2014-06-24 17:33:49 4"))); + assertEquals("2014-06-24 09:33:49 4", format.format(getDateWithZoneOffset(1403602429504L))); + assertEquals(1403602429000L, getTimeWithoutZoneOffset(format.parse("2014-06-24 09:33:49 4"))); } @Test public void shortWeekdayHandled() throws ParseException { SimpleDateFormat format = new SimpleDateFormat("E yyyy-MM-dd HH:mm:ss", Locale.ENGLISH); - assertEquals("Tue 2014-06-24 17:33:49", format.format(getDateWithZoneOffset(1403602429504L))); - assertEquals(1403602429000L, getTimeWithoutZoneOffset(format.parse("Tue 2014-06-24 17:33:49"))); + assertEquals("Tue 2014-06-24 09:33:49", format.format(getDateWithZoneOffset(1403602429504L))); + assertEquals(1403602429000L, getTimeWithoutZoneOffset(format.parse("Tue 2014-06-24 09:33:49"))); } @Test public void longWeekdayHandled() throws ParseException { SimpleDateFormat format = new SimpleDateFormat("EEEE, yyyy-MM-dd HH:mm:ss", Locale.ENGLISH); - assertEquals("Tuesday, 2014-06-24 17:33:49", format.format(getDateWithZoneOffset(1403602429504L))); - assertEquals(1403602429000L, getTimeWithoutZoneOffset(format.parse("Tuesday, 2014-06-24 17:33:49"))); + assertEquals("Tuesday, 2014-06-24 09:33:49", format.format(getDateWithZoneOffset(1403602429504L))); + assertEquals(1403602429000L, getTimeWithoutZoneOffset(format.parse("Tuesday, 2014-06-24 09:33:49"))); } @Test public void numericWeekdayHandled() throws ParseException { SimpleDateFormat format = new SimpleDateFormat("u yyyy-MM-dd HH:mm:ss", Locale.ENGLISH); - assertEquals("2 2014-06-24 17:33:49", format.format(getDateWithZoneOffset(1403602429504L))); - assertEquals(1403602429000L, getTimeWithoutZoneOffset(format.parse("2 2014-06-24 17:33:49"))); + assertEquals("2 2014-06-24 09:33:49", format.format(getDateWithZoneOffset(1403602429504L))); + assertEquals(1403602429000L, getTimeWithoutZoneOffset(format.parse("2 2014-06-24 09:33:49"))); } @Test public void amPmHandled() throws ParseException { SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd 'at' hh:mm:ss a", Locale.ENGLISH); - assertEquals("2014-06-24 at 05:33:49 PM", format.format(getDateWithZoneOffset(1403602429504L))); - assertEquals(1403602429000L, getTimeWithoutZoneOffset(format.parse("2014-06-24 at 05:33:49 PM"))); + assertEquals("2014-06-24 at 09:33:49 AM", format.format(getDateWithZoneOffset(1403602429504L))); + assertEquals(1403602429000L, getTimeWithoutZoneOffset(format.parse("2014-06-24 at 09:33:49 AM"))); } @Test public void shortMonthHandled() throws ParseException { SimpleDateFormat format = new SimpleDateFormat("MMM, dd yyyy HH:mm:ss", Locale.ENGLISH); - assertEquals("Jun, 24 2014 17:33:49", format.format(getDateWithZoneOffset(1403602429504L))); - assertEquals(1403602429000L, getTimeWithoutZoneOffset(format.parse("Jun, 24 2014 17:33:49"))); + assertEquals("Jun, 24 2014 09:33:49", format.format(getDateWithZoneOffset(1403602429504L))); + assertEquals(1403602429000L, getTimeWithoutZoneOffset(format.parse("Jun, 24 2014 09:33:49"))); } @Test public void longMonthHandled() throws ParseException { SimpleDateFormat format = new SimpleDateFormat("MMMM, dd yyyy HH:mm:ss", Locale.ENGLISH); - assertEquals("June, 24 2014 17:33:49", format.format(getDateWithZoneOffset(1403602429504L))); - assertEquals(1403602429000L, getTimeWithoutZoneOffset(format.parse("June, 24 2014 17:33:49"))); + assertEquals("June, 24 2014 09:33:49", format.format(getDateWithZoneOffset(1403602429504L))); + assertEquals(1403602429000L, getTimeWithoutZoneOffset(format.parse("June, 24 2014 09:33:49"))); } private Date getDateWithZoneOffset(long milliseconds) { Calendar calendar = new GregorianCalendar(Locale.ENGLISH); calendar.setTimeInMillis(milliseconds); - milliseconds += calendar.get(Calendar.ZONE_OFFSET); + milliseconds -= calendar.get(Calendar.ZONE_OFFSET); return new Date(milliseconds); } private long getTimeWithoutZoneOffset(Date date) { Calendar calendar = new GregorianCalendar(Locale.ENGLISH); calendar.setTime(date); - return calendar.getTimeInMillis() - calendar.get(Calendar.ZONE_OFFSET); + return calendar.getTimeInMillis() + calendar.get(Calendar.ZONE_OFFSET); } }