Merge branch 'master' into incremental

This commit is contained in:
konsoletyper 2014-09-09 21:16:37 +04:00
commit 55c60ccc41
5 changed files with 282 additions and 49 deletions

View File

@ -166,7 +166,7 @@ public class JCLComparisonBuilder {
return false; return false;
} }
int slashIndex = name.lastIndexOf('/'); 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 { private void compareClass(InputStream input) throws IOException {

View File

@ -283,9 +283,9 @@ public final class TMath extends TObject {
return direction > start ? start + ulp(start) : start - ulp(start); 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) { if (start == direction) {
return direction; return start;
} }
return direction > start ? start + ulp(start) : start - ulp(start); return direction > start ? start + ulp(start) : start - ulp(start);
} }

View File

@ -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 <konsoletyper@gmail.com>
*/
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);
}
}

View File

@ -32,41 +32,41 @@ public class DateFormatTest {
@Test @Test
public void shortDateFormatHandled() throws ParseException { public void shortDateFormatHandled() throws ParseException {
DateFormat format = DateFormat.getDateInstance(DateFormat.SHORT, Locale.ENGLISH); DateFormat format = DateFormat.getDateInstance(DateFormat.SHORT, Locale.ENGLISH);
assertEquals("6/24/14", format.format(getDateWithZoneOffset(1403539200000L))); assertEquals("6/23/14", format.format(getDateWithZoneOffset(1403481600000L)));
assertEquals(1403539200000L, getTimeWithoutZoneOffset(format.parse("6/24/14"))); assertEquals(1403481600000L, getTimeWithoutZoneOffset(format.parse("6/23/14")));
} }
@Test @Test
public void mediumDateFormatHandled() throws ParseException { public void mediumDateFormatHandled() throws ParseException {
DateFormat format = DateFormat.getDateInstance(DateFormat.MEDIUM, Locale.ENGLISH); DateFormat format = DateFormat.getDateInstance(DateFormat.MEDIUM, Locale.ENGLISH);
assertEquals("Jun 24, 2014", format.format(getDateWithZoneOffset(1403539200000L))); assertEquals("Jun 23, 2014", format.format(getDateWithZoneOffset(1403481600000L)));
assertEquals(1403539200000L, getTimeWithoutZoneOffset(format.parse("Jun 24, 2014"))); assertEquals(1403481600000L, getTimeWithoutZoneOffset(format.parse("Jun 23, 2014")));
} }
@Test @Test
public void longDateFormatHandled() throws ParseException { public void longDateFormatHandled() throws ParseException {
DateFormat format = DateFormat.getDateInstance(DateFormat.LONG, Locale.ENGLISH); DateFormat format = DateFormat.getDateInstance(DateFormat.LONG, Locale.ENGLISH);
assertEquals("June 24, 2014", format.format(getDateWithZoneOffset(1403539200000L))); assertEquals("June 23, 2014", format.format(getDateWithZoneOffset(1403481600000L)));
assertEquals(1403539200000L, getTimeWithoutZoneOffset(format.parse("June 24, 2014"))); assertEquals(1403481600000L, getTimeWithoutZoneOffset(format.parse("June 23, 2014")));
} }
@Test @Test
public void fullDateFormatHandled() throws ParseException { public void fullDateFormatHandled() throws ParseException {
DateFormat format = DateFormat.getDateInstance(DateFormat.FULL, Locale.ENGLISH); DateFormat format = DateFormat.getDateInstance(DateFormat.FULL, Locale.ENGLISH);
assertEquals("Tuesday, June 24, 2014", format.format(getDateWithZoneOffset(1403539200000L))); assertEquals("Monday, June 23, 2014", format.format(getDateWithZoneOffset(1403481600000L)));
assertEquals(1403539200000L, getTimeWithoutZoneOffset(format.parse("Tuesday, June 24, 2014"))); assertEquals(1403481600000L, getTimeWithoutZoneOffset(format.parse("Monday, June 23, 2014")));
} }
private Date getDateWithZoneOffset(long milliseconds) { private Date getDateWithZoneOffset(long milliseconds) {
Calendar calendar = new GregorianCalendar(Locale.ENGLISH); Calendar calendar = new GregorianCalendar(Locale.ENGLISH);
calendar.setTimeInMillis(milliseconds); calendar.setTimeInMillis(milliseconds);
milliseconds += calendar.get(Calendar.ZONE_OFFSET); milliseconds -= calendar.get(Calendar.ZONE_OFFSET);
return new Date(milliseconds); return new Date(milliseconds);
} }
private long getTimeWithoutZoneOffset(Date date) { private long getTimeWithoutZoneOffset(Date date) {
Calendar calendar = new GregorianCalendar(Locale.ENGLISH); Calendar calendar = new GregorianCalendar(Locale.ENGLISH);
calendar.setTime(date); calendar.setTime(date);
return calendar.getTimeInMillis() - calendar.get(Calendar.ZONE_OFFSET); return calendar.getTimeInMillis() + calendar.get(Calendar.ZONE_OFFSET);
} }
} }

View File

@ -18,10 +18,7 @@ package org.teavm.classlib.java.text;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import java.text.ParseException; import java.text.ParseException;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.Calendar; import java.util.*;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.Locale;
import org.junit.Test; import org.junit.Test;
/** /**
@ -38,114 +35,114 @@ public class SimpleDateFormatTest {
@Test @Test
public void fieldsFormatted() { public void fieldsFormatted() {
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.ENGLISH); 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 @Test
public void fieldsParsed() throws ParseException { public void fieldsParsed() throws ParseException {
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.ENGLISH); 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 @Test
public void eraHandled() throws ParseException { public void eraHandled() throws ParseException {
SimpleDateFormat format = new SimpleDateFormat("G yyyy-MM-dd HH:mm:ss", Locale.ENGLISH); 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("AD 2014-06-24 09:33:49", format.format(getDateWithZoneOffset(1403602429504L)));
assertEquals(1403602429000L, getTimeWithoutZoneOffset(format.parse("AD 2014-06-24 17:33:49"))); assertEquals(1403602429000L, getTimeWithoutZoneOffset(format.parse("AD 2014-06-24 09:33:49")));
} }
@Test @Test
public void shortYearHandled() throws ParseException { public void shortYearHandled() throws ParseException {
SimpleDateFormat format = new SimpleDateFormat("yy-MM-dd HH:mm:ss", Locale.ENGLISH); SimpleDateFormat format = new SimpleDateFormat("yy-MM-dd HH:mm:ss", Locale.ENGLISH);
assertEquals("14-06-24 17:33:49", format.format(getDateWithZoneOffset(1403602429504L))); assertEquals("14-06-24 09:33:49", format.format(getDateWithZoneOffset(1403602429504L)));
assertEquals(1403602429000L, getTimeWithoutZoneOffset(format.parse("14-06-24 17:33:49"))); assertEquals(1403602429000L, getTimeWithoutZoneOffset(format.parse("14-06-24 09:33:49")));
} }
@Test @Test
public void weekInYearHandled() throws ParseException { public void weekInYearHandled() throws ParseException {
long day = 24 * 3600 * 1000; long day = 24 * 3600 * 1000;
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss www", Locale.ENGLISH); 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-24 09:33:49 026", format.format(getDateWithZoneOffset(1403602429504L)));
assertEquals("2014-06-28 17:33:49 026", format.format(getDateWithZoneOffset(1403602429504L + day * 4))); assertEquals("2014-06-28 09:33:49 026", format.format(getDateWithZoneOffset(1403602429504L + day * 4)));
assertEquals("2014-06-29 17:33:49 027", format.format(getDateWithZoneOffset(1403602429504L + day * 5))); assertEquals("2014-06-29 09:33:49 027", format.format(getDateWithZoneOffset(1403602429504L + day * 5)));
assertEquals(1403602429000L, getTimeWithoutZoneOffset(format.parse("2014-06-24 17:33:49 026"))); assertEquals(1403602429000L, getTimeWithoutZoneOffset(format.parse("2014-06-24 09:33:49 026")));
assertEquals(1403602429000L + day * 4, getTimeWithoutZoneOffset(format.parse("2014-06-28 17: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 17:33:49 027"))); assertEquals(1403602429000L + day * 5, getTimeWithoutZoneOffset(format.parse("2014-06-29 09:33:49 027")));
} }
@Test @Test
public void weekInMonthHandled() throws ParseException { public void weekInMonthHandled() throws ParseException {
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss WW", Locale.ENGLISH); 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("2014-06-24 09:33:49 04", format.format(getDateWithZoneOffset(1403602429504L)));
assertEquals(1403602429000L, getTimeWithoutZoneOffset(format.parse("2014-06-24 17:33:49 04"))); assertEquals(1403602429000L, getTimeWithoutZoneOffset(format.parse("2014-06-24 09:33:49 04")));
} }
@Test @Test
public void dayInYearHandled() throws ParseException { public void dayInYearHandled() throws ParseException {
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss DD", Locale.ENGLISH); 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("2014-06-24 09:33:49 175", format.format(getDateWithZoneOffset(1403602429504L)));
assertEquals(1403602429000L, getTimeWithoutZoneOffset(format.parse("2014-06-24 17:33:49 175"))); assertEquals(1403602429000L, getTimeWithoutZoneOffset(format.parse("2014-06-24 09:33:49 175")));
} }
@Test @Test
public void weekdayInMonthHandled() throws ParseException { public void weekdayInMonthHandled() throws ParseException {
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss F", Locale.ENGLISH); 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("2014-06-24 09:33:49 4", format.format(getDateWithZoneOffset(1403602429504L)));
assertEquals(1403602429000L, getTimeWithoutZoneOffset(format.parse("2014-06-24 17:33:49 4"))); assertEquals(1403602429000L, getTimeWithoutZoneOffset(format.parse("2014-06-24 09:33:49 4")));
} }
@Test @Test
public void shortWeekdayHandled() throws ParseException { public void shortWeekdayHandled() throws ParseException {
SimpleDateFormat format = new SimpleDateFormat("E yyyy-MM-dd HH:mm:ss", Locale.ENGLISH); 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("Tue 2014-06-24 09:33:49", format.format(getDateWithZoneOffset(1403602429504L)));
assertEquals(1403602429000L, getTimeWithoutZoneOffset(format.parse("Tue 2014-06-24 17:33:49"))); assertEquals(1403602429000L, getTimeWithoutZoneOffset(format.parse("Tue 2014-06-24 09:33:49")));
} }
@Test @Test
public void longWeekdayHandled() throws ParseException { public void longWeekdayHandled() throws ParseException {
SimpleDateFormat format = new SimpleDateFormat("EEEE, yyyy-MM-dd HH:mm:ss", Locale.ENGLISH); 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("Tuesday, 2014-06-24 09:33:49", format.format(getDateWithZoneOffset(1403602429504L)));
assertEquals(1403602429000L, getTimeWithoutZoneOffset(format.parse("Tuesday, 2014-06-24 17:33:49"))); assertEquals(1403602429000L, getTimeWithoutZoneOffset(format.parse("Tuesday, 2014-06-24 09:33:49")));
} }
@Test @Test
public void numericWeekdayHandled() throws ParseException { public void numericWeekdayHandled() throws ParseException {
SimpleDateFormat format = new SimpleDateFormat("u yyyy-MM-dd HH:mm:ss", Locale.ENGLISH); 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("2 2014-06-24 09:33:49", format.format(getDateWithZoneOffset(1403602429504L)));
assertEquals(1403602429000L, getTimeWithoutZoneOffset(format.parse("2 2014-06-24 17:33:49"))); assertEquals(1403602429000L, getTimeWithoutZoneOffset(format.parse("2 2014-06-24 09:33:49")));
} }
@Test @Test
public void amPmHandled() throws ParseException { public void amPmHandled() throws ParseException {
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd 'at' hh:mm:ss a", Locale.ENGLISH); 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("2014-06-24 at 09:33:49 AM", format.format(getDateWithZoneOffset(1403602429504L)));
assertEquals(1403602429000L, getTimeWithoutZoneOffset(format.parse("2014-06-24 at 05:33:49 PM"))); assertEquals(1403602429000L, getTimeWithoutZoneOffset(format.parse("2014-06-24 at 09:33:49 AM")));
} }
@Test @Test
public void shortMonthHandled() throws ParseException { public void shortMonthHandled() throws ParseException {
SimpleDateFormat format = new SimpleDateFormat("MMM, dd yyyy HH:mm:ss", Locale.ENGLISH); SimpleDateFormat format = new SimpleDateFormat("MMM, dd yyyy HH:mm:ss", Locale.ENGLISH);
assertEquals("Jun, 24 2014 17:33:49", format.format(getDateWithZoneOffset(1403602429504L))); assertEquals("Jun, 24 2014 09:33:49", format.format(getDateWithZoneOffset(1403602429504L)));
assertEquals(1403602429000L, getTimeWithoutZoneOffset(format.parse("Jun, 24 2014 17:33:49"))); assertEquals(1403602429000L, getTimeWithoutZoneOffset(format.parse("Jun, 24 2014 09:33:49")));
} }
@Test @Test
public void longMonthHandled() throws ParseException { public void longMonthHandled() throws ParseException {
SimpleDateFormat format = new SimpleDateFormat("MMMM, dd yyyy HH:mm:ss", Locale.ENGLISH); SimpleDateFormat format = new SimpleDateFormat("MMMM, dd yyyy HH:mm:ss", Locale.ENGLISH);
assertEquals("June, 24 2014 17:33:49", format.format(getDateWithZoneOffset(1403602429504L))); assertEquals("June, 24 2014 09:33:49", format.format(getDateWithZoneOffset(1403602429504L)));
assertEquals(1403602429000L, getTimeWithoutZoneOffset(format.parse("June, 24 2014 17:33:49"))); assertEquals(1403602429000L, getTimeWithoutZoneOffset(format.parse("June, 24 2014 09:33:49")));
} }
private Date getDateWithZoneOffset(long milliseconds) { private Date getDateWithZoneOffset(long milliseconds) {
Calendar calendar = new GregorianCalendar(Locale.ENGLISH); Calendar calendar = new GregorianCalendar(Locale.ENGLISH);
calendar.setTimeInMillis(milliseconds); calendar.setTimeInMillis(milliseconds);
milliseconds += calendar.get(Calendar.ZONE_OFFSET); milliseconds -= calendar.get(Calendar.ZONE_OFFSET);
return new Date(milliseconds); return new Date(milliseconds);
} }
private long getTimeWithoutZoneOffset(Date date) { private long getTimeWithoutZoneOffset(Date date) {
Calendar calendar = new GregorianCalendar(Locale.ENGLISH); Calendar calendar = new GregorianCalendar(Locale.ENGLISH);
calendar.setTime(date); calendar.setTime(date);
return calendar.getTimeInMillis() - calendar.get(Calendar.ZONE_OFFSET); return calendar.getTimeInMillis() + calendar.get(Calendar.ZONE_OFFSET);
} }
} }