Fix build. Apply rules to some classes of teavm-classlib

This commit is contained in:
Alexey Andreev 2015-07-23 15:31:49 +03:00
parent 4548705620
commit bda49b95bd
161 changed files with 2296 additions and 2022 deletions

View File

@ -13,14 +13,13 @@
<module name="EmptyBlock">
<property name="tokens" value="LITERAL_DO, LITERAL_ELSE, LITERAL_FINALLY, LITERAL_IF,
LITERAL_FOR, LITERAL_TRY, LITERAL_WHILE, STATIC_INIT"/>
<property name="option" value="text"/>
</module>
<module name="LeftCurly"/>
<module name="NeedBraces"/>
<module name="RightCurly"/>
<module name="FinalClass"/>
<module name="InterfaceIsType"/>
<module name="HideUtilityClassConstructor"/>
<module name="MutableException"/>
<module name="EmptyStatement"/>
<module name="EqualsHashCode"/>
<module name="InnerAssignment"/>
@ -49,7 +48,9 @@
<module name="LocalFinalVariableName"/>
<module name="LocalVariableName"/>
<module name="MemberName"/>
<module name="MethodName"/>
<module name="MethodName">
<property name="format" value="^(([A-Z][A-Z0-9]+)|([a-z][a-z0-9]*))([A-Z][a-z0-9]*)*"/>
</module>
<module name="MethodTypeParameterName"/>
<module name="PackageName"/>
<module name="ParameterName"/>

View File

@ -1,5 +1,5 @@
/\*
\* Copyright 2[0-9]{3} .+
\* Copyright 2[0-9]{3}(\-2[0-9]{3})? .+
\*
\* Licensed under the Apache License, Version 2.0 \(the "License"\);
\* you may not use this file except in compliance with the License.

14
pom.xml
View File

@ -123,27 +123,27 @@
<dependency>
<groupId>org.ow2.asm</groupId>
<artifactId>asm-debug-all</artifactId>
<version>5.0.3</version>
<version>5.0.4</version>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-plugin-api</artifactId>
<version>3.0</version>
<version>3.3.3</version>
</dependency>
<dependency>
<groupId>org.apache.maven.plugin-tools</groupId>
<artifactId>maven-plugin-annotations</artifactId>
<version>3.0</version>
<version>3.3</version>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-core</artifactId>
<version>3.0</version>
<version>3.3.3</version>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-artifact</artifactId>
<version>3.0</version>
<version>3.3.3</version>
</dependency>
<dependency>
<groupId>javax.websocket</groupId>
@ -165,11 +165,13 @@
<artifactId>slf4j-api</artifactId>
<version>${slf4j.version}</version>
</dependency>
<!--
<dependency>
<groupId>org.checkerframework</groupId>
<artifactId>checker</artifactId>
<version>${checker.version}</version>
</dependency>
-->
</dependencies>
</dependencyManagement>
@ -225,7 +227,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<version>2.11</version>
<version>2.15</version>
<executions>
<execution>
<id>validate</id>

View File

@ -78,6 +78,15 @@
<build>
<plugins>
<!--
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<configuration>
<configLocation>../checkstyle.xml</configLocation>
</configuration>
</plugin>
-->
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>

View File

@ -28,7 +28,10 @@ package org.teavm.classlib.impl;
*
* @author Alexey Andreev
*/
public class Base46 {
public final class Base46 {
private Base46() {
}
public static void encodeUnsigned(StringBuilder sb, int number) {
boolean hasMore;
do {

View File

@ -76,8 +76,8 @@ public class CountriesGenerator implements MetadataGenerator {
while (index < row.length()) {
next = row.indexOf('"', index);
if (next == -1) {
throw new IllegalStateException("Syntax error at row " + rowIndex +
": closing quote not found");
throw new IllegalStateException("Syntax error at row " + rowIndex
+ ": closing quote not found");
}
if (next + 1 == row.length() || row.charAt(next + 1) != '"') {
sb.append(row.substring(index, next));
@ -87,8 +87,8 @@ public class CountriesGenerator implements MetadataGenerator {
index = next + 2;
}
if (index < row.length() && row.charAt(index) != ',') {
throw new IllegalStateException("Syntax error at row " + rowIndex + ": closing quote must be " +
"followed by either line separator or comma");
throw new IllegalStateException("Syntax error at row " + rowIndex + ": closing quote must be "
+ "followed by either line separator or comma");
}
values.add(sb.toString());
} else {

View File

@ -25,6 +25,9 @@ import org.teavm.platform.metadata.StringResource;
* @author Alexey Andreev
*/
public final class CurrencyHelper {
private CurrencyHelper() {
}
@MetadataProvider(CurrenciesGenerator.class)
public static native ResourceArray<CurrencyResource> getCurrencies();

View File

@ -100,8 +100,8 @@ class JCLComparisonVisitor extends ClassVisitor {
if ((access & Opcodes.ACC_ABSTRACT) == 0 && method.hasModifier(ElementModifier.ABSTRACT)) {
item.status = JCLStatus.MISSING;
} else {
item.status = method.getOwnerName().equals(classReader.getName()) ?
JCLStatus.FOUND : JCLStatus.PARTIAL;
item.status = method.getOwnerName().equals(classReader.getName())
? JCLStatus.FOUND : JCLStatus.PARTIAL;
}
}
item.visibility = (access & Opcodes.ACC_PROTECTED) != 0 ? JCLVisibility.PROTECTED : JCLVisibility.PUBLIC;

View File

@ -25,7 +25,7 @@ package org.teavm.classlib.impl.tz;
* @author Brian S O'Neill
* @since 1.0
*/
public class CachedDateTimeZone extends StorableDateTimeZone {
public final class CachedDateTimeZone extends StorableDateTimeZone {
private static final int cInfoCacheMask;
@ -124,7 +124,8 @@ public class CachedDateTimeZone extends StorableDateTimeZone {
break;
}
periodStart = next;
chain = (chain.iNextInfo = new Info(iZone, periodStart));
chain.iNextInfo = new Info(iZone, periodStart);
chain = chain.iNextInfo;
}
return info;

View File

@ -99,17 +99,10 @@ public class DateTimeZoneBuilder {
* dayOfWeek when true, retreat when false.
* @param millisOfDay additional precision for specifying time of day of cutover
*/
public DateTimeZoneBuilder addCutover(int year,
char mode,
int monthOfYear,
int dayOfMonth,
int dayOfWeek,
boolean advanceDayOfWeek,
int millisOfDay)
{
public DateTimeZoneBuilder addCutover(int year, char mode, int monthOfYear, int dayOfMonth, int dayOfWeek,
boolean advanceDayOfWeek, int millisOfDay) {
if (iRuleSets.size() > 0) {
OfYear ofYear = new OfYear
(mode, monthOfYear, dayOfMonth, dayOfWeek, advanceDayOfWeek, millisOfDay);
OfYear ofYear = new OfYear(mode, monthOfYear, dayOfMonth, dayOfWeek, advanceDayOfWeek, millisOfDay);
RuleSet lastRuleSet = iRuleSets.get(iRuleSets.size() - 1);
lastRuleSet.setUpperLimit(year, ofYear);
}
@ -162,11 +155,9 @@ public class DateTimeZoneBuilder {
int dayOfMonth,
int dayOfWeek,
boolean advanceDayOfWeek,
int millisOfDay)
{
int millisOfDay) {
if (fromYear <= toYear) {
OfYear ofYear = new OfYear
(mode, monthOfYear, dayOfMonth, dayOfWeek, advanceDayOfWeek, millisOfDay);
OfYear ofYear = new OfYear(mode, monthOfYear, dayOfMonth, dayOfWeek, advanceDayOfWeek, millisOfDay);
Recurrence recurrence = new Recurrence(ofYear, saveMillis);
Rule rule = new Rule(recurrence, fromYear, toYear);
getLastRuleSet().addRule(rule);
@ -302,12 +293,7 @@ public class DateTimeZoneBuilder {
final boolean iAdvance;
final int iMillisOfDay;
OfYear(char mode,
int monthOfYear,
int dayOfMonth,
int dayOfWeek, boolean advanceDayOfWeek,
int millisOfDay)
{
OfYear(char mode, int monthOfYear, int dayOfMonth, int dayOfWeek, boolean advanceDayOfWeek, int millisOfDay) {
if (mode != 'u' && mode != 'w' && mode != 's') {
throw new IllegalArgumentException("Unknown mode: " + mode);
}
@ -678,8 +664,7 @@ public class DateTimeZoneBuilder {
if (other == null) {
return true;
}
return iMillis > other.iMillis &&
iWallOffset != other.iWallOffset;
return iMillis > other.iMillis && iWallOffset != other.iWallOffset;
}
}
@ -886,8 +871,7 @@ public class DateTimeZoneBuilder {
if (iRules.size() == 2) {
Rule startRule = iRules.get(0);
Rule endRule = iRules.get(1);
if (startRule.getToYear() == Integer.MAX_VALUE &&
endRule.getToYear() == Integer.MAX_VALUE) {
if (startRule.getToYear() == Integer.MAX_VALUE && endRule.getToYear() == Integer.MAX_VALUE) {
// With exactly two infinitely recurring rules left, a
// simple DSTZone can be formed.
@ -937,11 +921,11 @@ public class DateTimeZoneBuilder {
Recurrence startRecurrence = iStartRecurrence;
Recurrence endRecurrence = iEndRecurrence;
long start, end;
long start;
long end;
try {
start = startRecurrence.next
(instant, standardOffset, endRecurrence.getSaveMillis());
start = startRecurrence.next(instant, standardOffset, endRecurrence.getSaveMillis());
if (instant > 0 && start < 0) {
// Overflowed.
start = instant;
@ -955,8 +939,7 @@ public class DateTimeZoneBuilder {
}
try {
end = endRecurrence.next
(instant, standardOffset, startRecurrence.getSaveMillis());
end = endRecurrence.next(instant, standardOffset, startRecurrence.getSaveMillis());
if (instant > 0 && end < 0) {
// Overflowed.
end = instant;
@ -982,11 +965,11 @@ public class DateTimeZoneBuilder {
Recurrence startRecurrence = iStartRecurrence;
Recurrence endRecurrence = iEndRecurrence;
long start, end;
long start;
long end;
try {
start = startRecurrence.previous
(instant, standardOffset, endRecurrence.getSaveMillis());
start = startRecurrence.previous(instant, standardOffset, endRecurrence.getSaveMillis());
if (instant < 0 && start > 0) {
// Overflowed.
start = instant;
@ -1000,8 +983,7 @@ public class DateTimeZoneBuilder {
}
try {
end = endRecurrence.previous
(instant, standardOffset, startRecurrence.getSaveMillis());
end = endRecurrence.previous(instant, standardOffset, startRecurrence.getSaveMillis());
if (instant < 0 && end > 0) {
// Overflowed.
end = instant;
@ -1022,11 +1004,11 @@ public class DateTimeZoneBuilder {
Recurrence startRecurrence = iStartRecurrence;
Recurrence endRecurrence = iEndRecurrence;
long start, end;
long start;
long end;
try {
start = startRecurrence.next
(instant, standardOffset, endRecurrence.getSaveMillis());
start = startRecurrence.next(instant, standardOffset, endRecurrence.getSaveMillis());
} catch (IllegalArgumentException e) {
// Overflowed.
start = instant;
@ -1036,8 +1018,7 @@ public class DateTimeZoneBuilder {
}
try {
end = endRecurrence.next
(instant, standardOffset, startRecurrence.getSaveMillis());
end = endRecurrence.next(instant, standardOffset, startRecurrence.getSaveMillis());
} catch (IllegalArgumentException e) {
// Overflowed.
end = instant;
@ -1100,8 +1081,7 @@ public class DateTimeZoneBuilder {
last = tr;
}
return new PrecalculatedZone
((outputID ? id : ""), trans, wallOffsets, standardOffsets, tailZone);
return new PrecalculatedZone(outputID ? id : "", trans, wallOffsets, standardOffsets, tailZone);
}
// All array fields have the same length.
@ -1116,9 +1096,8 @@ public class DateTimeZoneBuilder {
/**
* Constructor used ONLY for valid input, loaded via static methods.
*/
private PrecalculatedZone(String id, long[] transitions, int[] wallOffsets,
int[] standardOffsets, DSTZone tailZone)
{
private PrecalculatedZone(String id, long[] transitions, int[] wallOffsets, int[] standardOffsets,
DSTZone tailZone) {
super(id);
iTransitions = transitions;
iWallOffsets = wallOffsets;

View File

@ -33,9 +33,12 @@ import org.teavm.platform.metadata.ResourceMap;
*
* @author Alexey Andreev
*/
public class DateTimeZoneProvider {
public final class DateTimeZoneProvider {
private static Map<String, DateTimeZone> cache = new HashMap<>();
private DateTimeZoneProvider() {
}
public static DateTimeZone getTimeZone(String id) {
if (!cache.containsKey(id)) {
cache.put(id, createTimeZone(id));

View File

@ -156,12 +156,10 @@ public class ZoneInfoCompiler {
if (offset == nextOffset) {
System.out.println("*d* Error in " + tz.getID() + " "
+ new DateTime(millis,
ISOChronology.getInstanceUTC()));
+ new DateTime(millis, ISOChronology.getInstanceUTC()));
return false;
}
transitions.add(Long.valueOf(millis));
offset = nextOffset;
@ -184,10 +182,8 @@ public class ZoneInfoCompiler {
if (trans - 1 != millis) {
System.out.println("*r* Error in " + tz.getID() + " "
+ new DateTime(millis,
ISOChronology.getInstanceUTC()) + " != "
+ new DateTime(trans - 1,
ISOChronology.getInstanceUTC()));
+ new DateTime(millis, ISOChronology.getInstanceUTC()) + " != "
+ new DateTime(trans - 1, ISOChronology.getInstanceUTC()));
return false;
}
@ -237,8 +233,8 @@ public class ZoneInfoCompiler {
String alias = iGoodLinks.get(i + 1);
Zone sourceZone = sourceMap.get(baseId);
if (sourceZone == null) {
/*throw new RuntimeException("Cannot find source zone '" + baseId + "' to link alias '" +
alias + "' to");*/
throw new RuntimeException("Cannot find source zone '" + baseId + "' to link alias '"
+ alias + "' to");
} else {
DateTimeZoneBuilder builder = new DateTimeZoneBuilder();
sourceZone.addToBuilder(builder, iRuleSets);
@ -257,10 +253,10 @@ public class ZoneInfoCompiler {
String alias = iBackLinks.get(i + 1);
StorableDateTimeZone tz = map.get(id);
if (tz == null) {
/*if (pass > 0) {
throw new RuntimeException("Cannot find time zone '" + id + "' to link alias '" +
alias + "' to");
}*/
if (pass > 0) {
throw new RuntimeException("Cannot find time zone '" + id + "' to link alias '"
+ alias + "' to");
}
} else {
map.put(alias, new AliasDateTimeZone(alias, tz));
}
@ -404,10 +400,9 @@ public class ZoneInfoCompiler {
if (month == 12 && day == 31) {
millis = parseTime("23:59:59.999");
} else {
LocalDate date = (day == -1 ?
new LocalDate(2001, month, 1).plusMonths(1) :
new LocalDate(2001, month, day).plusDays(1));
advance = (day != -1 && dayOfWeek != 0);
LocalDate date = day == -1 ? new LocalDate(2001, month, 1).plusMonths(1)
: new LocalDate(2001, month, day).plusDays(1);
advance = day != -1 && dayOfWeek != 0;
month = date.getMonthOfYear();
day = date.getDayOfMonth();
if (dayOfWeek != 0) {
@ -459,13 +454,9 @@ public class ZoneInfoCompiler {
@Override
public String toString() {
return
"MonthOfYear: " + iMonthOfYear + "\n" +
"DayOfMonth: " + iDayOfMonth + "\n" +
"DayOfWeek: " + iDayOfWeek + "\n" +
"AdvanceDayOfWeek: " + iAdvanceDayOfWeek + "\n" +
"MillisOfDay: " + iMillisOfDay + "\n" +
"ZoneChar: " + iZoneChar + "\n";
return "MonthOfYear: " + iMonthOfYear + "\n" + "DayOfMonth: " + iDayOfMonth + "\n" + "DayOfWeek: "
+ iDayOfWeek + "\n" + "AdvanceDayOfWeek: " + iAdvanceDayOfWeek + "\n" + "MillisOfDay: "
+ iMillisOfDay + "\n" + "ZoneChar: " + iZoneChar + "\n";
}
}
@ -500,15 +491,9 @@ public class ZoneInfoCompiler {
@Override
public String toString() {
return
"[Rule]\n" +
"Name: " + iName + "\n" +
"FromYear: " + iFromYear + "\n" +
"ToYear: " + iToYear + "\n" +
"Type: " + iType + "\n" +
iDateTimeOfYear +
"SaveMillis: " + iSaveMillis + "\n" +
"LetterS: " + iLetterS + "\n";
return "[Rule]\n" + "Name: " + iName + "\n" + "FromYear: " + iFromYear + "\n" + "ToYear: " + iToYear + "\n"
+ "Type: " + iType + "\n" + iDateTimeOfYear + "SaveMillis: " + iSaveMillis + "\n" + "LetterS: "
+ iLetterS + "\n";
}
}
@ -595,10 +580,7 @@ public class ZoneInfoCompiler {
addToBuilder(this, builder, ruleSets);
}
private static void addToBuilder(Zone zone,
DateTimeZoneBuilder builder,
Map<String, RuleSet> ruleSets)
{
private static void addToBuilder(Zone zone, DateTimeZoneBuilder builder, Map<String, RuleSet> ruleSets) {
for (; zone != null; zone = zone.iNext) {
builder.setStandardOffset(zone.iOffsetMillis);
@ -609,12 +591,10 @@ public class ZoneInfoCompiler {
// Check if iRules actually just refers to a savings.
int saveMillis = parseTime(zone.iRules);
builder.setFixedSavings(zone.iFormat, saveMillis);
}
catch (Exception e) {
} catch (Exception e) {
RuleSet rs = ruleSets.get(zone.iRules);
if (rs == null) {
throw new IllegalArgumentException
("Rules not found: " + zone.iRules);
throw new IllegalArgumentException("Rules not found: " + zone.iRules);
}
rs.addRecurring(builder);
}
@ -630,14 +610,9 @@ public class ZoneInfoCompiler {
@Override
public String toString() {
String str =
"[Zone]\n" +
"Name: " + iName + "\n" +
"OffsetMillis: " + iOffsetMillis + "\n" +
"Rules: " + iRules + "\n" +
"Format: " + iFormat + "\n" +
"UntilYear: " + iUntilYear + "\n" +
iUntilDateTimeOfYear;
String str = "[Zone]\n" + "Name: " + iName + "\n" + "OffsetMillis: " + iOffsetMillis + "\n" + "Rules: "
+ iRules + "\n" + "Format: " + iFormat + "\n" + "UntilYear: " + iUntilYear + "\n"
+ iUntilDateTimeOfYear;
if (iNext == null) {
return str;

View File

@ -25,7 +25,7 @@ public class CLDRDecimalData {
int listSeparator;
int perMille;
int percent;
String NaN;
String nan;
String infinity;
int minusSign;
int monetaryDecimalSeparator;
@ -52,7 +52,7 @@ public class CLDRDecimalData {
}
public String getNaN() {
return NaN;
return nan;
}
public String getInfinity() {

View File

@ -23,7 +23,10 @@ import org.teavm.platform.metadata.*;
*
* @author Alexey Andreev
*/
public class CLDRHelper {
public final class CLDRHelper {
private CLDRHelper() {
}
public static String getCode(String language, String country) {
return !country.isEmpty() ? language + "-" + country : language;
}
@ -90,8 +93,9 @@ public class CLDRHelper {
private static String[] resolveDateFormatSymbols(ResourceMap<ResourceArray<StringResource>> map, String language,
String country) {
String localeCode = getCode(language, country);
ResourceArray<StringResource> arrayRes = map.has(localeCode) ? map.get(localeCode) :
map.has(language) ? map.get(language) : map.get("root");
ResourceArray<StringResource> arrayRes = map.has(localeCode)
? map.get(localeCode)
: map.has(language) ? map.get(language) : map.get("root");
String[] result = new String[arrayRes.size()];
for (int i = 0; i < result.length; ++i) {
result[i] = arrayRes.get(i).getValue();
@ -198,16 +202,16 @@ public class CLDRHelper {
private static String resolveFormatSymbols(ResourceMap<StringResource> map, String language, String country) {
String localeCode = getCode(language, country);
StringResource res = map.has(localeCode) ? map.get(localeCode) : map.has(language) ? map.get(language) :
map.get("root");
StringResource res = map.has(localeCode) ? map.get(localeCode) : map.has(language) ? map.get(language)
: map.get("root");
return res.getValue();
}
public static DecimalData resolveDecimalData(String language, String country) {
ResourceMap<DecimalData> map = getDecimalDataMap();
String localeCode = getCode(language, country);
return map.has(localeCode) ? map.get(localeCode) : map.has(language) ? map.get(language) :
map.get("root");
return map.has(localeCode) ? map.get(localeCode) : map.has(language) ? map.get(language)
: map.get("root");
}
@MetadataProvider(DecimalMetadataGenerator.class)

View File

@ -15,15 +15,23 @@
*/
package org.teavm.classlib.impl.unicode;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.*;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.Set;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;
/**
*
@ -224,7 +232,7 @@ public class CLDRReader {
locale.decimalData.exponentSeparator = symbolsJson.get("exponential").getAsString();
locale.decimalData.perMille = symbolsJson.get("perMille").getAsString().charAt(0);
locale.decimalData.infinity = symbolsJson.get("infinity").getAsString();
locale.decimalData.NaN = symbolsJson.get("nan").getAsString();
locale.decimalData.nan = symbolsJson.get("nan").getAsString();
JsonObject numberJson = numbersJson.get("decimalFormats-numberSystem-" + numbering).getAsJsonObject();
locale.numberFormat = numberJson.get("standard").getAsString();

View File

@ -28,29 +28,17 @@ public class DateSymbolsMetadataGenerator implements MetadataGenerator {
public Resource generateMetadata(MetadataGeneratorContext context, MethodReference method) {
switch (method.getName()) {
case "getErasMap":
return generateSymbols(context, new ResourceExtractor() {
@Override public String[] extract(CLDRLocale locale) { return locale.getEras(); }
});
return generateSymbols(context, locale -> locale.getEras());
case "getAmPmMap":
return generateSymbols(context, new ResourceExtractor() {
@Override public String[] extract(CLDRLocale locale) { return locale.getDayPeriods(); }
});
return generateSymbols(context, locale -> locale.getDayPeriods());
case "getMonthMap":
return generateSymbols(context, new ResourceExtractor() {
@Override public String[] extract(CLDRLocale locale) { return locale.getMonths(); }
});
return generateSymbols(context, locale -> locale.getMonths());
case "getShortMonthMap":
return generateSymbols(context, new ResourceExtractor() {
@Override public String[] extract(CLDRLocale locale) { return locale.getShortMonths(); }
});
return generateSymbols(context, locale -> locale.getShortMonths());
case "getWeekdayMap":
return generateSymbols(context, new ResourceExtractor() {
@Override public String[] extract(CLDRLocale locale) { return locale.getWeekdays(); }
});
return generateSymbols(context, locale -> locale.getWeekdays());
case "getShortWeekdayMap":
return generateSymbols(context, new ResourceExtractor() {
@Override public String[] extract(CLDRLocale locale) { return locale.getShortWeekdays(); }
});
return generateSymbols(context, locale -> locale.getShortWeekdays());
default:
throw new AssertionError("Unsupported method: " + method);
}
@ -71,7 +59,7 @@ public class DateSymbolsMetadataGenerator implements MetadataGenerator {
return result;
}
private static interface ResourceExtractor {
private interface ResourceExtractor {
String[] extract(CLDRLocale locale);
}
}

View File

@ -24,7 +24,10 @@ import org.teavm.classlib.impl.CharFlow;
*
* @author Alexey Andreev
*/
public class UnicodeHelper {
public final class UnicodeHelper {
private UnicodeHelper() {
}
static char hexDigit(int value) {
return value < 10 ? (char) ('0' + value) : (char) ('A' + value);
}

View File

@ -30,7 +30,7 @@ import org.teavm.common.IntegerArray;
*
* @author Alexey Andreev
*/
public class UnicodeSupport {
public final class UnicodeSupport {
private static AtomicBoolean filled = new AtomicBoolean();
private static volatile CountDownLatch latch = new CountDownLatch(1);
private static int[] digitValues;
@ -70,6 +70,9 @@ public class UnicodeSupport {
classMap.put("Pf", Character.FINAL_QUOTE_PUNCTUATION);
}
private UnicodeSupport() {
}
private static void parseUnicodeData() {
IntegerArray digitValues = new IntegerArray(4096);
IntegerArray classes = new IntegerArray(65536);

View File

@ -1,10 +1,9 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You 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
* Copyright 2015 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
*
@ -78,13 +77,15 @@ public class TBufferedInputStream extends TFilterInputStream {
System.arraycopy(localBuf, 0, newbuf, 0, localBuf.length);
// Reassign buf, which will invalidate any local references
// FIXME: what if buf was null?
localBuf = buf = newbuf;
buf = newbuf;
localBuf = buf;
} else if (markpos > 0) {
System.arraycopy(localBuf, markpos, localBuf, 0, localBuf.length - markpos);
}
/* Set the new position and mark position */
pos -= markpos;
count = markpos = 0;
count = 0;
markpos = 0;
int bytesread = localIn.read(localBuf, pos, localBuf.length - pos);
count = bytesread <= 0 ? pos : pos + bytesread;
return bytesread;
@ -245,7 +246,7 @@ public class TBufferedInputStream extends TFilterInputStream {
return amount;
}
// Couldn't get all the bytes, skip what we read
read += (count - pos);
read += count - pos;
pos = count;
return read;
}

View File

@ -122,7 +122,7 @@ public class TBufferedReader extends TReader {
index += n;
return n;
} else {
n -= (count - index);
n -= count - index;
long skipped = innerReader.skip(n);
if (skipped == n) {
fillBuffer(0);

View File

@ -23,5 +23,5 @@ import org.teavm.classlib.java.lang.TAutoCloseable;
*/
public interface TCloseable extends TAutoCloseable {
@Override
public void close() throws TIOException;
void close() throws TIOException;
}

View File

@ -61,7 +61,9 @@ public class TDataInputStream extends TFilterInputStream implements TDataInput {
int offset = 0;
while (offset < count) {
int bytesRead = in.read(buff, offset, count - offset);
if(bytesRead == -1) return bytesRead;
if (bytesRead == -1) {
return bytesRead;
}
offset += bytesRead;
}
return offset;
@ -167,10 +169,10 @@ public class TDataInputStream extends TFilterInputStream implements TDataInput {
if (readToBuff(8) < 0) {
throw new TEOFException();
}
int i1 = ((buff[0] & 0xff) << 24) | ((buff[1] & 0xff) << 16) |
((buff[2] & 0xff) << 8) | (buff[3] & 0xff);
int i2 = ((buff[4] & 0xff) << 24) | ((buff[5] & 0xff) << 16) |
((buff[6] & 0xff) << 8) | (buff[7] & 0xff);
int i1 = ((buff[0] & 0xff) << 24) | ((buff[1] & 0xff) << 16)
| ((buff[2] & 0xff) << 8) | (buff[3] & 0xff);
int i2 = ((buff[4] & 0xff) << 24) | ((buff[5] & 0xff) << 16)
| ((buff[6] & 0xff) << 8) | (buff[7] & 0xff);
return ((i1 & 0xffffffffL) << 32) | (i2 & 0xffffffffL);
}
@ -223,8 +225,12 @@ public class TDataInputStream extends TFilterInputStream implements TDataInput {
@Override
public final int skipBytes(int count) throws TIOException {
int skipped = 0;
long skip;
while (skipped < count && (skip = in.skip(count - skipped)) != 0) {
while (skipped < count) {
long skip = in.skip(count - skipped);
if (skip == 0) {
break;
}
skipped += skip;
}
if (skipped < 0) {
@ -241,9 +247,10 @@ public class TDataInputStream extends TFilterInputStream implements TDataInput {
while (count < utfSize) {
char ch = (char) buf[offset + count++];
out[s] = ch;
a = out[s];
if (ch < '\u0080') {
s++;
} else if (((a = out[s]) & 0xe0) == 0xc0) {
} else if ((a & 0xe0) == 0xc0) {
if (count >= utfSize) {
throw new TUTFDataFormatException(TString.wrap("End of stream reached"));
}

View File

@ -1,10 +1,9 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You 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
* Copyright 2015 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
*
@ -14,7 +13,6 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.teavm.classlib.java.io;
import org.teavm.classlib.java.lang.*;
@ -23,7 +21,7 @@ public class TDataOutputStream extends TFilterOutputStream implements TDataOutpu
* The number of bytes written out so far.
*/
protected int written;
byte buff[];
byte[] buff;
public TDataOutputStream(TOutputStream out) {
super(out);
@ -43,7 +41,7 @@ public class TDataOutputStream extends TFilterOutputStream implements TDataOutpu
}
@Override
public void write(byte buffer[], int offset, int count) throws TIOException {
public void write(byte[] buffer, int offset, int count) throws TIOException {
if (buffer == null) {
throw new TNullPointerException();
}
@ -74,7 +72,7 @@ public class TDataOutputStream extends TFilterOutputStream implements TDataOutpu
if (str.length() == 0) {
return;
}
byte bytes[] = new byte[str.length()];
byte[] bytes = new byte[str.length()];
for (int index = 0; index < str.length(); index++) {
bytes[index] = (byte) str.charAt(index);
}
@ -92,7 +90,7 @@ public class TDataOutputStream extends TFilterOutputStream implements TDataOutpu
@Override
public final void writeChars(TString str) throws TIOException {
byte newBytes[] = new byte[str.length() * 2];
byte[] newBytes = new byte[str.length() * 2];
for (int index = 0; index < str.length(); index++) {
int newIndex = index == 0 ? index : index * 2;
newBytes[newIndex] = (byte) (str.charAt(index) >> 8);
@ -136,8 +134,7 @@ public class TDataOutputStream extends TFilterOutputStream implements TDataOutpu
written += 8;
}
int writeLongToBuffer(long val,
byte[] buffer, int offset) throws TIOException {
int writeLongToBuffer(long val, byte[] buffer, int offset) throws TIOException {
buffer[offset++] = (byte) (val >> 56);
buffer[offset++] = (byte) (val >> 48);
buffer[offset++] = (byte) (val >> 40);
@ -157,8 +154,7 @@ public class TDataOutputStream extends TFilterOutputStream implements TDataOutpu
written += 2;
}
int writeShortToBuffer(int val,
byte[] buffer, int offset) throws TIOException {
int writeShortToBuffer(int val, byte[] buffer, int offset) throws TIOException {
buffer[offset++] = (byte) (val >> 8);
buffer[offset++] = (byte) val;
return offset;
@ -178,7 +174,8 @@ public class TDataOutputStream extends TFilterOutputStream implements TDataOutpu
}
long countUTFBytes(TString str) {
int utfCount = 0, length = str.length();
int utfCount = 0;
int length = str.length();
for (int i = 0; i < length; i++) {
int charValue = str.charAt(i);
if (charValue > 0 && charValue <= 127) {

View File

@ -1,10 +1,9 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You 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
* Copyright 2015 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
*

View File

@ -70,7 +70,7 @@ public class TPushbackInputStream extends TFilterInputStream {
}
// Is there a pushback byte available?
if (pos < buf.length) {
return (buf[pos++] & 0xFF);
return buf[pos++] & 0xFF;
}
// Assume read() in the InputStream will return low-order byte or -1
// if end of stream.
@ -90,7 +90,9 @@ public class TPushbackInputStream extends TFilterInputStream {
throw new TArrayIndexOutOfBoundsException(TString.wrap("Length out of bounds: " + length));
}
int copiedBytes = 0, copyLength = 0, newOffset = offset;
int copiedBytes = 0;
int copyLength = 0;
int newOffset = offset;
// Are there pushback bytes available?
if (pos < buf.length) {
copyLength = (buf.length - pos >= length) ? length : buf.length - pos;

View File

@ -27,7 +27,7 @@ import org.teavm.classlib.java.lang.TString;
public class TStringReader extends TReader {
private TString string;
private int index;
private int mark = 0;
private int mark;
public TStringReader(TString string) {
if (string == null) {

View File

@ -33,15 +33,15 @@ public abstract class TWriter implements TAppendable, TCloseable, TFlushable {
this.lock = lock;
}
public void write(char buf[]) throws TIOException {
public void write(char[] buf) throws TIOException {
write(buf, 0, buf.length);
}
public abstract void write(char buf[], int offset, int count) throws TIOException;
public abstract void write(char[] buf, int offset, int count) throws TIOException;
public void write(int oneChar) throws TIOException {
synchronized (lock) {
char oneCharArray[] = new char[1];
char[] oneCharArray = new char[1];
oneCharArray[0] = (char) oneChar;
write(oneCharArray);
}
@ -55,7 +55,7 @@ public abstract class TWriter implements TAppendable, TCloseable, TFlushable {
if (count < 0) {
throw new StringIndexOutOfBoundsException();
}
char buf[] = new char[count];
char[] buf = new char[count];
str.getChars(offset, offset + count, buf, 0);
synchronized (lock) {
write(buf, 0, buf.length);

View File

@ -178,13 +178,13 @@ public class TCharacter extends TObject implements TComparable<TCharacter> {
}
public static int toCodePoint(char high, char low) {
return (((high & SURROGATE_BIT_INV_MASK) << MEANINGFUL_SURROGATE_BITS) | (low & SURROGATE_BIT_INV_MASK)) +
MIN_SUPPLEMENTARY_CODE_POINT;
return (((high & SURROGATE_BIT_INV_MASK) << MEANINGFUL_SURROGATE_BITS) | (low & SURROGATE_BIT_INV_MASK))
+ MIN_SUPPLEMENTARY_CODE_POINT;
}
public static int codePointAt(TCharSequence seq, int index) {
if (index >= seq.length() - 1 || !isHighSurrogate(seq.charAt(index)) ||
!isLowSurrogate(seq.charAt(index + 1))) {
if (index >= seq.length() - 1 || !isHighSurrogate(seq.charAt(index))
|| !isLowSurrogate(seq.charAt(index + 1))) {
return seq.charAt(index);
} else {
return toCodePoint(seq.charAt(index), seq.charAt(index + 1));
@ -361,8 +361,8 @@ public class TCharacter extends TObject implements TComparable<TCharacter> {
public static int offsetByCodePoints(TCharSequence seq, int index, int codePointOffset) {
for (int i = 0; i < codePointOffset; ++i) {
if (index < seq.length() - 1 && isHighSurrogate(seq.charAt(index)) &&
isLowSurrogate(seq.charAt(index + 1))) {
if (index < seq.length() - 1 && isHighSurrogate(seq.charAt(index))
&& isLowSurrogate(seq.charAt(index + 1))) {
index += 2;
} else {
index++;
@ -594,8 +594,8 @@ public class TCharacter extends TObject implements TComparable<TCharacter> {
}
public static boolean isIdentifierIgnorable(int codePoint) {
if (codePoint >= 0x00 && codePoint <= 0x08 || codePoint >= 0x0E && codePoint <= 0x1B ||
codePoint >= 0x7F && codePoint <= 0x9F) {
if (codePoint >= 0x00 && codePoint <= 0x08 || codePoint >= 0x0E && codePoint <= 0x1B
|| codePoint >= 0x7F && codePoint <= 0x9F) {
return true;
}
return getType(codePoint) == FORMAT;

View File

@ -182,8 +182,8 @@ public class TClass<T> extends TObject implements TAnnotatedElement {
@SuppressWarnings("unchecked")
public T cast(TObject obj) {
if (obj != null && !isAssignableFrom((TClass<?>) (Object) obj.getClass())) {
throw new TClassCastException(TString.wrap(obj.getClass().getName() +
" is not subtype of " + name));
throw new TClassCastException(TString.wrap(obj.getClass().getName()
+ " is not subtype of " + name));
}
return (T) obj;
}

View File

@ -23,7 +23,7 @@ import org.teavm.platform.Platform;
*
* @author Alexey Andreev
*/
class TConsoleOutputStream_stderr extends TOutputStream {
class TConsoleOutputStreamStderr extends TOutputStream {
@Override
public void write(int b) throws TIOException {
Platform.getConsole().error(b);

View File

@ -23,7 +23,7 @@ import org.teavm.platform.Platform;
*
* @author Alexey Andreev
*/
class TConsoleOutputStream_stdout extends TOutputStream {
class TConsoleOutputStreamStdout extends TOutputStream {
@Override
public void write(int b) throws TIOException {
Platform.getConsole().output(b);

View File

@ -278,7 +278,7 @@ public class TDouble extends TNumber implements TComparable<TDouble> {
if (rawExp == 0) {
mantissa <<= 1;
} else {
mantissa |= (1L << 52);
mantissa |= 1L << 52;
}
double value = mantissa * binaryExponent(rawExp - 1023 - 52);
return !negative ? value : -value;

View File

@ -68,9 +68,8 @@ public abstract class TEnum<E extends TEnum<E>> extends TObject implements TComp
@Override
public final int compareTo(E o) {
if (o.getDeclaringClass() != getDeclaringClass()) {
throw new TIllegalArgumentException(TString.wrap("Can't compare " +
getDeclaringClass().getName().toString() + " to " +
o.getDeclaringClass().getName().toString()));
throw new TIllegalArgumentException(TString.wrap("Can't compare "
+ getDeclaringClass().getName().toString() + " to " + o.getDeclaringClass().getName().toString()));
}
return TInteger.compare(ordinal, o.ordinal());
}
@ -86,7 +85,7 @@ public abstract class TEnum<E extends TEnum<E>> extends TObject implements TComp
return constant;
}
}
throw new TIllegalArgumentException(TString.wrap("Enum " + enumType.getName() + " does not have the " + name +
"constant"));
throw new TIllegalArgumentException(TString.wrap("Enum " + enumType.getName() + " does not have the " + name
+ "constant"));
}
}

View File

@ -280,7 +280,7 @@ public class TFloat extends TNumber implements TComparable<TFloat> {
if (rawExp == 0) {
mantissa <<= 1;
} else {
mantissa |= (1L << 23);
mantissa |= 1L << 23;
}
float value = mantissa * binaryExponent(rawExp - 127 - 23);
return !negative ? value : -value;

View File

@ -86,8 +86,8 @@ public class TInteger extends TNumber implements TComparable<TInteger> {
throw new TNumberFormatException(TString.wrap("String contains invalid digits: " + s));
}
if (digit >= radix) {
throw new TNumberFormatException(TString.wrap("String contains digits out of radix " + radix +
": " + s));
throw new TNumberFormatException(TString.wrap("String contains digits out of radix " + radix
+ ": " + s));
}
value = radix * value + digit;
if (value < 0) {

View File

@ -65,8 +65,8 @@ public class TLong extends TNumber implements TComparable<TLong> {
throw new TNumberFormatException(TString.wrap("String contains invalid digits: " + s));
}
if (digit >= radix) {
throw new TNumberFormatException(TString.wrap("String contains digits out of radix " + radix +
": " + s));
throw new TNumberFormatException(TString.wrap("String contains digits out of radix " + radix
+ ": " + s));
}
value = radix * value + digit;
if (value < 0) {

View File

@ -22,8 +22,8 @@ import org.teavm.javascript.spi.GeneratedBy;
* @author Alexey Andreev
*/
public final class TMath extends TObject {
public static double E = 2.71828182845904523536;
public static double PI = 3.14159265358979323846;
public static final double E = 2.71828182845904523536;
public static final double PI = 3.14159265358979323846;
private TMath() {
}

View File

@ -247,7 +247,7 @@ public class TObject {
}
@Rename("wait")
private final void wait0(long timeout, int nanos) throws TInterruptedException {
private void wait0(long timeout, int nanos) throws TInterruptedException {
if (!holdsLock(this)) {
throw new TIllegalMonitorStateException();
}
@ -255,14 +255,14 @@ public class TObject {
}
@Async
private native final void waitImpl(long timeout, int nanos) throws TInterruptedException;
private native void waitImpl(long timeout, int nanos) throws TInterruptedException;
public final void waitImpl(long timeout, int nanos, final AsyncCallback<Void> callback) {
final NotifyListenerImpl listener = new NotifyListenerImpl(this, callback, monitor.count);
monitor.notifyListeners.add(listener);
if (timeout > 0 || nanos > 0) {
listener.timerId = Platform.schedule(listener, timeout >= Integer.MAX_VALUE ? Integer.MAX_VALUE :
(int)timeout);
listener.timerId = Platform.schedule(listener, timeout >= Integer.MAX_VALUE ? Integer.MAX_VALUE
: (int) timeout);
}
monitorExit(this, monitor.count);
}
@ -332,7 +332,7 @@ public class TObject {
@Rename("wait")
public final void wait0() throws TInterruptedException {
try {
wait(0l);
wait(0L);
} catch (InterruptedException ex) {
throw new TInterruptedException();
}

View File

@ -1,5 +1,5 @@
/*
* Copyright 2015 Steve Hannah.
* Copyright 2013 Steve Hannah.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.

View File

@ -73,10 +73,10 @@ public final class TStackTraceElement extends TObject implements TSerializable {
return false;
}
TStackTraceElement other = (TStackTraceElement) obj;
return TObjects.equals(declaringClass, other.declaringClass) &&
TObjects.equals(methodName, other.methodName) &&
TObjects.equals(fileName, other.fileName) &&
lineNumber == other.lineNumber;
return TObjects.equals(declaringClass, other.declaringClass)
&& TObjects.equals(methodName, other.methodName)
&& TObjects.equals(fileName, other.fileName)
&& lineNumber == other.lineNumber;
}
@Override

View File

@ -20,8 +20,8 @@ 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;
public static final double E = 2.71828182845904523536;
public static final double PI = 3.14159265358979323846;
private TStrictMath() {
}

View File

@ -152,8 +152,8 @@ public class TString extends TObject implements TSerializable, TComparable<TStri
}
public void getChars(int srcBegin, int srcEnd, char[] dst, int dstBegin) {
if (srcBegin < 0 || srcBegin > srcEnd || srcEnd > length() || dstBegin < 0 ||
dstBegin + (srcEnd - srcBegin) > dst.length) {
if (srcBegin < 0 || srcBegin > srcEnd || srcEnd > length() || dstBegin < 0
|| dstBegin + (srcEnd - srcBegin) > dst.length) {
throw new TIndexOutOfBoundsException();
}
while (srcBegin < srcEnd) {
@ -591,8 +591,8 @@ public class TString extends TObject implements TSerializable, TComparable<TStri
int[] codePoints = new int[characters.length];
int codePointCount = 0;
for (int i = 0; i < characters.length; ++i) {
if (i == characters.length - 1 || !TCharacter.isHighSurrogate(characters[i]) ||
!TCharacter.isLowSurrogate(characters[i + 1])) {
if (i == characters.length - 1 || !TCharacter.isHighSurrogate(characters[i])
|| !TCharacter.isLowSurrogate(characters[i + 1])) {
codePoints[codePointCount++] = TCharacter.toLowerCase(characters[i]);
} else {
codePoints[codePointCount++] = TCharacter.toLowerCase(TCharacter.toCodePoint(
@ -610,8 +610,8 @@ public class TString extends TObject implements TSerializable, TComparable<TStri
int[] codePoints = new int[characters.length];
int codePointCount = 0;
for (int i = 0; i < characters.length; ++i) {
if (i == characters.length - 1 || !TCharacter.isHighSurrogate(characters[i]) ||
!TCharacter.isLowSurrogate(characters[i + 1])) {
if (i == characters.length - 1 || !TCharacter.isHighSurrogate(characters[i])
|| !TCharacter.isLowSurrogate(characters[i + 1])) {
codePoints[codePointCount++] = TCharacter.toUpperCase(characters[i]);
} else {
codePoints[codePointCount++] = TCharacter.toUpperCase(TCharacter.toCodePoint(

View File

@ -26,8 +26,8 @@ import org.teavm.javascript.spi.GeneratedBy;
* @author Alexey Andreev
*/
public final class TSystem extends TObject {
public static final TPrintStream out = new TPrintStream(new TConsoleOutputStream_stdout(), false);
public static final TPrintStream err = new TPrintStream(new TConsoleOutputStream_stderr(), false);
public static final TPrintStream out = new TPrintStream(new TConsoleOutputStreamStdout(), false);
public static final TPrintStream err = new TPrintStream(new TConsoleOutputStreamStderr(), false);
private TSystem() {
}
@ -40,8 +40,8 @@ public final class TSystem extends TObject {
if (src == null || dest == null) {
throw new TNullPointerException(TString.wrap("Either src or dest is null"));
}
if (srcPos < 0 || destPos < 0 || length < 0 || srcPos + length > TArray.getLength(src) ||
destPos + length > TArray.getLength(dest)) {
if (srcPos < 0 || destPos < 0 || length < 0 || srcPos + length > TArray.getLength(src)
|| destPos + length > TArray.getLength(dest)) {
throw new TIndexOutOfBoundsException();
}
if (src != dest) {

View File

@ -33,7 +33,7 @@ public class TThread extends TObject implements TRunnable {
private static long nextId = 1;
private static int activeCount = 1;
private long id;
private int priority = 0;
private int priority;
private long timeSliceStart;
private int yieldCount;
private final Object finishedLock = new Object();

View File

@ -144,8 +144,8 @@ public class AnnotationDependencyListener extends AbstractDependencyListener {
}
}
if (method.getMethod().hasModifier(ElementModifier.STATIC) &&
method.getMethod().getName().equals("$$__readAnnotations__$$")) {
if (method.getMethod().hasModifier(ElementModifier.STATIC)
&& method.getMethod().getName().equals("$$__readAnnotations__$$")) {
ClassReader cls = agent.getClassSource().get(method.getReference().getClassName());
if (cls != null) {
for (AnnotationReader annotation : cls.getAnnotations().all()) {

View File

@ -1,10 +1,9 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You 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
* Copyright 2015 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
*
@ -14,7 +13,6 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.teavm.classlib.java.math;
import java.io.Serializable;
@ -116,22 +114,22 @@ public class TBigDecimal extends Number implements Comparable<TBigDecimal>, Seri
private static final double LOG10_2 = 0.3010299956639812;
/** The <code>String</code> representation is cached. */
private transient String toStringImage = null;
private transient String toStringImage;
/** Cache for the hash code. */
private transient int hashCode = 0;
private transient int hashCode;
/**
* An array with powers of five that fit in the type <code>long</code>
* (<code>5^0,5^1,...,5^27</code>).
*/
private static final TBigInteger FIVE_POW[];
private static final TBigInteger[] FIVE_POW;
/**
* An array with powers of ten that fit in the type <code>long</code>
* (<code>10^0,10^1,...,10^18</code>).
*/
private static final TBigInteger TEN_POW[];
private static final TBigInteger[] TEN_POW;
/**
* An array with powers of ten that fit in the type <code>long</code>
@ -198,13 +196,13 @@ public class TBigDecimal extends Number implements Comparable<TBigDecimal>, Seri
* An array with the first <code>BigInteger</code> scaled by zero.
* (<code>[0,0],[1,0],...,[10,0]</code>).
*/
private static final TBigDecimal BI_SCALED_BY_ZERO[] = new TBigDecimal[BI_SCALED_BY_ZERO_LENGTH];
private static final TBigDecimal[] BI_SCALED_BY_ZERO = new TBigDecimal[BI_SCALED_BY_ZERO_LENGTH];
/**
* An array with the zero number scaled by the first positive scales.
* (<code>0*10^0, 0*10^1, ..., 0*10^10</code>).
*/
private static final TBigDecimal ZERO_SCALED_BY[] = new TBigDecimal[11];
private static final TBigDecimal[] ZERO_SCALED_BY = new TBigDecimal[11];
/** An array filled with characters <code>'0'</code>. */
private static final char[] CH_ZEROS = new char[100];
@ -258,7 +256,7 @@ public class TBigDecimal extends Number implements Comparable<TBigDecimal>, Seri
* @see #precision()
* @see #inplaceRound(TMathContext)
*/
private transient int precision = 0;
private transient int precision;
private TBigDecimal(long smallValue, int scale) {
this.smallValue = smallValue;
@ -822,14 +820,15 @@ public class TBigDecimal extends Number implements Comparable<TBigDecimal>, Seri
} else if (diffScale > 0) {
// case s1 > s2 : [(u1 + u2) * 10 ^ (s1 - s2) , s1]
return addAndMult10(this, augend, diffScale);
} else {// case s2 > s1 : [(u2 + u1) * 10 ^ (s2 - s1) , s2]
} else {
// case s2 > s1 : [(u2 + u1) * 10 ^ (s2 - s1) , s2]
return addAndMult10(augend, this, -diffScale);
}
}
private static TBigDecimal addAndMult10(TBigDecimal thisValue, TBigDecimal augend, int diffScale) {
if(diffScale < LONG_TEN_POW.length &&
Math.max(thisValue.bitLength, augend.bitLength + LONG_TEN_POW_BIT_LENGTH[diffScale]) + 1 < 64) {
if (diffScale < LONG_TEN_POW.length
&& Math.max(thisValue.bitLength, augend.bitLength + LONG_TEN_POW_BIT_LENGTH[diffScale]) + 1 < 64) {
return valueOf(thisValue.smallValue + augend.smallValue * LONG_TEN_POW[diffScale], thisValue.scale);
}
return new TBigDecimal(thisValue.getUnscaledValue().add(
@ -865,7 +864,7 @@ public class TBigDecimal extends Number implements Comparable<TBigDecimal>, Seri
} else if (augend.aproxPrecision() < -diffScale - 1) {
larger = this;
smaller = augend;
} else {// No optimization is done
} else {
return add(augend).round(mc);
}
if (mc.getPrecision() >= larger.aproxPrecision()) {
@ -920,16 +919,17 @@ public class TBigDecimal extends Number implements Comparable<TBigDecimal>, Seri
return new TBigDecimal(this.getUnscaledValue().subtract(subtrahend.getUnscaledValue()), this.scale);
} else if (diffScale > 0) {
// case s1 > s2 : [ u1 - u2 * 10 ^ (s1 - s2) , s1 ]
if(diffScale < LONG_TEN_POW.length &&
Math.max(this.bitLength, subtrahend.bitLength + LONG_TEN_POW_BIT_LENGTH[diffScale]) + 1 < 64) {
if (diffScale < LONG_TEN_POW.length
&& Math.max(this.bitLength, subtrahend.bitLength + LONG_TEN_POW_BIT_LENGTH[diffScale]) + 1 < 64) {
return valueOf(this.smallValue - subtrahend.smallValue * LONG_TEN_POW[diffScale], this.scale);
}
return new TBigDecimal(this.getUnscaledValue().subtract(
TMultiplication.multiplyByTenPow(subtrahend.getUnscaledValue(), diffScale)), this.scale);
} else {// case s2 > s1 : [ u1 * 10 ^ (s2 - s1) - u2 , s2 ]
} else {
// case s2 > s1 : [ u1 * 10 ^ (s2 - s1) - u2 , s2 ]
diffScale = -diffScale;
if(diffScale < LONG_TEN_POW.length &&
Math.max(this.bitLength + LONG_TEN_POW_BIT_LENGTH[diffScale], subtrahend.bitLength) + 1 < 64) {
if (diffScale < LONG_TEN_POW.length
&& Math.max(this.bitLength + LONG_TEN_POW_BIT_LENGTH[diffScale], subtrahend.bitLength) + 1 < 64) {
return valueOf(this.smallValue * LONG_TEN_POW[diffScale] - subtrahend.smallValue, subtrahend.scale);
}
return new TBigDecimal(TMultiplication.multiplyByTenPow(this.getUnscaledValue(), diffScale)
@ -1091,16 +1091,16 @@ public class TBigDecimal extends Number implements Comparable<TBigDecimal>, Seri
if (diffScale == 0) {
return dividePrimitiveLongs(this.smallValue, divisor.smallValue, scale, roundingMode);
} else if (diffScale > 0) {
if(diffScale < LONG_TEN_POW.length &&
divisor.bitLength + LONG_TEN_POW_BIT_LENGTH[(int)diffScale] < 64) {
if (diffScale < LONG_TEN_POW.length
&& divisor.bitLength + LONG_TEN_POW_BIT_LENGTH[(int) diffScale] < 64) {
return dividePrimitiveLongs(this.smallValue,
divisor.smallValue * LONG_TEN_POW[(int) diffScale],
scale,
roundingMode);
}
} else { // diffScale < 0
if(-diffScale < LONG_TEN_POW.length &&
this.bitLength + LONG_TEN_POW_BIT_LENGTH[(int)-diffScale] < 64) {
if (-diffScale < LONG_TEN_POW.length
&& this.bitLength + LONG_TEN_POW_BIT_LENGTH[(int) -diffScale] < 64) {
return dividePrimitiveLongs(this.smallValue * LONG_TEN_POW[(int) -diffScale],
divisor.smallValue, scale, roundingMode);
}
@ -1130,7 +1130,8 @@ public class TBigDecimal extends Number implements Comparable<TBigDecimal>, Seri
}
int sign = scaledDividend.signum() * scaledDivisor.signum();
int compRem; // 'compare to remainder'
if(scaledDivisor.bitLength() < 63) { // 63 in order to avoid out of long after <<1
if (scaledDivisor.bitLength() < 63) {
// 63 in order to avoid out of long after <<1
long rem = remainder.longValue();
long divisor = scaledDivisor.longValue();
compRem = longCompareTo(Math.abs(rem) << 1, Math.abs(divisor));
@ -1241,7 +1242,7 @@ public class TBigDecimal extends Number implements Comparable<TBigDecimal>, Seri
TBigInteger p = this.getUnscaledValue();
TBigInteger q = divisor.getUnscaledValue();
TBigInteger gcd; // greatest common divisor between 'p' and 'q'
TBigInteger quotAndRem[];
TBigInteger[] quotAndRem;
long diffScale = (long) scale - divisor.scale;
int newScale; // the new scale for final quotient
int k; // number of factors "2" in 'q'
@ -1325,7 +1326,7 @@ public class TBigDecimal extends Number implements Comparable<TBigDecimal>, Seri
int i = 1; // index
int lastPow = TEN_POW.length - 1; // last power of ten
TBigInteger integerQuot; // for temporal results
TBigInteger quotAndRem[] = {getUnscaledValue()};
TBigInteger[] quotAndRem = {getUnscaledValue()};
// In special cases it reduces the problem to call the dual method
if ((mc.getPrecision() == 0) || (this.isZero())
|| (divisor.isZero())) {
@ -1385,7 +1386,7 @@ public class TBigDecimal extends Number implements Comparable<TBigDecimal>, Seri
public TBigDecimal divideToIntegralValue(TBigDecimal divisor) {
TBigInteger integralValue; // the integer of result
TBigInteger powerOfTen; // some power of ten
TBigInteger quotAndRem[] = {getUnscaledValue()};
TBigInteger[] quotAndRem = {getUnscaledValue()};
long newScale = (long) this.scale - divisor.scale;
long tempScale = 0;
int i = 1;
@ -1405,7 +1406,8 @@ public class TBigDecimal extends Number implements Comparable<TBigDecimal>, Seri
powerOfTen = TMultiplication.powerOf10(newScale);
integralValue = getUnscaledValue().divide(divisor.getUnscaledValue().multiply(powerOfTen));
integralValue = integralValue.multiply(powerOfTen);
} else {// (newScale < 0)
} else {
// (newScale < 0)
powerOfTen = TMultiplication.powerOf10(-newScale);
integralValue = getUnscaledValue().multiply(powerOfTen).divide(divisor.getUnscaledValue());
// To strip trailing zeros approximating to the preferred scale
@ -1427,9 +1429,9 @@ public class TBigDecimal extends Number implements Comparable<TBigDecimal>, Seri
}
newScale = tempScale;
}
return ((integralValue.signum() == 0)
return integralValue.signum() == 0
? zeroScaledBy(newScale)
: new TBigDecimal(integralValue, toIntScale(newScale)));
: new TBigDecimal(integralValue, toIntScale(newScale));
}
/**
@ -1460,7 +1462,7 @@ public class TBigDecimal extends Number implements Comparable<TBigDecimal>, Seri
long diffScale = (long) this.scale - divisor.scale;
long newScale = diffScale;
long quotPrecision = diffPrecision - diffScale + 1;
TBigInteger quotAndRem[] = new TBigInteger[2];
TBigInteger[] quotAndRem = new TBigInteger[2];
// In special cases it call the dual method
if ((mcPrecision == 0) || (this.isZero()) || (divisor.isZero())) {
return this.divideToIntegralValue(divisor);
@ -1479,7 +1481,8 @@ public class TBigDecimal extends Number implements Comparable<TBigDecimal>, Seri
newScale = Math.min(diffScale, Math.max(mcPrecision - quotPrecision + 1, 0));
// To calculate: (u1 / (u2 * 10^(s1-s2)) * 10^newScale
quotAndRem[0] = quotAndRem[0].multiply(TMultiplication.powerOf10(newScale));
} else {// CASE s2 > s1:
} else {
// CASE s2 > s1:
/* To calculate the minimum power of ten, such that the quotient
* (u1 * 10^exp) / u2 has at least 'mc.precision()' digits. */
long exp = Math.min(-diffScale, Math.max((long) mcPrecision - diffPrecision, 0));
@ -1517,8 +1520,8 @@ public class TBigDecimal extends Number implements Comparable<TBigDecimal>, Seri
// To strip trailing zeros until the specified precision is reached
while (!strippedBI.testBit(0)) {
quotAndRem = strippedBI.divideAndRemainder(TEN_POW[i]);
if ((quotAndRem[1].signum() == 0) &&
((resultPrecision - i >= mcPrecision)
if ((quotAndRem[1].signum() == 0)
&& ((resultPrecision - i >= mcPrecision)
|| (newScale - i >= diffScale))) {
resultPrecision -= i;
newScale -= i;
@ -1604,7 +1607,7 @@ public class TBigDecimal extends Number implements Comparable<TBigDecimal>, Seri
* @see #remainder
*/
public TBigDecimal[] divideAndRemainder(TBigDecimal divisor) {
TBigDecimal quotAndRem[] = new TBigDecimal[2];
TBigDecimal[] quotAndRem = new TBigDecimal[2];
quotAndRem[0] = this.divideToIntegralValue(divisor);
quotAndRem[1] = this.subtract(quotAndRem[0].multiply(divisor));
@ -1634,7 +1637,7 @@ public class TBigDecimal extends Number implements Comparable<TBigDecimal>, Seri
* @see #remainder
*/
public TBigDecimal[] divideAndRemainder(TBigDecimal divisor, TMathContext mc) {
TBigDecimal quotAndRem[] = new TBigDecimal[2];
TBigDecimal[] quotAndRem = new TBigDecimal[2];
quotAndRem[0] = this.divideToIntegralValue(divisor, mc);
quotAndRem[1] = this.subtract(quotAndRem[0].multiply(divisor));
@ -1665,9 +1668,9 @@ public class TBigDecimal extends Number implements Comparable<TBigDecimal>, Seri
}
long newScale = scale * (long) n;
// Let be: this = [u,s] so: this^n = [u^n, s*n]
return ((isZero())
return isZero()
? zeroScaledBy(newScale)
: new TBigDecimal(getUnscaledValue().pow(n), toIntScale(newScale)));
: new TBigDecimal(getUnscaledValue().pow(n), toIntScale(newScale));
}
/**
@ -1698,13 +1701,11 @@ public class TBigDecimal extends Number implements Comparable<TBigDecimal>, Seri
if ((n == 0) || ((isZero()) && (n > 0))) {
return pow(n);
}
if ((m > 999999999) || ((mcPrecision == 0) && (n < 0))
|| ((mcPrecision > 0) && (elength > mcPrecision))) {
if ((m > 999999999) || ((mcPrecision == 0) && (n < 0)) || ((mcPrecision > 0) && (elength > mcPrecision))) {
throw new ArithmeticException("Invalid Operation");
}
if (mcPrecision > 0) {
newPrecision = new TMathContext( mcPrecision + elength + 1,
mc.getRoundingMode());
newPrecision = new TMathContext(mcPrecision + elength + 1, mc.getRoundingMode());
}
// The result is calculated as if 'n' were positive
accum = round(newPrecision);
@ -1733,7 +1734,7 @@ public class TBigDecimal extends Number implements Comparable<TBigDecimal>, Seri
* @return {@code abs(this)}
*/
public TBigDecimal abs() {
return ((signum() < 0) ? negate() : this);
return signum() < 0 ? negate() : this;
}
/**
@ -1851,7 +1852,8 @@ public class TBigDecimal extends Number implements Comparable<TBigDecimal>, Seri
doubleUnsc = smallValue;
}
decimalDigits += Math.log10(Math.abs(doubleUnsc));
} else {// (bitLength >= 1024)
} else {
// (bitLength >= 1024)
/* To calculate the precision for large numbers
* Note that: 2 ^(bitlength() - 1) <= intVal < 10 ^(precision()) */
decimalDigits += (bitLength - 1) * LOG10_2;
@ -1933,8 +1935,8 @@ public class TBigDecimal extends Number implements Comparable<TBigDecimal>, Seri
}
if (diffScale > 0) {
// return [u * 10^(s2 - s), newScale]
if(diffScale < LONG_TEN_POW.length &&
(this.bitLength + LONG_TEN_POW_BIT_LENGTH[(int)diffScale]) < 64 ) {
if (diffScale < LONG_TEN_POW.length
&& (this.bitLength + LONG_TEN_POW_BIT_LENGTH[(int) diffScale]) < 64) {
return valueOf(this.smallValue * LONG_TEN_POW[(int) diffScale], newScale);
}
return new TBigDecimal(TMultiplication.multiplyByTenPow(getUnscaledValue(), (int) diffScale), newScale);
@ -1944,7 +1946,8 @@ public class TBigDecimal extends Number implements Comparable<TBigDecimal>, Seri
if (this.bitLength < 64 && -diffScale < LONG_TEN_POW.length) {
return dividePrimitiveLongs(this.smallValue, LONG_TEN_POW[(int) -diffScale], newScale, roundingMode);
}
return divideBigIntegers(this.getUnscaledValue(),TMultiplication.powerOf10(-diffScale),newScale,roundingMode);
return divideBigIntegers(this.getUnscaledValue(), TMultiplication.powerOf10(-diffScale),
newScale, roundingMode);
}
/**
@ -2025,8 +2028,8 @@ public class TBigDecimal extends Number implements Comparable<TBigDecimal>, Seri
}
return new TBigDecimal(getUnscaledValue(), toIntScale(newScale));
}
if(-newScale < LONG_TEN_POW.length &&
bitLength + LONG_TEN_POW_BIT_LENGTH[(int)-newScale] < 64 ) {
if (-newScale < LONG_TEN_POW.length
&& bitLength + LONG_TEN_POW_BIT_LENGTH[(int) -newScale] < 64) {
return valueOf(smallValue * LONG_TEN_POW[(int) -newScale], 0);
}
return new TBigDecimal(TMultiplication.multiplyByTenPow(getUnscaledValue(), (int) -newScale), 0);
@ -2152,10 +2155,12 @@ public class TBigDecimal extends Number implements Comparable<TBigDecimal>, Seri
return thisSign;
} else if (diffPrecision < diffScale - 1) {
return -thisSign;
} else {// thisSign == val.signum() and diffPrecision is aprox. diffScale
} else {
// thisSign == val.signum() and diffPrecision is aprox. diffScale
TBigInteger thisUnscaled = this.getUnscaledValue();
TBigInteger valUnscaled = val.getUnscaledValue();
// If any of both precision is bigger, append zeros to the shorter one
// If any of both precision is bigger, append zeros to the
// shorter one
if (diffScale < 0) {
thisUnscaled = thisUnscaled.multiply(TMultiplication.powerOf10(-diffScale));
} else if (diffScale > 0) {
@ -2207,7 +2212,7 @@ public class TBigDecimal extends Number implements Comparable<TBigDecimal>, Seri
* if {@code val == null}.
*/
public TBigDecimal min(TBigDecimal val) {
return ((compareTo(val) <= 0) ? this : val);
return compareTo(val) <= 0 ? this : val;
}
/**
@ -2220,7 +2225,7 @@ public class TBigDecimal extends Number implements Comparable<TBigDecimal>, Seri
* if {@code val == null}.
*/
public TBigDecimal max(TBigDecimal val) {
return ((compareTo(val) >= 0) ? this : val);
return compareTo(val) >= 0 ? this : val;
}
/**
@ -2321,7 +2326,7 @@ public class TBigDecimal extends Number implements Comparable<TBigDecimal>, Seri
if (exponent >= 0) {
result.insert(end - scale, '.');
} else {
result.insert(begin - 1, "0."); //$NON-NLS-1$
result.insert(begin - 1, "0.");
result.insert(begin + 1, CH_ZEROS, 0, -(int) exponent - 1);
}
} else {
@ -2391,7 +2396,7 @@ public class TBigDecimal extends Number implements Comparable<TBigDecimal>, Seri
result.append('-');
}
if (scale > 0) {
delta -= (intStr.length() - begin);
delta -= intStr.length() - begin;
if (delta >= 0) {
result.append("0."); //$NON-NLS-1$
// To append zeros after the decimal point
@ -2406,7 +2411,8 @@ public class TBigDecimal extends Number implements Comparable<TBigDecimal>, Seri
result.append('.');
result.append(intStr.substring(delta));
}
} else {// (scale <= 0)
} else {
// (scale <= 0)
result.append(intStr.substring(begin));
// To append trailing zeros
for (; delta < -CH_ZEROS.length; delta += CH_ZEROS.length) {
@ -2428,7 +2434,8 @@ public class TBigDecimal extends Number implements Comparable<TBigDecimal>, Seri
return getUnscaledValue();
} else if (scale < 0) {
return getUnscaledValue().multiply(TMultiplication.powerOf10(-(long) scale));
} else {// (scale > 0)
} else {
// (scale > 0)
return getUnscaledValue().divide(TMultiplication.powerOf10(scale));
}
}
@ -2447,7 +2454,8 @@ public class TBigDecimal extends Number implements Comparable<TBigDecimal>, Seri
return getUnscaledValue();
} else if (scale < 0) {
return getUnscaledValue().multiply(TMultiplication.powerOf10(-(long) scale));
} else {// (scale > 0)
} else {
// (scale > 0)
TBigInteger[] integerAndFraction;
// An optimization before do a heavy division
if ((scale > aproxPrecision()) || (scale > getUnscaledValue().getLowestSetBit())) {
@ -2473,9 +2481,7 @@ public class TBigDecimal extends Number implements Comparable<TBigDecimal>, Seri
public long longValue() {
/* If scale <= -64 there are at least 64 trailing bits zero in 10^(-scale).
* If the scale is positive and very large the long value could be zero. */
return ((scale <= -64) || (scale > aproxPrecision())
? 0L
: toBigInteger().longValue());
return scale <= -64 || scale > aproxPrecision() ? 0L : toBigInteger().longValue();
}
/**
@ -2502,9 +2508,7 @@ public class TBigDecimal extends Number implements Comparable<TBigDecimal>, Seri
public int intValue() {
/* If scale <= -32 there are at least 32 trailing bits zero in 10^(-scale).
* If the scale is positive and very large the long value could be zero. */
return ((scale <= -32) || (scale > aproxPrecision())
? 0
: toBigInteger().intValue());
return scale <= -32 || scale > aproxPrecision() ? 0 : toBigInteger().intValue();
}
/**
@ -2615,18 +2619,19 @@ public class TBigDecimal extends Number implements Comparable<TBigDecimal>, Seri
if ((powerOfTwo < -1074) || (sign == 0)) {
// Cases which 'this' is very small
return (sign * 0.0d);
return sign * 0.0d;
} else if (powerOfTwo > 1025) {
// Cases which 'this' is very large
return (sign * Double.POSITIVE_INFINITY);
return sign * Double.POSITIVE_INFINITY;
}
mantisa = getUnscaledValue().abs();
// Let be: this = [u,s], with s > 0
if (scale <= 0) {
// mantisa = abs(u) * 10^s
mantisa = mantisa.multiply(TMultiplication.powerOf10(-scale));
} else {// (scale > 0)
TBigInteger quotAndRem[];
} else {
// (scale > 0)
TBigInteger[] quotAndRem;
TBigInteger powerOfTen = TMultiplication.powerOf10(scale);
int k = 100 - (int) powerOfTwo;
int compRem;
@ -2642,13 +2647,13 @@ public class TBigDecimal extends Number implements Comparable<TBigDecimal>, Seri
// To check if the fractional part >= 0.5
compRem = quotAndRem[1].shiftLeftOneBit().compareTo(powerOfTen);
// To add two rounded bits at end of mantisa
mantisa = quotAndRem[0].shiftLeft(2).add(
TBigInteger.valueOf((compRem * (compRem + 3)) / 2 + 1));
mantisa = quotAndRem[0].shiftLeft(2).add(TBigInteger.valueOf((compRem * (compRem + 3)) / 2 + 1));
exponent -= 2;
}
lowestSetBit = mantisa.getLowestSetBit();
discardedSize = mantisa.bitLength() - 54;
if (discardedSize > 0) {// (n > 54)
if (discardedSize > 0) {
// (n > 54)
// mantisa = (abs(u) * 10^s) >> (n - 54)
bits = mantisa.shiftRight(discardedSize).longValue();
tempBits = bits;
@ -2657,7 +2662,8 @@ public class TBigDecimal extends Number implements Comparable<TBigDecimal>, Seri
|| ((bits & 3) == 3)) {
bits += 2;
}
} else {// (n <= 54)
} else {
// (n <= 54)
// mantisa = (abs(u) * 10^s) << (54 - n)
bits = mantisa.longValue() << -discardedSize;
tempBits = bits;
@ -2672,23 +2678,27 @@ public class TBigDecimal extends Number implements Comparable<TBigDecimal>, Seri
bits >>= 1;
// exponent = 2^(s-n+53+bias)
exponent += discardedSize;
} else {// #bits = 54
} else {
// #bits = 54
bits >>= 2;
exponent += discardedSize + 1;
}
// To test if the 53-bits number fits in 'double'
if (exponent > 2046) {// (exponent - bias > 1023)
return (sign * Double.POSITIVE_INFINITY);
} else if (exponent <= 0) {// (exponent - bias <= -1023)
if (exponent > 2046) {
// (exponent - bias > 1023)
return sign * Double.POSITIVE_INFINITY;
} else if (exponent <= 0) {
// (exponent - bias <= -1023)
// Denormalized numbers (having exponent == 0)
if (exponent < -53) {// exponent - bias < -1076
return (sign * 0.0d);
if (exponent < -53) {
// exponent - bias < -1076
return sign * 0.0d;
}
// -1076 <= exponent - bias <= -1023
// To discard '- exponent + 1' bits
bits = tempBits >> 1;
tempBits = bits & (-1L >>> (63 + exponent));
bits >>= (-exponent );
bits >>= -exponent;
// To test if after discard bits, a new carry is generated
if (((bits & 3) == 3) || (((bits & 1) == 1) && (tempBits != 0)
&& (lowestSetBit < discardedSize))) {
@ -2739,7 +2749,7 @@ public class TBigDecimal extends Number implements Comparable<TBigDecimal>, Seri
}
int discardedPrecision = precision() - mcPrecision;
// If no rounding is necessary it returns immediately
if ((discardedPrecision <= 0)) {
if (discardedPrecision <= 0) {
return;
}
// When the number is small perform an efficient rounding
@ -2756,7 +2766,7 @@ public class TBigDecimal extends Number implements Comparable<TBigDecimal>, Seri
// If the discarded fraction is non-zero, perform rounding
if (integerAndFraction[1].signum() != 0) {
// To check if the discarded fraction >= 0.5
compRem = (integerAndFraction[1].abs().shiftLeftOneBit().compareTo(sizeOfFraction));
compRem = integerAndFraction[1].abs().shiftLeftOneBit().compareTo(sizeOfFraction);
// To look if there is a carry
compRem = roundingBehavior(integerAndFraction[0].testBit(0) ? 1 : 0,
integerAndFraction[1].signum() * (5 + compRem),

View File

@ -1,10 +1,9 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You 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
* Copyright 2015 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
*
@ -14,11 +13,10 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.teavm.classlib.java.math;
import java.util.Random;
import java.io.Serializable;
import java.util.Random;
/**
* This class represents immutable integer numbers of arbitrary length. Large
@ -49,7 +47,7 @@ public class TBigInteger extends Number implements Comparable<TBigInteger>, Seri
* is represented as [ Integer.MIN_VALUE ] The magnitude array may be longer
* than strictly necessary, which results in additional trailing zeros.
*/
transient int digits[];
transient int[] digits;
/**
* The length of this in measured in ints. Can be less than digits.length().
@ -103,7 +101,7 @@ public class TBigInteger extends Number implements Comparable<TBigInteger>, Seri
private transient int firstNonzeroDigit = -2;
/** Cache for the hash code. */
private transient int hashCode = 0;
private transient int hashCode;
/**
* Constructs a random non-negative {@code BigInteger} instance in the range
@ -342,7 +340,7 @@ public class TBigInteger extends Number implements Comparable<TBigInteger>, Seri
* @param digits
* The magnitude of the number
*/
TBigInteger(int signum, int digits[]) {
TBigInteger(int signum, int[] digits) {
if (digits.length == 0) {
sign = 0;
numberLength = 1;
@ -363,7 +361,8 @@ public class TBigInteger extends Number implements Comparable<TBigInteger>, Seri
return MINUS_ONE;
} else if (val <= 10) {
return SMALL_VALUES[(int) val];
} else {// (val > 10)
} else {
// (val > 10)
return new TBigInteger(1, val);
}
}
@ -480,8 +479,8 @@ public class TBigInteger extends Number implements Comparable<TBigInteger>, Seri
int substrEnd = startChar + ((topChars == 0) ? charsPerInt : topChars);
int newDigit;
for (int substrStart = startChar; substrStart < endChar; substrStart = substrEnd, substrEnd = substrStart +
charsPerInt) {
for (int substrStart = startChar; substrStart < endChar; substrStart = substrEnd, substrEnd = substrStart
+ charsPerInt) {
int bigRadixDigit = Integer.parseInt(val.substring(substrStart, substrEnd), radix);
newDigit = TMultiplication.multiplyByInt(digits, digitIndex, bigRadix);
newDigit += TElementary.inplaceAdd(digits, digitIndex, bigRadixDigit);
@ -501,7 +500,7 @@ public class TBigInteger extends Number implements Comparable<TBigInteger>, Seri
* @return {@code abs(this)}.
*/
public TBigInteger abs() {
return ((sign < 0) ? new TBigInteger(1, numberLength, digits) : this);
return sign < 0 ? new TBigInteger(1, numberLength, digits) : this;
}
/**
@ -510,7 +509,7 @@ public class TBigInteger extends Number implements Comparable<TBigInteger>, Seri
* @return {@code -this}.
*/
public TBigInteger negate() {
return ((sign == 0) ? this : new TBigInteger(-sign, numberLength, digits));
return sign == 0 ? this : new TBigInteger(-sign, numberLength, digits);
}
/**
@ -566,7 +565,7 @@ public class TBigInteger extends Number implements Comparable<TBigInteger>, Seri
if ((n == 0) || (sign == 0)) {
return this;
}
return ((n > 0) ? TBitLevel.shiftRight(this, n) : TBitLevel.shiftLeft(this, -n));
return n > 0 ? TBitLevel.shiftRight(this, n) : TBitLevel.shiftLeft(this, -n);
}
/**
@ -584,10 +583,10 @@ public class TBigInteger extends Number implements Comparable<TBigInteger>, Seri
* otherwise
*/
public TBigInteger shiftLeft(int n) {
if ((n == 0) || (sign == 0)) {
if (n == 0 || sign == 0) {
return this;
}
return ((n > 0) ? TBitLevel.shiftLeft(this, n) : TBitLevel.shiftRight(this, -n));
return n > 0 ? TBitLevel.shiftLeft(this, n) : TBitLevel.shiftRight(this, -n);
}
TBigInteger shiftLeftOneBit() {
@ -627,17 +626,17 @@ public class TBigInteger extends Number implements Comparable<TBigInteger>, Seri
*/
public boolean testBit(int n) {
if (n == 0) {
return ((digits[0] & 1) != 0);
return (digits[0] & 1) != 0;
}
if (n < 0) {
throw new ArithmeticException("Negative bit address");
}
int intCount = n >> 5;
if (intCount >= numberLength) {
return (sign < 0);
return sign < 0;
}
int digit = digits[intCount];
n = (1 << (n & 31)); // int with 1 set to the needed position
n = 1 << (n & 31); // int with 1 set to the needed position
if (sign < 0) {
int firstNonZeroDigit = getFirstNonzeroDigit();
if (intCount < firstNonZeroDigit) {
@ -648,7 +647,7 @@ public class TBigInteger extends Number implements Comparable<TBigInteger>, Seri
digit = ~digit;
}
}
return ((digit & n) != 0);
return (digit & n) != 0;
}
/**
@ -730,7 +729,7 @@ public class TBigInteger extends Number implements Comparable<TBigInteger>, Seri
}
// (sign != 0) implies that exists some non zero digit
int i = getFirstNonzeroDigit();
return ((i << 5) + Integer.numberOfTrailingZeros(digits[i]));
return i << 5 + Integer.numberOfTrailingZeros(digits[i]);
}
/**
@ -840,7 +839,7 @@ public class TBigInteger extends Number implements Comparable<TBigInteger>, Seri
*/
@Override
public int intValue() {
return (sign * digits[0]);
return sign * digits[0];
}
/**
@ -853,7 +852,7 @@ public class TBigInteger extends Number implements Comparable<TBigInteger>, Seri
public long longValue() {
long value = (numberLength > 1) ? (((long) digits[1]) << 32) | (digits[0] & 0xFFFFFFFFL)
: (digits[0] & 0xFFFFFFFFL);
return (sign * value);
return sign * value;
}
/**
@ -913,7 +912,7 @@ public class TBigInteger extends Number implements Comparable<TBigInteger>, Seri
return -val.sign;
}
// Equal sign and equal numberLength
return (sign * TElementary.compareArrays(digits, val.digits, numberLength));
return sign * TElementary.compareArrays(digits, val.digits, numberLength);
}
/**
@ -926,7 +925,7 @@ public class TBigInteger extends Number implements Comparable<TBigInteger>, Seri
* if {@code val == null}.
*/
public TBigInteger min(TBigInteger val) {
return ((this.compareTo(val) == LESS) ? this : val);
return (this.compareTo(val) == LESS) ? this : val;
}
/**
@ -939,7 +938,7 @@ public class TBigInteger extends Number implements Comparable<TBigInteger>, Seri
* if {@code val == null}
*/
public TBigInteger max(TBigInteger val) {
return ((this.compareTo(val) == GREATER) ? this : val);
return this.compareTo(val) == GREATER ? this : val;
}
/**
@ -953,7 +952,7 @@ public class TBigInteger extends Number implements Comparable<TBigInteger>, Seri
return hashCode;
}
for (int i = 0; i < digits.length; i++) {
hashCode = (hashCode * 33 + (digits[i] & 0xffffffff));
hashCode = hashCode * 33 + (digits[i] & 0xffffffff);
}
hashCode = hashCode * sign;
return hashCode;
@ -1038,8 +1037,8 @@ public class TBigInteger extends Number implements Comparable<TBigInteger>, Seri
// Optimization for small operands
// (op2.bitLength() < 64) and (op1.bitLength() < 64)
if (((val1.numberLength == 1) || ((val1.numberLength == 2) && (val1.digits[1] > 0))) &&
(val2.numberLength == 1 || (val2.numberLength == 2 && val2.digits[1] > 0))) {
if (((val1.numberLength == 1) || ((val1.numberLength == 2) && (val1.digits[1] > 0)))
&& (val2.numberLength == 1 || (val2.numberLength == 2 && val2.digits[1] > 0))) {
return TBigInteger.valueOf(TDivision.gcdBinary(val1.longValue(), val2.longValue()));
}
@ -1133,9 +1132,9 @@ public class TBigInteger extends Number implements Comparable<TBigInteger>, Seri
int thisSign = sign;
int quotientLength = thisLen - divisorLen + 1;
int remainderLength = divisorLen;
int quotientSign = ((thisSign == divisorSign) ? 1 : -1);
int quotientDigits[] = new int[quotientLength];
int remainderDigits[] = TDivision.divide(quotientDigits, quotientLength, thisDigits, thisLen, divisorDigits,
int quotientSign = thisSign == divisorSign ? 1 : -1;
int[] quotientDigits = new int[quotientLength];
int[] remainderDigits = TDivision.divide(quotientDigits, quotientLength, thisDigits, thisLen, divisorDigits,
divisorLen);
TBigInteger result0 = new TBigInteger(quotientSign, quotientLength, quotientDigits);
TBigInteger result1 = new TBigInteger(thisSign, remainderLength, remainderDigits);
@ -1161,7 +1160,7 @@ public class TBigInteger extends Number implements Comparable<TBigInteger>, Seri
}
int divisorSign = divisor.sign;
if (divisor.isOne()) {
return ((divisor.sign > 0) ? this : this.negate());
return divisor.sign > 0 ? this : this.negate();
}
int thisSign = sign;
int thisLen = numberLength;
@ -1173,17 +1172,17 @@ public class TBigInteger extends Number implements Comparable<TBigInteger>, Seri
}
return valueOf(val);
}
int cmp = ((thisLen != divisorLen) ? ((thisLen > divisorLen) ? 1 : -1) : TElementary.compareArrays(digits,
divisor.digits, thisLen));
int cmp = thisLen != divisorLen ? (thisLen > divisorLen ? 1 : -1) : TElementary.compareArrays(digits,
divisor.digits, thisLen);
if (cmp == EQUALS) {
return ((thisSign == divisorSign) ? ONE : MINUS_ONE);
return thisSign == divisorSign ? ONE : MINUS_ONE;
}
if (cmp == LESS) {
return ZERO;
}
int resLength = thisLen - divisorLen + 1;
int resDigits[] = new int[resLength];
int resSign = ((thisSign == divisorSign) ? 1 : -1);
int[] resDigits = new int[resLength];
int resSign = thisSign == divisorSign ? 1 : -1;
if (divisorLen == 1) {
TDivision.divideArrayByInt(resDigits, digits, thisLen, divisor.digits[0]);
} else {
@ -1218,7 +1217,7 @@ public class TBigInteger extends Number implements Comparable<TBigInteger>, Seri
return this;
}
int resLength = divisorLen;
int resDigits[] = new int[resLength];
int[] resDigits = new int[resLength];
if (resLength == 1) {
resDigits[0] = TDivision.remainderArrayByInt(digits, thisLen, divisor.digits[0]);
} else {
@ -1263,7 +1262,7 @@ public class TBigInteger extends Number implements Comparable<TBigInteger>, Seri
throw new ArithmeticException("BigInteger not invertible.");
}
res = ((sign < 0) ? m.subtract(res) : res);
res = sign < 0 ? m.subtract(res) : res;
return res;
}
@ -1402,7 +1401,7 @@ public class TBigInteger extends Number implements Comparable<TBigInteger>, Seri
/** Tests if {@code this.abs()} is equals to {@code ONE} */
boolean isOne() {
return ((numberLength == 1) && (digits[0] == 1));
return numberLength == 1 && digits[0] == 1;
}
/**
@ -1416,8 +1415,8 @@ public class TBigInteger extends Number implements Comparable<TBigInteger>, Seri
int i = 0;
// Put bytes to the int array starting from the end of the byte array
while (bytesLen > highBytes) {
digits[i++] = (byteValues[--bytesLen] & 0xFF) | (byteValues[--bytesLen] & 0xFF) << 8 |
(byteValues[--bytesLen] & 0xFF) << 16 | (byteValues[--bytesLen] & 0xFF) << 24;
digits[i++] = (byteValues[--bytesLen] & 0xFF) | (byteValues[--bytesLen] & 0xFF) << 8
| (byteValues[--bytesLen] & 0xFF) << 16 | (byteValues[--bytesLen] & 0xFF) << 24;
}
// Put the first bytes in the highest element of the int array
for (int j = 0; j < bytesLen; j++) {
@ -1439,15 +1438,15 @@ public class TBigInteger extends Number implements Comparable<TBigInteger>, Seri
digits[numberLength - 1] = -1;
// Put bytes to the int array starting from the end of the byte array
while (bytesLen > highBytes) {
digits[i] = (byteValues[--bytesLen] & 0xFF) | (byteValues[--bytesLen] & 0xFF) << 8 |
(byteValues[--bytesLen] & 0xFF) << 16 | (byteValues[--bytesLen] & 0xFF) << 24;
digits[i] = (byteValues[--bytesLen] & 0xFF) | (byteValues[--bytesLen] & 0xFF) << 8
| (byteValues[--bytesLen] & 0xFF) << 16 | (byteValues[--bytesLen] & 0xFF) << 24;
if (digits[i] != 0) {
digits[i] = -digits[i];
firstNonzeroDigit = i;
i++;
while (bytesLen > highBytes) {
digits[i] = (byteValues[--bytesLen] & 0xFF) | (byteValues[--bytesLen] & 0xFF) << 8 |
(byteValues[--bytesLen] & 0xFF) << 16 | (byteValues[--bytesLen] & 0xFF) << 24;
digits[i] = (byteValues[--bytesLen] & 0xFF) | (byteValues[--bytesLen] & 0xFF) << 8
| (byteValues[--bytesLen] & 0xFF) << 16 | (byteValues[--bytesLen] & 0xFF) << 24;
digits[i] = ~digits[i];
i++;
}
@ -1505,7 +1504,7 @@ public class TBigInteger extends Number implements Comparable<TBigInteger>, Seri
}
int intCount = exp >> 5;
int bitN = exp & 31;
int resDigits[] = new int[intCount + 1];
int[] resDigits = new int[intCount + 1];
resDigits[intCount] = 1 << bitN;
return new TBigInteger(1, intCount + 1, resDigits);
}

View File

@ -1,10 +1,9 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You 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
* Copyright 2015 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
*
@ -14,7 +13,6 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.teavm.classlib.java.math;
/**
@ -43,7 +41,7 @@ class TBitLevel {
if (val.sign == 0) {
return 0;
}
int bLength = (val.numberLength << 5);
int bLength = val.numberLength << 5;
int highDigit = val.digits[val.numberLength - 1];
if (val.sign < 0) {
@ -71,7 +69,8 @@ class TBitLevel {
for (; i < val.numberLength; i++) {
bCount += Integer.bitCount(val.digits[i]);
}
} else {// (sign < 0)
} else {
// (sign < 0)
// this digit absorbs the carry
bCount += Integer.bitCount(-val.digits[i]);
for (i++; i < val.numberLength; i++) {
@ -89,7 +88,7 @@ class TBitLevel {
*/
static boolean testBit(TBigInteger val, int n) {
// PRE: 0 <= n < val.bitLength()
return ((val.digits[n >> 5] & (1 << (n & 31))) != 0);
return (val.digits[n >> 5] & (1 << (n & 31))) != 0;
}
/**
@ -99,15 +98,15 @@ class TBitLevel {
* the number of the lowest bits to check
* @return false if all bits are 0s, true otherwise
*/
static boolean nonZeroDroppedBits(int numberOfBits, int digits[]) {
static boolean nonZeroDroppedBits(int numberOfBits, int[] digits) {
int intCount = numberOfBits >> 5;
int bitCount = numberOfBits & 31;
int i;
for (i = 0; (i < intCount) && (digits[i] == 0); i++) {
for (i = 0; i < intCount && digits[i] == 0; i++) {
// do nothing
}
return ((i != intCount) || (digits[i] << (32 - bitCount) != 0));
return i != intCount || digits[i] << (32 - bitCount) != 0;
}
/** @see TBigInteger#shiftLeft(int) */
@ -115,7 +114,7 @@ class TBitLevel {
int intCount = count >> 5;
count &= 31; // %= 32
int resLength = source.numberLength + intCount + ((count == 0) ? 0 : 1);
int resDigits[] = new int[resLength];
int[] resDigits = new int[resLength];
shiftLeft(resDigits, source.digits, intCount, count);
TBigInteger result = new TBigInteger(source.sign, resLength, resDigits);
@ -129,8 +128,8 @@ class TBitLevel {
// val should have enough place (and one digit more)
static void inplaceShiftLeft(TBigInteger val, int count) {
int intCount = count >> 5; // count of integers
val.numberLength += intCount +
(Integer.numberOfLeadingZeros(val.digits[val.numberLength - 1]) - (count & 31) >= 0 ? 0 : 1);
val.numberLength += intCount
+ (Integer.numberOfLeadingZeros(val.digits[val.numberLength - 1]) - (count & 31) >= 0 ? 0 : 1);
shiftLeft(val.digits, val.digits, intCount, count & 31);
val.cutOffLeadingZeroes();
val.unCache();
@ -149,7 +148,7 @@ class TBitLevel {
* @param count
* an additional shift distance in bits
*/
static void shiftLeft(int result[], int source[], int intCount, int count) {
static void shiftLeft(int[] result, int[] source, int intCount, int count) {
if (count == 0) {
System.arraycopy(source, 0, result, intCount, result.length - intCount);
} else {
@ -183,7 +182,7 @@ class TBitLevel {
* the length of {@code source}; may be less than
* {@code source.length}
*/
static void shiftLeftOneBit(int result[], int source[], int srcLen) {
static void shiftLeftOneBit(int[] result, int[] source, int srcLen) {
int carry = 0;
for (int i = 0; i < srcLen; i++) {
int val = source[i];
@ -198,7 +197,7 @@ class TBitLevel {
static TBigInteger shiftLeftOneBit(TBigInteger source) {
int srcLen = source.numberLength;
int resLen = srcLen + 1;
int resDigits[] = new int[resLen];
int[] resDigits = new int[resLen];
shiftLeftOneBit(resDigits, source.digits, srcLen);
TBigInteger result = new TBigInteger(source.sign, resLen, resDigits);
result.cutOffLeadingZeroes();
@ -210,11 +209,11 @@ class TBitLevel {
int intCount = count >> 5; // count of integers
count &= 31; // count of remaining bits
if (intCount >= source.numberLength) {
return ((source.sign < 0) ? TBigInteger.MINUS_ONE : TBigInteger.ZERO);
return source.sign < 0 ? TBigInteger.MINUS_ONE : TBigInteger.ZERO;
}
int i;
int resLength = source.numberLength - intCount;
int resDigits[] = new int[resLength + 1];
int[] resDigits = new int[resLength + 1];
shiftRight(resDigits, resLength, source.digits, intCount, count);
if (source.sign < 0) {
@ -244,8 +243,9 @@ class TBitLevel {
*/
static void inplaceShiftRight(TBigInteger val, int count) {
int sign = val.signum();
if (count == 0 || val.signum() == 0)
if (count == 0 || val.signum() == 0) {
return;
}
int intCount = count >> 5; // count of integers
val.numberLength -= intCount;
if (!shiftRight(val.digits, val.numberLength, val.digits, intCount, count & 31) && sign < 0) {
@ -279,7 +279,7 @@ class TBitLevel {
* the number of bits to be shifted
* @return dropped bit's are all zero (i.e. remaider is zero)
*/
static boolean shiftRight(int result[], int resultLen, int source[], int intCount, int count) {
static boolean shiftRight(int[] result, int resultLen, int[] source, int intCount, int count) {
int i;
boolean allZero = true;
for (i = 0; i < intCount; i++) {
@ -295,7 +295,7 @@ class TBitLevel {
for (i = 0; i < resultLen - 1; i++) {
result[i] = (source[i + intCount] >>> count) | (source[i + intCount + 1] << leftShiftCount);
}
result[i] = (source[i + intCount] >>> count);
result[i] = source[i + intCount] >>> count;
i++;
}
@ -317,7 +317,7 @@ class TBitLevel {
int intCount = n >> 5;
int bitN = n & 31;
int resLength = Math.max(intCount + 1, val.numberLength) + 1;
int resDigits[] = new int[resLength];
int[] resDigits = new int[resLength];
int i;
int bitNumber = 1 << bitN;
@ -348,7 +348,8 @@ class TBitLevel {
}
}
}
} else {// case where val is positive
} else {
// case where val is positive
resDigits[intCount] ^= bitNumber;
}
TBigInteger result = new TBigInteger(resSign, resLength, resDigits);

View File

@ -1,10 +1,9 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You 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
* Copyright 2015 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
*
@ -14,7 +13,6 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.teavm.classlib.java.math;
/**
@ -24,7 +22,8 @@ package org.teavm.classlib.java.math;
class TConversion {
/** Just to denote that this class can't be instantiated */
private TConversion() {}
private TConversion() {
}
/**
* Holds the maximal exponent for each radix, so that radix<sup>digitFitInInt[radix]</sup>
@ -39,7 +38,7 @@ class TConversion {
* 2 ^ 31, bigRadices[8] = 10 ^ 9, etc.
*/
static final int bigRadices[] = { -2147483648, 1162261467, 1073741824, 1220703125, 362797056, 1977326743,
static final int[] bigRadices = { -2147483648, 1162261467, 1073741824, 1220703125, 362797056, 1977326743,
1073741824, 387420489, 1000000000, 214358881, 429981696, 815730721, 1475789056, 170859375, 268435456,
410338673, 612220032, 893871739, 1280000000, 1801088541, 113379904, 148035889, 191102976, 244140625,
308915776, 387420489, 481890304, 594823321, 729000000, 887503681, 1073741824, 1291467969, 1544804416,
@ -50,7 +49,7 @@ class TConversion {
static String bigInteger2String(TBigInteger val, int radix) {
int sign = val.sign;
int numberLength = val.numberLength;
int digits[] = val.digits;
int[] digits = val.digits;
if (sign == 0) {
return "0";
@ -70,11 +69,11 @@ class TConversion {
bitsForRadixDigit = Math.log(radix) / Math.log(2);
int resLengthInChars = (int) (val.abs().bitLength() / bitsForRadixDigit + ((sign < 0) ? 1 : 0)) + 1;
char result[] = new char[resLengthInChars];
char[] result = new char[resLengthInChars];
int currentChar = resLengthInChars;
int resDigit;
if (radix != 16) {
int temp[] = new int[numberLength];
int[] temp = new int[numberLength];
System.arraycopy(digits, 0, temp, 0, numberLength);
int tempLen = numberLength;
int charsPerInt = digitFitInInt[radix];
@ -88,7 +87,8 @@ class TConversion {
int previous = currentChar;
do {
result[--currentChar] = Character.forDigit(resDigit % radix, radix);
} while (((resDigit /= radix) != 0) && (currentChar != 0));
resDigit /= radix;
} while (resDigit != 0 && currentChar != 0);
int delta = charsPerInt - previous + currentChar;
for (i = 0; i < delta && currentChar > 0; i++) {
result[--currentChar] = '0';
@ -129,10 +129,10 @@ class TConversion {
static String toDecimalScaledString(TBigInteger val, int scale) {
int sign = val.sign;
int numberLength = val.numberLength;
int digits[] = val.digits;
int[] digits = val.digits;
int resLengthInChars;
int currentChar;
char result[];
char[] result;
if (sign == 0) {
switch (scale) {
@ -190,7 +190,7 @@ class TConversion {
} while (v != 0);
}
} else {
int temp[] = new int[numberLength];
int[] temp = new int[numberLength];
int tempLen = numberLength;
System.arraycopy(digits, 0, temp, 0, tempLen);
BIG_LOOP: while (true) {
@ -208,7 +208,8 @@ class TConversion {
int previous = currentChar;
do {
result[--currentChar] = (char) (0x0030 + (resDigit % 10));
} while ((resDigit /= 10) != 0 && currentChar != 0);
resDigit /= 10;
} while (resDigit != 0 && currentChar != 0);
int delta = 9 - previous + currentChar;
for (int i = 0; (i < delta) && (currentChar > 0); i++) {
result[--currentChar] = '0';
@ -225,7 +226,7 @@ class TConversion {
currentChar++;
}
}
boolean negNumber = (sign < 0);
boolean negNumber = sign < 0;
int exponent = resLengthInChars - currentChar - scale - 1;
if (scale == 0) {
if (negNumber) {
@ -282,7 +283,7 @@ class TConversion {
static String toDecimalScaledString(long value, int scale) {
int resLengthInChars;
int currentChar;
char result[];
char[] result;
boolean negNumber = value < 0;
if (negNumber) {
value = -value;
@ -382,8 +383,8 @@ class TConversion {
if (a >= 0) {
long bLong = 1000000000L;
quot = (a / bLong);
rem = (a % bLong);
quot = a / bLong;
rem = a % bLong;
} else {
/*
* Make the dividend positive shifting it right by 1 bit then get

View File

@ -1,10 +1,9 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You 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
* Copyright 2015 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
*
@ -14,7 +13,6 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.teavm.classlib.java.math;
/**
@ -39,6 +37,8 @@ package org.teavm.classlib.java.math;
* </ul>
*/
class TDivision {
private TDivision() {
}
/**
* Divides the array 'a' by the array 'b' and gets the quotient and the
@ -60,11 +60,11 @@ class TDivision {
* the divisor's length
* @return the remainder
*/
static int[] divide(int quot[], int quotLength, int a[], int aLength, int b[], int bLength) {
static int[] divide(int[] quot, int quotLength, int[] a, int aLength, int[] b, int bLength) {
int normA[] = new int[aLength + 1]; // the normalized dividend
int[] normA = new int[aLength + 1]; // the normalized dividend
// an extra byte is needed for correct shift
int normB[] = new int[bLength + 1]; // the normalized divisor;
int[] normB = new int[bLength + 1]; // the normalized divisor;
int normBLength = bLength;
/*
* Step D1: normalize a and b and put the results to a1 and b1 the
@ -90,7 +90,7 @@ class TDivision {
// set guessDigit to the largest unsigned int value
guessDigit = -1;
} else {
long product = (((normA[j] & 0xffffffffL) << 32) + (normA[j - 1] & 0xffffffffL));
long product = ((normA[j] & 0xffffffffL) << 32) + (normA[j - 1] & 0xffffffffL);
long res = TDivision.divideLongByInt(product, firstDivisorDigit);
guessDigit = (int) res; // the quotient of divideLongByInt
int rem = (int) (res >> 32); // the remainder of
@ -125,7 +125,7 @@ class TDivision {
} else {
rem = (int) longR;
}
} while (((leftHand ^ 0x8000000000000000L) > (rightHand ^ 0x8000000000000000L)));
} while ((leftHand ^ 0x8000000000000000L) > (rightHand ^ 0x8000000000000000L));
}
}
// Step D4: multiply normB by guessDigit and subtract the production
@ -177,7 +177,7 @@ class TDivision {
* the divisor
* @return remainder
*/
static int divideArrayByInt(int dest[], int src[], final int srcLength, final int divisor) {
static int divideArrayByInt(int[] dest, int[] src, final int srcLength, final int divisor) {
long rem = 0;
long bLong = divisor & 0xffffffffL;
@ -186,8 +186,8 @@ class TDivision {
long temp = (rem << 32) | (src[i] & 0xffffffffL);
long quot;
if (temp >= 0) {
quot = (temp / bLong);
rem = (temp % bLong);
quot = temp / bLong;
rem = temp % bLong;
} else {
/*
* make the dividend positive shifting it right by 1 bit then
@ -231,7 +231,7 @@ class TDivision {
* the divisor
* @return remainder
*/
static int remainderArrayByInt(int src[], final int srcLength, final int divisor) {
static int remainderArrayByInt(int[] src, final int srcLength, final int divisor) {
long result = 0;
@ -274,8 +274,8 @@ class TDivision {
long bLong = b & 0xffffffffL;
if (a >= 0) {
quot = (a / bLong);
rem = (a % bLong);
quot = a / bLong;
rem = a % bLong;
} else {
/*
* Make the dividend positive shifting it right by 1 bit then get
@ -316,8 +316,8 @@ class TDivision {
int valLen = val.numberLength;
int valSign = val.sign;
if (valLen == 1) {
long a = (valDigits[0] & 0xffffffffL);
long b = (divisor & 0xffffffffL);
long a = valDigits[0] & 0xffffffffL;
long b = divisor & 0xffffffffL;
long quo = a / b;
long rem = a % b;
if (valSign != divisorSign) {
@ -329,10 +329,9 @@ class TDivision {
return new TBigInteger[] { TBigInteger.valueOf(quo), TBigInteger.valueOf(rem) };
}
int quotientLength = valLen;
int quotientSign = ((valSign == divisorSign) ? 1 : -1);
int quotientDigits[] = new int[quotientLength];
int remainderDigits[];
remainderDigits = new int[] { TDivision.divideArrayByInt(quotientDigits, valDigits, valLen, divisor) };
int quotientSign = valSign == divisorSign ? 1 : -1;
int[] quotientDigits = new int[quotientLength];
int[] remainderDigits = { TDivision.divideArrayByInt(quotientDigits, valDigits, valLen, divisor) };
TBigInteger result0 = new TBigInteger(quotientSign, quotientLength, quotientDigits);
TBigInteger result1 = new TBigInteger(valSign, 1, remainderDigits);
result0.cutOffLeadingZeroes();
@ -356,7 +355,7 @@ class TDivision {
* the multiplier of b
* @return the carry element of subtraction
*/
static int multiplyAndSubtract(int a[], int start, int b[], int bLen, int c) {
static int multiplyAndSubtract(int[] a, int start, int[] b, int bLen, int c) {
long carry0 = 0;
long carry1 = 0;
@ -472,7 +471,7 @@ class TDivision {
op2 >>>= Long.numberOfTrailingZeros(op2);
}
} while (op1 != 0);
return (op2 << pow2Count);
return op2 << pow2Count;
}
/**
@ -493,7 +492,10 @@ class TDivision {
int m = p.numberLength * 32;
// PRE: a \in [1, p - 1]
TBigInteger u, v, r, s;
TBigInteger u;
TBigInteger v;
TBigInteger r;
TBigInteger s;
u = p.copy(); // make copy to use inplace method
v = a.copy();
int max = Math.max(v.numberLength, u.numberLength);
@ -536,8 +538,9 @@ class TDivision {
while (u.compareTo(v) <= TBigInteger.EQUALS) {
TElementary.inplaceSubtract(v, u);
if (v.signum() == 0)
if (v.signum() == 0) {
break;
}
toShift = v.getLowestSetBit();
TBitLevel.inplaceShiftRight(v, toShift);
TElementary.inplaceAdd(s, r);
@ -608,7 +611,11 @@ class TDivision {
*/
static TBigInteger modInverseHars(TBigInteger a, TBigInteger m) {
// PRE: (a > 0) and (m > 0)
TBigInteger u, v, r, s, temp;
TBigInteger u;
TBigInteger v;
TBigInteger r;
TBigInteger s;
TBigInteger temp;
// u = MAX(a,m), v = MIN(a,m)
if (a.compareTo(m) == TBigInteger.LESS) {
u = m;
@ -675,9 +682,10 @@ class TDivision {
*
* @see #oddModPow(BigInteger, BigInteger, BigInteger)
*/
static TBigInteger slidingWindow(TBigInteger x2, TBigInteger a2, TBigInteger exponent, TBigInteger modulus, int n2) {
static TBigInteger slidingWindow(TBigInteger x2, TBigInteger a2, TBigInteger exponent,
TBigInteger modulus, int n2) {
// fill odd low pows of a2
TBigInteger pows[] = new TBigInteger[8];
TBigInteger[] pows = new TBigInteger[8];
TBigInteger res = x2;
int lowexp;
TBigInteger x3;
@ -730,7 +738,7 @@ class TDivision {
*/
static TBigInteger oddModPow(TBigInteger base, TBigInteger exponent, TBigInteger modulus) {
// PRE: (base > 0), (exponent > 0), (modulus > 0) and (odd modulus)
int k = (modulus.numberLength << 5); // r = 2^k
int k = modulus.numberLength << 5; // r = 2^k
// n-residue of base [base * r (mod modulus)]
TBigInteger a2 = base.shiftLeft(k).mod(modulus);
// n-residue of base [1 * r (mod modulus)]
@ -818,7 +826,7 @@ class TDivision {
private static void monReduction(int[] res, TBigInteger modulus, int n2) {
/* res + m*modulus_digits */
int[] modulus_digits = modulus.digits;
int[] modulusDigits = modulus.digits;
int modulusLen = modulus.numberLength;
long outerCarry = 0;
@ -826,7 +834,7 @@ class TDivision {
long innnerCarry = 0;
int m = (int) TMultiplication.unsignedMultAddAdd(res[i], n2, 0, 0);
for (int j = 0; j < modulusLen; j++) {
innnerCarry = TMultiplication.unsignedMultAddAdd(m, modulus_digits[j], res[i + j], (int) innnerCarry);
innnerCarry = TMultiplication.unsignedMultAddAdd(m, modulusDigits[j], res[i + j], (int) innnerCarry);
res[i + j] = (int) innnerCarry;
innnerCarry >>>= 32;
}
@ -863,7 +871,7 @@ class TDivision {
*/
static TBigInteger monPro(TBigInteger a, TBigInteger b, TBigInteger modulus, int n2) {
int modulusLen = modulus.numberLength;
int res[] = new int[(modulusLen << 1) + 1];
int[] res = new int[(modulusLen << 1) + 1];
TMultiplication.multArraysPAP(a.digits, Math.min(modulusLen, a.numberLength), b.digits,
Math.min(modulusLen, b.numberLength), res);
monReduction(res, modulus, n2);
@ -877,13 +885,13 @@ class TDivision {
* @see #monPro(TBigInteger, TBigInteger, TBigInteger, long)
* @see #monSquare(TBigInteger, TBigInteger, long)
*/
static TBigInteger finalSubtraction(int res[], TBigInteger modulus) {
static TBigInteger finalSubtraction(int[] res, TBigInteger modulus) {
// skipping leading zeros
int modulusLen = modulus.numberLength;
boolean doSub = res[modulusLen] != 0;
if (!doSub) {
int modulusDigits[] = modulus.digits;
int[] modulusDigits = modulus.digits;
doSub = true;
for (int i = modulusLen - 1; i >= 0; i--) {
if (res[i] != modulusDigits[i]) {
@ -921,7 +929,7 @@ class TDivision {
for (int i = 1; i < n; i++) {
if (TBitLevel.testBit(x.multiply(y), i)) {
// Adding 2^i to y (setting the i-th bit)
y.digits[i >> 5] |= (1 << (i & 31));
y.digits[i >> 5] |= 1 << (i & 31);
}
}
return y;

View File

@ -1,10 +1,9 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You 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
* Copyright 2015 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
*
@ -14,7 +13,6 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.teavm.classlib.java.math;
/**
@ -51,13 +49,14 @@ class TElementary {
for (i = size - 1; (i >= 0) && (a[i] == b[i]); i--) {
// do nothing
}
return ((i < 0) ? TBigInteger.EQUALS : (a[i] & 0xFFFFFFFFL) < (b[i] & 0xFFFFFFFFL) ? TBigInteger.LESS
: TBigInteger.GREATER);
return i < 0
? TBigInteger.EQUALS
: (a[i] & 0xFFFFFFFFL) < (b[i] & 0xFFFFFFFFL) ? TBigInteger.LESS : TBigInteger.GREATER;
}
/** @see TBigInteger#add(TBigInteger) */
static TBigInteger add(TBigInteger op1, TBigInteger op2) {
int resDigits[];
int[] resDigits;
int resSign;
int op1Sign = op1.sign;
int op2Sign = op2.sign;
@ -72,8 +71,8 @@ class TElementary {
int op2Len = op2.numberLength;
if (op1Len + op2Len == 2) {
long a = (op1.digits[0] & 0xFFFFFFFFL);
long b = (op2.digits[0] & 0xFFFFFFFFL);
long a = op1.digits[0] & 0xFFFFFFFFL;
long b = op2.digits[0] & 0xFFFFFFFFL;
long res;
int valueLo;
int valueHi;
@ -82,8 +81,8 @@ class TElementary {
res = a + b;
valueLo = (int) res;
valueHi = (int) (res >>> 32);
return ((valueHi == 0) ? new TBigInteger(op1Sign, valueLo) : new TBigInteger(op1Sign, 2, new int[] {
valueLo, valueHi }));
return valueHi == 0 ? new TBigInteger(op1Sign, valueLo) : new TBigInteger(op1Sign, 2, new int[] {
valueLo, valueHi });
}
return TBigInteger.valueOf((op1Sign < 0) ? (b - a) : (a - b));
} else if (op1Sign == op2Sign) {
@ -92,8 +91,9 @@ class TElementary {
resDigits = (op1Len >= op2Len) ? add(op1.digits, op1Len, op2.digits, op2Len) : add(op2.digits, op2Len,
op1.digits, op1Len);
} else { // signs are different
int cmp = ((op1Len != op2Len) ? ((op1Len > op2Len) ? 1 : -1)
: compareArrays(op1.digits, op2.digits, op1Len));
int cmp = op1Len != op2Len
? (op1Len > op2Len ? 1 : -1)
: compareArrays(op1.digits, op2.digits, op1Len);
if (cmp == TBigInteger.EQUALS) {
return TBigInteger.ZERO;
@ -115,7 +115,7 @@ class TElementary {
/**
* Performs {@code res = a + b}.
*/
private static void add(int res[], int a[], int aSize, int b[], int bSize) {
private static void add(int[] res, int[] a, int aSize, int[] b, int bSize) {
// PRE: a.length < max(aSize, bSize)
int i;
@ -155,7 +155,7 @@ class TElementary {
/** @see TBigInteger#subtract(TBigInteger) */
static TBigInteger subtract(TBigInteger op1, TBigInteger op2) {
int resSign;
int resDigits[];
int[] resDigits;
int op1Sign = op1.sign;
int op2Sign = op2.sign;
@ -168,8 +168,8 @@ class TElementary {
int op1Len = op1.numberLength;
int op2Len = op2.numberLength;
if (op1Len + op2Len == 2) {
long a = (op1.digits[0] & 0xFFFFFFFFL);
long b = (op2.digits[0] & 0xFFFFFFFFL);
long a = op1.digits[0] & 0xFFFFFFFFL;
long b = op2.digits[0] & 0xFFFFFFFFL;
if (op1Sign < 0) {
a = -a;
}
@ -178,8 +178,9 @@ class TElementary {
}
return TBigInteger.valueOf(a - b);
}
int cmp = ((op1Len != op2Len) ? ((op1Len > op2Len) ? 1 : -1) : TElementary.compareArrays(op1.digits, op2.digits,
op1Len));
int cmp = op1Len != op2Len
? (op1Len > op2Len ? 1 : -1)
: TElementary.compareArrays(op1.digits, op2.digits, op1Len);
if (cmp == TBigInteger.LESS) {
resSign = -op2Sign;
@ -205,7 +206,7 @@ class TElementary {
* Performs {@code res = a - b}. It is assumed the magnitude of a is not
* less than the magnitude of b.
*/
private static void subtract(int res[], int a[], int aSize, int b[], int bSize) {
private static void subtract(int[] res, int[] a, int aSize, int[] b, int bSize) {
// PRE: a[] >= b[]
int i;
long borrow = 0;
@ -229,9 +230,9 @@ class TElementary {
*
* @return {@code a + b}
*/
private static int[] add(int a[], int aSize, int b[], int bSize) {
private static int[] add(int[] a, int aSize, int[] b, int bSize) {
// PRE: a[] >= b[]
int res[] = new int[aSize + 1];
int[] res = new int[aSize + 1];
add(res, a, aSize, b, bSize);
return res;
}
@ -259,7 +260,7 @@ class TElementary {
*
* @return a possible generated carry (0 or 1)
*/
static int inplaceAdd(int a[], final int aSize, final int addend) {
static int inplaceAdd(int[] a, final int aSize, final int addend) {
long carry = addend & 0xFFFFFFFFL;
for (int i = 0; (carry != 0) && (i < aSize); i++) {
@ -303,7 +304,7 @@ class TElementary {
/**
* Performs {@code res = b - a}
*/
private static void inverseSubtract(int res[], int a[], int aSize, int b[], int bSize) {
private static void inverseSubtract(int[] res, int[] a, int aSize, int[] b, int bSize) {
int i;
long borrow = 0;
if (aSize < bSize) {
@ -339,9 +340,9 @@ class TElementary {
*
* @return {@code a - b}
*/
private static int[] subtract(int a[], int aSize, int b[], int bSize) {
private static int[] subtract(int[] a, int aSize, int[] b, int bSize) {
// PRE: a[] >= b[]
int res[] = new int[aSize];
int[] res = new int[aSize];
subtract(res, a, aSize, b, bSize);
return res;
}
@ -387,17 +388,17 @@ class TElementary {
* any number
*/
static void completeInPlaceAdd(TBigInteger op1, TBigInteger op2) {
if (op1.sign == 0)
if (op1.sign == 0) {
System.arraycopy(op2.digits, 0, op1.digits, 0, op2.numberLength);
else if (op2.sign == 0)
} else if (op2.sign == 0) {
return;
else if (op1.sign == op2.sign)
} else if (op1.sign == op2.sign) {
add(op1.digits, op1.digits, op1.numberLength, op2.digits, op2.numberLength);
else {
} else {
int sign = unsignedArraysCompare(op1.digits, op2.digits, op1.numberLength, op2.numberLength);
if (sign > 0)
if (sign > 0) {
subtract(op1.digits, op1.digits, op1.numberLength, op2.digits, op2.numberLength);
else {
} else {
inverseSubtract(op1.digits, op1.digits, op1.numberLength, op2.digits, op2.numberLength);
op1.sign = -op1.sign;
}
@ -413,12 +414,11 @@ class TElementary {
* then b
*/
private static int unsignedArraysCompare(int[] a, int[] b, int aSize, int bSize) {
if (aSize > bSize)
if (aSize > bSize) {
return 1;
else if (aSize < bSize)
} else if (aSize < bSize) {
return -1;
else {
} else {
int i;
for (i = aSize - 1; i >= 0 && a[i] == b[i]; i--) {
// do nothing
@ -427,5 +427,4 @@ class TElementary {
: TBigInteger.GREATER);
}
}
}

View File

@ -1,10 +1,9 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You 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
* Copyright 2015 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
*
@ -14,7 +13,6 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.teavm.classlib.java.math;
/**
@ -32,7 +30,8 @@ class TLogical {
/** Just to denote that this class can't be instantiated. */
private TLogical() {}
private TLogical() {
}
/** @see TBigInteger#not() */
@ -43,7 +42,7 @@ class TLogical {
if (val.equals(TBigInteger.MINUS_ONE)) {
return TBigInteger.ZERO;
}
int resDigits[] = new int[val.numberLength + 1];
int[] resDigits = new int[val.numberLength + 1];
int i;
if (val.sign > 0) {
@ -62,7 +61,8 @@ class TLogical {
}
}
// Here a carry 1 was generated
} else {// (val.sign < 0)
} else {
// (val.sign < 0)
// ~val = -val - 1
for (i = 0; val.digits[i] == 0; i++) {
resDigits[i] = -1;
@ -117,7 +117,7 @@ class TLogical {
return TBigInteger.ZERO;
}
int resDigits[] = new int[resLength];
int[] resDigits = new int[resLength];
for (; i < resLength; i++) {
resDigits[i] = val.digits[i] & that.digits[i];
}
@ -139,7 +139,7 @@ class TLogical {
return TBigInteger.ZERO;
}
int resLength = positive.numberLength;
int resDigits[] = new int[resLength];
int[] resDigits = new int[resLength];
// Must start from max(iPos, iNeg)
int i = Math.max(iPos, iNeg);
@ -177,7 +177,7 @@ class TLogical {
}
int resLength;
int resDigits[];
int[] resDigits;
int i = Math.max(iShorter, iLonger);
int digit;
if (iShorter > iLonger) {
@ -188,13 +188,19 @@ class TLogical {
digit = -shorter.digits[i] & -longer.digits[i];
}
if (digit == 0) {
for (i++; i < shorter.numberLength && (digit = ~(longer.digits[i] | shorter.digits[i])) == 0; i++) {
// do nothing
for (i++; i < shorter.numberLength; i++) {
digit = ~(longer.digits[i] | shorter.digits[i]);
if (digit != 0) {
break;
}
}
if (digit == 0) {
// shorter has only the remaining virtual sign bits
for ( ; i < longer.numberLength && (digit = ~longer.digits[i]) == 0; i++) {
// do nothing
for (; i < longer.numberLength; i++) {
digit = ~longer.digits[i];
if (digit != 0) {
break;
}
}
if (digit == 0) {
resLength = longer.numberLength + 1;
@ -257,7 +263,7 @@ class TLogical {
/** @return sign = 1, magnitude = val.magnitude & ~that.magnitude*/
static TBigInteger andNotPositive(TBigInteger val, TBigInteger that) {
// PRE: both arguments are positive
int resDigits[] = new int[val.numberLength];
int[] resDigits = new int[val.numberLength];
int limit = Math.min(val.numberLength, that.numberLength);
int i;
@ -284,7 +290,7 @@ class TLogical {
}
int resLength = Math.min(positive.numberLength, negative.numberLength);
int resDigits[] = new int[resLength];
int[] resDigits = new int[resLength];
// Always start from first non zero of positive
int i = iPos;
@ -310,7 +316,7 @@ class TLogical {
static TBigInteger andNotNegativePositive(TBigInteger negative, TBigInteger positive) {
// PRE: negative < 0 && positive > 0
int resLength;
int resDigits[];
int[] resDigits;
int limit;
int digit;
@ -341,16 +347,25 @@ class TLogical {
digit = -negative.digits[i] & ~positive.digits[i];
if (digit == 0) {
limit = Math.min(positive.numberLength, negative.numberLength);
for (i++; i < limit && (digit = ~(negative.digits[i] | positive.digits[i])) == 0; i++) {
// do nothing
for (i++; i < limit; i++) {
digit = ~(negative.digits[i] | positive.digits[i]);
if (digit != 0) {
break;
}
}
if (digit == 0) {
// the shorter has only the remaining virtual sign bits
for ( ; i < positive.numberLength && (digit = ~positive.digits[i]) == 0; i++) {
// do nothing
for (; i < positive.numberLength; i++) {
digit = ~positive.digits[i];
if (digit != 0) {
break;
}
}
for (; i < negative.numberLength; i++) {
digit = ~negative.digits[i];
if (digit != 0) {
break;
}
for ( ; i < negative.numberLength && (digit = ~negative.digits[i]) == 0; i++) {
// do nothing
}
if (digit == 0) {
resLength++;
@ -395,7 +410,7 @@ class TLogical {
}
int resLength = that.numberLength;
int resDigits[] = new int[resLength];
int[] resDigits = new int[resLength];
int limit;
int i = iVal;
if (iVal < iThat) {
@ -478,7 +493,7 @@ class TLogical {
// PRE: longer and shorter are positive;
// PRE: longer has at least as many digits as shorter
int resLength = longer.numberLength;
int resDigits[] = new int[resLength];
int[] resDigits = new int[resLength];
int i = Math.min(longer.getFirstNonzeroDigit(), shorter.getFirstNonzeroDigit());
for (i = 0; i < shorter.numberLength; i++) {
@ -507,7 +522,7 @@ class TLogical {
}
int resLength = Math.min(val.numberLength, that.numberLength);
int resDigits[] = new int[resLength];
int[] resDigits = new int[resLength];
//Looking for the first non-zero digit of the result
if (iThat == iVal) {
@ -543,7 +558,7 @@ class TLogical {
return negative;
}
int resLength = negative.numberLength;
int resDigits[] = new int[resLength];
int[] resDigits = new int[resLength];
if (iNeg < iPos) {
// We know for sure that this will
@ -568,7 +583,8 @@ class TLogical {
resDigits[i] = negative.digits[i] - 1;
}
i++;
} else {// iNeg == iPos
} else {
// iNeg == iPos
// Applying two complement to negative and to result
i = iPos;
resDigits[i] = -(-negative.digits[i] | positive.digits[i]);
@ -630,7 +646,7 @@ class TLogical {
// PRE: longer and shorter are positive;
// PRE: longer has at least as many digits as shorter
int resLength = longer.numberLength;
int resDigits[] = new int[resLength];
int[] resDigits = new int[resLength];
int i = Math.min(longer.getFirstNonzeroDigit(), shorter.getFirstNonzeroDigit());
for (; i < shorter.numberLength; i++) {
resDigits[i] = longer.digits[i] ^ shorter.digits[i];
@ -649,7 +665,7 @@ class TLogical {
// PRE: val and that are negative
// PRE: val has at least as many trailing zero digits as that
int resLength = Math.max(val.numberLength, that.numberLength);
int resDigits[] = new int[resLength];
int[] resDigits = new int[resLength];
int iVal = val.getFirstNonzeroDigit();
int iThat = that.getFirstNonzeroDigit();
int i = iThat;
@ -702,7 +718,7 @@ class TLogical {
/** @return sign = 1, magnitude = -(positive.magnitude ^ -negative.magnitude)*/
static TBigInteger xorDiffSigns(TBigInteger positive, TBigInteger negative) {
int resLength = Math.max(negative.numberLength, positive.numberLength);
int resDigits[];
int[] resDigits;
int iNeg = negative.getFirstNonzeroDigit();
int iPos = positive.getFirstNonzeroDigit();
int i;
@ -762,16 +778,25 @@ class TLogical {
digit = positive.digits[i] ^ -negative.digits[i];
if (digit == 0) {
limit = Math.min(positive.numberLength, negative.numberLength);
for (i++; i < limit && (digit = positive.digits[i] ^ ~negative.digits[i]) == 0; i++) {
// do nothing
for (i++; i < limit; i++) {
digit = positive.digits[i] ^ ~negative.digits[i];
if (digit != 0) {
break;
}
}
if (digit == 0) {
// shorter has only the remaining virtual sign bits
for ( ; i < positive.numberLength && (digit = ~positive.digits[i]) == 0; i++) {
// do nothing
for (; i < positive.numberLength; i++) {
digit = ~positive.digits[i];
if (digit != 0) {
break;
}
}
for (; i < negative.numberLength; i++) {
digit = ~negative.digits[i];
if (digit != 0) {
break;
}
for ( ; i < negative.numberLength && (digit = ~negative.digits[i]) == 0; i++) {
// do nothing
}
if (digit == 0) {
resLength = resLength + 1;

View File

@ -1,10 +1,9 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You 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
* Copyright 2015 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
*
@ -14,7 +13,6 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.teavm.classlib.java.math;
import java.io.Serializable;
@ -249,9 +247,9 @@ public final class TMathContext implements Serializable {
*/
@Override
public boolean equals(Object x) {
return ((x instanceof TMathContext)
return x instanceof TMathContext
&& (((TMathContext) x).getPrecision() == precision) && (((TMathContext) x)
.getRoundingMode() == roundingMode));
.getRoundingMode() == roundingMode);
}
/**
@ -262,7 +260,7 @@ public final class TMathContext implements Serializable {
@Override
public int hashCode() {
// Make place for the necessary bits to represent 8 rounding modes
return ((precision << 3) | roundingMode.ordinal());
return (precision << 3) | roundingMode.ordinal();
}
/**

View File

@ -1,10 +1,9 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You 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
* Copyright 2015 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
*
@ -14,7 +13,6 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.teavm.classlib.java.math;
/**
@ -23,7 +21,8 @@ package org.teavm.classlib.java.math;
class TMultiplication {
/** Just to denote that this class can't be instantiated. */
private TMultiplication() {}
private TMultiplication() {
}
/**
* Break point in digits (number of {@code int} elements)
@ -35,7 +34,7 @@ class TMultiplication {
* An array with powers of ten that fit in the type {@code int}.
* ({@code 10^0,10^1,...,10^9})
*/
static final int tenPows[] = {
static final int[] tenPows = {
1, 10, 100, 1000, 10000, 100000, 1000000, 10000000, 100000000, 1000000000
};
@ -43,7 +42,7 @@ class TMultiplication {
* An array with powers of five that fit in the type {@code int}.
* ({@code 5^0,5^1,...,5^13})
*/
static final int fivePows[] = {
static final int[] fivePows = {
1, 5, 25, 125, 625, 3125, 15625, 78125, 390625,
1953125, 9765625, 48828125, 244140625, 1220703125
};
@ -58,9 +57,7 @@ class TMultiplication {
* An array with the first powers of five in {@code BigInteger} version.
* ({@code 5^0,5^1,...,5^31})
*/
static final TBigInteger bigFivePows[] = new TBigInteger[32];
static final TBigInteger[] bigFivePows = new TBigInteger[32];
static {
int i;
@ -93,7 +90,8 @@ class TMultiplication {
* v = v<sub>1</sub> * B + v<sub>0</sub><br>
*
*
* u*v = (u<sub>1</sub> * v<sub>1</sub>) * B<sub>2</sub> + ((u<sub>1</sub> - u<sub>0</sub>) * (v<sub>0</sub> - v<sub>1</sub>) + u<sub>1</sub> * v<sub>1</sub> +
* u*v = (u<sub>1</sub> * v<sub>1</sub>) * B<sub>2</sub> + ((u<sub>1</sub> - u<sub>0</sub>)
* * (v<sub>0</sub> - v<sub>1</sub>) + u<sub>1</sub> * v<sub>1</sub> +
* u<sub>0</sub> * v<sub>0</sub> ) * B + u<sub>0</sub> * v<sub>0</sub><br>
*</tt>
* @param op1 first factor of the product
@ -124,8 +122,7 @@ class TMultiplication {
TBigInteger upper = karatsuba(upperOp1, upperOp2);
TBigInteger lower = karatsuba(lowerOp1, lowerOp2);
TBigInteger middle = karatsuba( upperOp1.subtract(lowerOp1),
lowerOp2.subtract(upperOp2));
TBigInteger middle = karatsuba(upperOp1.subtract(lowerOp1), lowerOp2.subtract(upperOp2));
middle = middle.add(upper).add(lower);
middle = middle.shiftLeft(ndiv2);
upper = upper.shiftLeft(ndiv2 << 1);
@ -231,13 +228,13 @@ class TMultiplication {
long val = unsignedMultAddAdd(a.digits[0], b.digits[0], 0, 0);
int valueLo = (int) val;
int valueHi = (int) (val >>> 32);
return ((valueHi == 0)
return valueHi == 0
? new TBigInteger(resSign, valueLo)
: new TBigInteger(resSign, 2, new int[]{valueLo, valueHi}));
: new TBigInteger(resSign, 2, new int[] { valueLo, valueHi });
}
int[] aDigits = a.digits;
int[] bDigits = b.digits;
int resDigits[] = new int[resLength];
int[] resDigits = new int[resLength];
// Common case
multArraysPAP(aDigits, aLen, bDigits, bLen, resDigits);
TBigInteger result = new TBigInteger(resSign, resLength, resDigits);
@ -246,7 +243,9 @@ class TMultiplication {
}
static void multArraysPAP(int[] aDigits, int aLen, int[] bDigits, int bLen, int[] resDigits) {
if(aLen == 0 || bLen == 0) return;
if (aLen == 0 || bLen == 0) {
return;
}
if (aLen == 1) {
resDigits[bLen] = multiplyByInt(resDigits, bDigits, bLen, aDigits[0]);
@ -257,7 +256,7 @@ class TMultiplication {
}
}
static void multPAP(int a[], int b[], int t[], int aLen, int bLen) {
static void multPAP(int[] a, int[] b, int[] t, int aLen, int bLen) {
if (a == b && aLen == bLen) {
square(a, aLen, t);
return;
@ -283,7 +282,7 @@ class TMultiplication {
* @param factor the multiplier
* @return the top digit of production
*/
private static int multiplyByInt(int res[], int a[], final int aSize, final int factor) {
private static int multiplyByInt(int[] res, int[] a, final int aSize, final int factor) {
long carry = 0;
for (int i = 0; i < aSize; i++) {
carry = unsignedMultAddAdd(a[i], factor, (int) carry, 0);
@ -301,7 +300,7 @@ class TMultiplication {
* @param factor the multiplier
* @return the top digit of production
*/
static int multiplyByInt(int a[], final int aSize, final int factor) {
static int multiplyByInt(int[] a, final int aSize, final int factor) {
return multiplyByInt(a, a, aSize, factor);
}
@ -323,13 +322,13 @@ class TMultiplication {
long res = unsignedMultAddAdd(aDigits[0], factor, 0, 0);
int resLo = (int) res;
int resHi = (int) (res >>> 32);
return ((resHi == 0)
return resHi == 0
? new TBigInteger(resSign, resLo)
: new TBigInteger(resSign, 2, new int[]{resLo, resHi}));
: new TBigInteger(resSign, 2, new int[] { resLo, resHi });
}
// Common case
int resLength = aNumberLength + 1;
int resDigits[] = new int[resLength];
int[] resDigits = new int[resLength];
resDigits[aNumberLength] = multiplyByInt(resDigits, aDigits, aNumberLength, factor);
TBigInteger result = new TBigInteger(resSign, resLength, resDigits);
@ -351,8 +350,7 @@ class TMultiplication {
//a limit where karatsuba performs a faster square than the square algorithm
if (acc.numberLength == 1) {
acc = acc.multiply(acc); // square
}
else{
} else {
acc = new TBigInteger(1, square(acc.digits, acc.numberLength, new int[acc.numberLength << 1]));
}
}
@ -403,9 +401,9 @@ class TMultiplication {
*/
static TBigInteger multiplyByTenPow(TBigInteger val, long exp) {
// PRE: exp >= 0
return ((exp < tenPows.length)
return exp < tenPows.length
? multiplyByPositiveInt(val, tenPows[(int) exp])
: val.multiply(powerOf10(exp)));
: val.multiply(powerOf10(exp));
}
/**
@ -484,7 +482,8 @@ class TMultiplication {
return multiplyByPositiveInt(val, fivePows[exp]);
} else if (exp < bigFivePows.length) {
return val.multiply(bigFivePows[exp]);
} else {// Large powers of five
} else {
// Large powers of five
return val.multiply(bigFivePows[1].pow(exp));
}
}

View File

@ -1,10 +1,9 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You 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
* Copyright 2015 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
*
@ -14,7 +13,6 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.teavm.classlib.java.math;
import java.util.Arrays;
@ -30,7 +28,7 @@ class TPrimality {
}
/** All prime numbers with bit length lesser than 10 bits. */
private static final int primes[] = { 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71,
private static final int[] primes = { 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71,
73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167, 173, 179, 181,
191, 193, 197, 199, 211, 223, 227, 229, 233, 239, 241, 251, 257, 263, 269, 271, 277, 281, 283, 293, 307,
311, 313, 317, 331, 337, 347, 349, 353, 359, 367, 373, 379, 383, 389, 397, 401, 409, 419, 421, 431, 433,
@ -41,7 +39,7 @@ class TPrimality {
1009, 1013, 1019, 1021 };
/** All {@code BigInteger} prime numbers with bit length lesser than 8 bits. */
private static final TBigInteger BIprimes[] = new TBigInteger[primes.length];
private static final TBigInteger[] BIprimes = new TBigInteger[primes.length];
/**
* It encodes how many iterations of Miller-Rabin test are need to get an
@ -62,7 +60,8 @@ class TPrimality {
private static final int[][] offsetPrimes = { null, null, { 0, 2 }, { 2, 2 }, { 4, 2 }, { 6, 5 }, { 11, 7 },
{ 18, 13 }, { 31, 23 }, { 54, 43 }, { 97, 75 } };
static {// To initialize the dual table of BigInteger primes
static {
// To initialize the dual table of BigInteger primes
for (int i = 0; i < primes.length; i++) {
BIprimes[i] = TBigInteger.valueOf(primes[i]);
}
@ -79,11 +78,12 @@ class TPrimality {
*/
static TBigInteger nextProbablePrime(TBigInteger n) {
// PRE: n >= 0
int i, j;
int i;
int j;
int certainty;
int gapSize = 1024; // for searching of the next probable prime number
int modules[] = new int[primes.length];
boolean isDivisible[] = new boolean[gapSize];
int[] modules = new int[primes.length];
boolean[] isDivisible = new boolean[gapSize];
TBigInteger startPoint;
TBigInteger probPrime;
// If n < "last prime of table" searches next prime in the table
@ -153,7 +153,7 @@ class TPrimality {
// PRE: bitLength >= 2;
// For small numbers get a random prime from the prime table
if (bitLength <= 10) {
int rp[] = offsetPrimes[bitLength];
int[] rp = offsetPrimes[bitLength];
return BIprimes[rp[0] + rnd.nextInt(rp[1])];
}
int shiftCount = (-bitLength) & 31;
@ -161,7 +161,8 @@ class TPrimality {
TBigInteger n = new TBigInteger(1, last, new int[last]);
last--;
do {// To fill the array with random integers
do {
// To fill the array with random integers
for (int i = 0; i < n.numberLength; i++) {
n.digits[i] = rnd.nextInt();
}
@ -190,8 +191,8 @@ class TPrimality {
return false;
}
// To check if 'n' exists in the table (it fit in 10 bits)
if ((n.numberLength == 1) && ((n.digits[0] & 0XFFFFFC00) == 0)) {
return (Arrays.binarySearch(primes, n.digits[0]) >= 0);
if (n.numberLength == 1 && (n.digits[0] & 0XFFFFFC00) == 0) {
return Arrays.binarySearch(primes, n.digits[0]) >= 0;
}
// To check if 'n' is divisible by some prime of the table
for (int i = 1; i < primes.length; i++) {
@ -227,19 +228,20 @@ class TPrimality {
// PRE: n >= 0, t >= 0
TBigInteger x; // x := UNIFORM{2...n-1}
TBigInteger y; // y := x^(q * 2^j) mod n
TBigInteger n_minus_1 = n.subtract(TBigInteger.ONE); // n-1
int bitLength = n_minus_1.bitLength(); // ~ log2(n-1)
TBigInteger nMinus1 = n.subtract(TBigInteger.ONE); // n-1
int bitLength = nMinus1.bitLength(); // ~ log2(n-1)
// (q,k) such that: n-1 = q * 2^k and q is odd
int k = n_minus_1.getLowestSetBit();
TBigInteger q = n_minus_1.shiftRight(k);
int k = nMinus1.getLowestSetBit();
TBigInteger q = nMinus1.shiftRight(k);
Random rnd = new Random();
for (int i = 0; i < t; i++) {
// To generate a witness 'x', first it use the primes of table
if (i < primes.length) {
x = BIprimes[i];
} else {/*
* It generates random witness only if it's necesssary. Note
} else {
/*
* It generates random witness only if it's necessary. Note
* that all methods would call Miller-Rabin with t <= 50 so
* this part is only to do more robust the algorithm
*/
@ -248,11 +250,11 @@ class TPrimality {
} while ((x.compareTo(n) >= TBigInteger.EQUALS) || (x.sign == 0) || x.isOne());
}
y = x.modPow(q, n);
if (y.isOne() || y.equals(n_minus_1)) {
if (y.isOne() || y.equals(nMinus1)) {
continue;
}
for (int j = 1; j < k; j++) {
if (y.equals(n_minus_1)) {
if (y.equals(nMinus1)) {
continue;
}
y = y.multiply(y).mod(n);
@ -260,7 +262,7 @@ class TPrimality {
return false;
}
}
if (!y.equals(n_minus_1)) {
if (!y.equals(nMinus1)) {
return false;
}
}

View File

@ -1,10 +1,9 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You 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
* Copyright 2015 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
*
@ -14,7 +13,6 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.teavm.classlib.java.math;
/**

View File

@ -1,10 +1,9 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You 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
* Copyright 2015 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
*
@ -14,7 +13,6 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.teavm.classlib.java.net;
import org.teavm.classlib.java.io.TSerializable;
@ -42,7 +40,7 @@ public final class TURI implements TComparable<TURI>, TSerializable {
private transient TString fragment;
private transient boolean opaque;
private transient boolean absolute;
private transient boolean serverAuthority = false;
private transient boolean serverAuthority;
private transient int hash = -1;
private TURI() {
@ -124,8 +122,8 @@ public final class TURI implements TComparable<TURI>, TSerializable {
* if the temporary created string doesn't fit to the
* specification RFC2396 or could not be parsed correctly.
*/
public TURI(TString scheme, TString userinfo, TString host, int port, TString path, TString query, TString fragment)
throws TURISyntaxException {
public TURI(TString scheme, TString userinfo, TString host, int port, TString path, TString query,
TString fragment) throws TURISyntaxException {
if (scheme == null && userinfo == null && host == null && path == null && query == null && fragment == null) {
this.path = TString.wrap("");
@ -273,7 +271,10 @@ public final class TURI implements TComparable<TURI>, TSerializable {
TString temp = uri;
// assign uri string to the input value per spec
string = uri;
int index, index1, index2, index3;
int index;
int index1;
int index2;
int index3;
// parse into Fragment, Scheme, and SchemeSpecificPart
// then parse SchemeSpecificPart if necessary
@ -287,7 +288,8 @@ public final class TURI implements TComparable<TURI>, TSerializable {
}
// Scheme and SchemeSpecificPart
index = index1 = temp.indexOf(':');
index = temp.indexOf(':');
index1 = index;
index2 = temp.indexOf('/');
index3 = temp.indexOf('?');
@ -444,8 +446,11 @@ public final class TURI implements TComparable<TURI>, TSerializable {
return;
}
TString temp, tempUserinfo = null, tempHost = null;
int index, hostindex = 0;
TString temp;
TString tempUserinfo = null;
TString tempHost = null;
int index;
int hostindex = 0;
int tempPort = -1;
temp = authority;
@ -952,7 +957,8 @@ public final class TURI implements TComparable<TURI>, TSerializable {
return s;
}
int index = 0, previndex = 0;
int index = 0;
int previndex = 0;
while ((index = s.indexOf('%', previndex)) != -1) {
result.append(s.substring(previndex, index + 1));
result.append(s.substring(index + 1, index + 3).toLowerCase());
@ -972,9 +978,17 @@ public final class TURI implements TComparable<TURI>, TSerializable {
return first.equals(second);
}
int index = 0, previndex = 0;
while ((index = first.indexOf('%', previndex)) != -1
&& second.indexOf('%', previndex) == index) {
int index = 0;
int previndex = 0;
while (true) {
index = first.indexOf('%', previndex);
if (index == -1) {
break;
}
if (second.indexOf('%', previndex) != index) {
break;
}
boolean match = first.substring(previndex, index).equals(second.substring(previndex, index));
if (!match) {
return false;

View File

@ -1,10 +1,9 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You 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
* Copyright 2015 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
*
@ -14,7 +13,6 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.teavm.classlib.java.net;
import org.teavm.classlib.java.io.TByteArrayOutputStream;
@ -32,6 +30,8 @@ import org.teavm.classlib.java.lang.TStringBuilder;
class TURIEncoderDecoder {
static final TString digits = TString.wrap("0123456789ABCDEF");
private TURIEncoderDecoder() {
}
/**
* Validate a string by checking if it contains any characters other than:

View File

@ -1,10 +1,9 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You 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
* Copyright 2015 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
*
@ -14,7 +13,6 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.teavm.classlib.java.net;
import org.teavm.classlib.java.lang.TException;

View File

@ -1,3 +1,18 @@
/*
* Copyright 2015 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.nio;
/**
@ -25,8 +40,8 @@ public abstract class TBuffer {
public final TBuffer position(int newPosition) {
if (newPosition < 0 || newPosition > limit) {
throw new IllegalArgumentException("New position " + newPosition + " is outside of range [0;" +
limit + "]");
throw new IllegalArgumentException("New position " + newPosition + " is outside of range [0;"
+ limit + "]");
}
position = newPosition;
if (newPosition < mark) {
@ -41,8 +56,8 @@ public abstract class TBuffer {
public final TBuffer limit(int newLimit) {
if (newLimit < 0 || newLimit > capacity) {
throw new IllegalArgumentException("New limit " + newLimit + " is outside of range [0;" +
capacity + "]");
throw new IllegalArgumentException("New limit " + newLimit + " is outside of range [0;"
+ capacity + "]");
}
if (mark > newLimit) {
mark = -1;

View File

@ -1,3 +1,18 @@
/*
* Copyright 2015 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.nio;
import org.teavm.classlib.java.lang.TRuntimeException;

View File

@ -1,3 +1,18 @@
/*
* Copyright 2015 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.nio;
/**

View File

@ -1,3 +1,18 @@
/*
* Copyright 2015 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.nio;
import org.teavm.classlib.java.lang.TComparable;
@ -60,8 +75,8 @@ public abstract class TByteBuffer extends TBuffer implements TComparable<TByteBu
throw new IndexOutOfBoundsException("Offset " + offset + " is outside of range [0;" + dst.length + ")");
}
if (offset + length > dst.length) {
throw new IndexOutOfBoundsException("The last byte in dst " + (offset + length) + " is outside " +
"of array of size " + dst.length);
throw new IndexOutOfBoundsException("The last byte in dst " + (offset + length) + " is outside "
+ "of array of size " + dst.length);
}
if (remaining() < length) {
throw new TBufferUnderflowException();
@ -99,8 +114,8 @@ public abstract class TByteBuffer extends TBuffer implements TComparable<TByteBu
throw new IndexOutOfBoundsException("Offset " + offset + " is outside of range [0;" + src.length + ")");
}
if (offset + length > src.length) {
throw new IndexOutOfBoundsException("The last byte in src " + (offset + length) + " is outside " +
"of array of size " + src.length);
throw new IndexOutOfBoundsException("The last byte in src " + (offset + length) + " is outside "
+ "of array of size " + src.length);
}
if (length < 0) {
throw new IndexOutOfBoundsException("Length " + length + " must be non-negative");
@ -139,8 +154,8 @@ public abstract class TByteBuffer extends TBuffer implements TComparable<TByteBu
@Override
public String toString() {
return "[ByteBuffer position=" + position + ", limit=" + limit + ", capacity=" + capacity + ", mark " +
(mark >= 0 ? " at " + mark : " is not set") + "]";
return "[ByteBuffer position=" + position + ", limit=" + limit + ", capacity=" + capacity + ", mark "
+ (mark >= 0 ? " at " + mark : " is not set") + "]";
}
@Override

View File

@ -1,3 +1,18 @@
/*
* Copyright 2015 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.nio;
/**

View File

@ -97,8 +97,8 @@ public abstract class TCharBuffer extends TBuffer implements Comparable<TCharBuf
throw new IndexOutOfBoundsException("Offset " + offset + " is outside of range [0;" + dst.length + ")");
}
if (offset + length > dst.length) {
throw new IndexOutOfBoundsException("The last char in dst " + (offset + length) + " is outside " +
"of array of size " + dst.length);
throw new IndexOutOfBoundsException("The last char in dst " + (offset + length) + " is outside "
+ "of array of size " + dst.length);
}
if (remaining() < length) {
throw new TBufferUnderflowException();
@ -146,8 +146,8 @@ public abstract class TCharBuffer extends TBuffer implements Comparable<TCharBuf
throw new IndexOutOfBoundsException("Offset " + offset + " is outside of range [0;" + src.length + ")");
}
if (offset + length > src.length) {
throw new IndexOutOfBoundsException("The last char in src " + (offset + length) + " is outside " +
"of array of size " + src.length);
throw new IndexOutOfBoundsException("The last char in src " + (offset + length) + " is outside "
+ "of array of size " + src.length);
}
if (length < 0) {
throw new IndexOutOfBoundsException("Length " + length + " must be non-negative");
@ -176,8 +176,8 @@ public abstract class TCharBuffer extends TBuffer implements Comparable<TCharBuf
throw new IndexOutOfBoundsException("Start " + start + " is outside of range [0;" + src.length() + ")");
}
if (end > src.length()) {
throw new IndexOutOfBoundsException("The last char in src " + end + " is outside " +
"of string of size " + src.length());
throw new IndexOutOfBoundsException("The last char in src " + end + " is outside "
+ "of string of size " + src.length());
}
if (start > end) {
throw new IndexOutOfBoundsException("Start " + start + " must be before end " + end);

View File

@ -27,8 +27,8 @@ class TCharBufferOverByteBufferBigEndian extends TCharBufferOverByteBuffer {
@Override
char getChar(int index) {
int value = ((byteByffer.array[start + index * 2] & 0xFF) << 8) |
(byteByffer.array[start + index * 2 + 1] & 0xFF);
int value = ((byteByffer.array[start + index * 2] & 0xFF) << 8)
| (byteByffer.array[start + index * 2 + 1] & 0xFF);
return (char) value;
}

View File

@ -27,8 +27,8 @@ class TCharBufferOverByteBufferLittleEndian extends TCharBufferOverByteBuffer {
@Override
char getChar(int index) {
int value = ((byteByffer.array[start + index * 2 + 1] & 0xFF) << 8) |
(byteByffer.array[start + index * 2] & 0xFF);
int value = ((byteByffer.array[start + index * 2 + 1] & 0xFF) << 8)
| (byteByffer.array[start + index * 2] & 0xFF);
return (char) value;
}

View File

@ -64,8 +64,8 @@ public abstract class TDoubleBuffer extends TBuffer implements Comparable<TDoubl
throw new IndexOutOfBoundsException("Offset " + offset + " is outside of range [0;" + dst.length + ")");
}
if (offset + length > dst.length) {
throw new IndexOutOfBoundsException("The last double in dst " + (offset + length) + " is outside " +
"of array of size " + dst.length);
throw new IndexOutOfBoundsException("The last double in dst " + (offset + length) + " is outside "
+ "of array of size " + dst.length);
}
if (remaining() < length) {
throw new TBufferUnderflowException();
@ -113,8 +113,8 @@ public abstract class TDoubleBuffer extends TBuffer implements Comparable<TDoubl
throw new IndexOutOfBoundsException("Offset " + offset + " is outside of range [0;" + src.length + ")");
}
if (offset + length > src.length) {
throw new IndexOutOfBoundsException("The last double in src " + (offset + length) + " is outside " +
"of array of size " + src.length);
throw new IndexOutOfBoundsException("The last double in src " + (offset + length) + " is outside "
+ "of array of size " + src.length);
}
if (length < 0) {
throw new IndexOutOfBoundsException("Length " + length + " must be non-negative");
@ -159,8 +159,8 @@ public abstract class TDoubleBuffer extends TBuffer implements Comparable<TDoubl
@Override
public String toString() {
return "[DoubleBuffer position=" + position + ", limit=" + limit + ", capacity=" + capacity + ", mark " +
(mark >= 0 ? " at " + mark : " is not set") + "]";
return "[DoubleBuffer position=" + position + ", limit=" + limit + ", capacity=" + capacity + ", mark "
+ (mark >= 0 ? " at " + mark : " is not set") + "]";
}
@Override

View File

@ -45,23 +45,23 @@ class TDoubleBufferOverByteBuffer extends TDoubleBufferImpl {
double getElement(int index) {
long value;
if (byteOrder == TByteOrder.BIG_ENDIAN) {
value = (((long)byteByffer.array[start + index * 8] & 0xFF) << 56) |
(((long)byteByffer.array[start + index * 8 + 1] & 0xFF) << 48) |
(((long)byteByffer.array[start + index * 8 + 2] & 0xFF) << 40) |
(((long)byteByffer.array[start + index * 8 + 3] & 0xFF) << 32) |
(((long)byteByffer.array[start + index * 8 + 4] & 0xFF) << 24) |
(((long)byteByffer.array[start + index * 8 + 5] & 0xFF) << 16) |
(((long)byteByffer.array[start + index * 8 + 6] & 0xFF) << 8) |
(byteByffer.array[start + index * 8 + 7] & 0xFF);
value = (((long) byteByffer.array[start + index * 8] & 0xFF) << 56)
| (((long) byteByffer.array[start + index * 8 + 1] & 0xFF) << 48)
| (((long) byteByffer.array[start + index * 8 + 2] & 0xFF) << 40)
| (((long) byteByffer.array[start + index * 8 + 3] & 0xFF) << 32)
| (((long) byteByffer.array[start + index * 8 + 4] & 0xFF) << 24)
| (((long) byteByffer.array[start + index * 8 + 5] & 0xFF) << 16)
| (((long) byteByffer.array[start + index * 8 + 6] & 0xFF) << 8)
| (byteByffer.array[start + index * 8 + 7] & 0xFF);
} else {
value = (byteByffer.array[start + index * 8] & 0xFF) |
(((long)byteByffer.array[start + index * 8 + 1] & 0xFF) << 8) |
(((long)byteByffer.array[start + index * 8 + 2] & 0xFF) << 16) |
(((long)byteByffer.array[start + index * 8 + 3] & 0xFF) << 24) |
(((long)byteByffer.array[start + index * 8 + 4] & 0xFF) << 32) |
(((long)byteByffer.array[start + index * 8 + 5] & 0xFF) << 40) |
(((long)byteByffer.array[start + index * 8 + 6] & 0xFF) << 48) |
(((long)byteByffer.array[start + index * 8 + 7] & 0xFF) << 56);
value = (byteByffer.array[start + index * 8] & 0xFF)
| (((long) byteByffer.array[start + index * 8 + 1] & 0xFF) << 8)
| (((long) byteByffer.array[start + index * 8 + 2] & 0xFF) << 16)
| (((long) byteByffer.array[start + index * 8 + 3] & 0xFF) << 24)
| (((long) byteByffer.array[start + index * 8 + 4] & 0xFF) << 32)
| (((long) byteByffer.array[start + index * 8 + 5] & 0xFF) << 40)
| (((long) byteByffer.array[start + index * 8 + 6] & 0xFF) << 48)
| (((long) byteByffer.array[start + index * 8 + 7] & 0xFF) << 56);
}
return Double.longBitsToDouble(value);
}

View File

@ -64,8 +64,8 @@ public abstract class TFloatBuffer extends TBuffer implements Comparable<TFloatB
throw new IndexOutOfBoundsException("Offset " + offset + " is outside of range [0;" + dst.length + ")");
}
if (offset + length > dst.length) {
throw new IndexOutOfBoundsException("The last float in dst " + (offset + length) + " is outside " +
"of array of size " + dst.length);
throw new IndexOutOfBoundsException("The last float in dst " + (offset + length) + " is outside "
+ "of array of size " + dst.length);
}
if (remaining() < length) {
throw new TBufferUnderflowException();
@ -113,8 +113,8 @@ public abstract class TFloatBuffer extends TBuffer implements Comparable<TFloatB
throw new IndexOutOfBoundsException("Offset " + offset + " is outside of range [0;" + src.length + ")");
}
if (offset + length > src.length) {
throw new IndexOutOfBoundsException("The last float in src " + (offset + length) + " is outside " +
"of array of size " + src.length);
throw new IndexOutOfBoundsException("The last float in src " + (offset + length) + " is outside "
+ "of array of size " + src.length);
}
if (length < 0) {
throw new IndexOutOfBoundsException("Length " + length + " must be non-negative");
@ -159,8 +159,8 @@ public abstract class TFloatBuffer extends TBuffer implements Comparable<TFloatB
@Override
public String toString() {
return "[FloatBuffer position=" + position + ", limit=" + limit + ", capacity=" + capacity + ", mark " +
(mark >= 0 ? " at " + mark : " is not set") + "]";
return "[FloatBuffer position=" + position + ", limit=" + limit + ", capacity=" + capacity + ", mark "
+ (mark >= 0 ? " at " + mark : " is not set") + "]";
}
@Override

View File

@ -33,10 +33,10 @@ class TFloatBufferOverByteBufferBigEndian extends TFloatBufferOverByteBuffer {
@Override
float getElement(int index) {
int value = (byteByffer.array[start + index * 4] & 0xFF) |
((byteByffer.array[start + index * 4 + 1] & 0xFF) << 8) |
((byteByffer.array[start + index * 4 + 2] & 0xFF) << 16) |
((byteByffer.array[start + index * 4 + 3] & 0xFF) << 24);
int value = (byteByffer.array[start + index * 4] & 0xFF)
| ((byteByffer.array[start + index * 4 + 1] & 0xFF) << 8)
| ((byteByffer.array[start + index * 4 + 2] & 0xFF) << 16)
| ((byteByffer.array[start + index * 4 + 3] & 0xFF) << 24);
return Float.intBitsToFloat(value);
}

View File

@ -33,10 +33,10 @@ class TFloatBufferOverByteBufferLittleEndian extends TFloatBufferOverByteBuffer
@Override
float getElement(int index) {
int value = ((byteByffer.array[start + index * 4] & 0xFF) << 24) |
((byteByffer.array[start + index * 4 + 1] & 0xFF) << 16) |
((byteByffer.array[start + index * 4 + 2] & 0xFF) << 8) |
(byteByffer.array[start + index * 4 + 3] & 0xFF);
int value = ((byteByffer.array[start + index * 4] & 0xFF) << 24)
| ((byteByffer.array[start + index * 4 + 1] & 0xFF) << 16)
| ((byteByffer.array[start + index * 4 + 2] & 0xFF) << 8)
| (byteByffer.array[start + index * 4 + 3] & 0xFF);
return Float.intBitsToFloat(value);
}

View File

@ -64,8 +64,8 @@ public abstract class TIntBuffer extends TBuffer implements Comparable<TIntBuffe
throw new IndexOutOfBoundsException("Offset " + offset + " is outside of range [0;" + dst.length + ")");
}
if (offset + length > dst.length) {
throw new IndexOutOfBoundsException("The last int in dst " + (offset + length) + " is outside " +
"of array of size " + dst.length);
throw new IndexOutOfBoundsException("The last int in dst " + (offset + length) + " is outside "
+ "of array of size " + dst.length);
}
if (remaining() < length) {
throw new TBufferUnderflowException();
@ -113,8 +113,8 @@ public abstract class TIntBuffer extends TBuffer implements Comparable<TIntBuffe
throw new IndexOutOfBoundsException("Offset " + offset + " is outside of range [0;" + src.length + ")");
}
if (offset + length > src.length) {
throw new IndexOutOfBoundsException("The last int in src " + (offset + length) + " is outside " +
"of array of size " + src.length);
throw new IndexOutOfBoundsException("The last int in src " + (offset + length) + " is outside "
+ "of array of size " + src.length);
}
if (length < 0) {
throw new IndexOutOfBoundsException("Length " + length + " must be non-negative");
@ -159,8 +159,8 @@ public abstract class TIntBuffer extends TBuffer implements Comparable<TIntBuffe
@Override
public String toString() {
return "[IntBuffer position=" + position + ", limit=" + limit + ", capacity=" + capacity + ", mark " +
(mark >= 0 ? " at " + mark : " is not set") + "]";
return "[IntBuffer position=" + position + ", limit=" + limit + ", capacity=" + capacity + ", mark "
+ (mark >= 0 ? " at " + mark : " is not set") + "]";
}
@Override

View File

@ -33,10 +33,10 @@ class TIntBufferOverByteBufferBigEndian extends TIntBufferOverByteBuffer {
@Override
int getElement(int index) {
return ((byteByffer.array[start + index * 4] & 0xFF) << 24) |
((byteByffer.array[start + index * 4 + 1] & 0xFF) << 16) |
((byteByffer.array[start + index * 4 + 2] & 0xFF) << 8) |
(byteByffer.array[start + index * 4 + 3] & 0xFF);
return ((byteByffer.array[start + index * 4] & 0xFF) << 24)
| ((byteByffer.array[start + index * 4 + 1] & 0xFF) << 16)
| ((byteByffer.array[start + index * 4 + 2] & 0xFF) << 8)
| (byteByffer.array[start + index * 4 + 3] & 0xFF);
}
@Override

View File

@ -33,10 +33,10 @@ class TIntBufferOverByteBufferLittleEndian extends TIntBufferOverByteBuffer {
@Override
int getElement(int index) {
return (byteByffer.array[start + index * 4] & 0xFF) |
((byteByffer.array[start + index * 4 + 1] & 0xFF) << 8) |
((byteByffer.array[start + index * 4 + 2] & 0xFF) << 16) |
((byteByffer.array[start + index * 4 + 3] & 0xFF) << 24);
return (byteByffer.array[start + index * 4] & 0xFF)
| ((byteByffer.array[start + index * 4 + 1] & 0xFF) << 8)
| ((byteByffer.array[start + index * 4 + 2] & 0xFF) << 16)
| ((byteByffer.array[start + index * 4 + 3] & 0xFF) << 24);
}
@Override

View File

@ -1,3 +1,18 @@
/*
* Copyright 2015 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.nio;
import org.teavm.classlib.java.lang.TIllegalStateException;

View File

@ -64,8 +64,8 @@ public abstract class TLongBuffer extends TBuffer implements Comparable<TLongBuf
throw new IndexOutOfBoundsException("Offset " + offset + " is outside of range [0;" + dst.length + ")");
}
if (offset + length > dst.length) {
throw new IndexOutOfBoundsException("The last long in dst " + (offset + length) + " is outside " +
"of array of size " + dst.length);
throw new IndexOutOfBoundsException("The last long in dst " + (offset + length) + " is outside "
+ "of array of size " + dst.length);
}
if (remaining() < length) {
throw new TBufferUnderflowException();
@ -113,8 +113,8 @@ public abstract class TLongBuffer extends TBuffer implements Comparable<TLongBuf
throw new IndexOutOfBoundsException("Offset " + offset + " is outside of range [0;" + src.length + ")");
}
if (offset + length > src.length) {
throw new IndexOutOfBoundsException("The last long in src " + (offset + length) + " is outside " +
"of array of size " + src.length);
throw new IndexOutOfBoundsException("The last long in src " + (offset + length) + " is outside "
+ "of array of size " + src.length);
}
if (length < 0) {
throw new IndexOutOfBoundsException("Length " + length + " must be non-negative");
@ -159,8 +159,8 @@ public abstract class TLongBuffer extends TBuffer implements Comparable<TLongBuf
@Override
public String toString() {
return "[LongBuffer position=" + position + ", limit=" + limit + ", capacity=" + capacity + ", mark " +
(mark >= 0 ? " at " + mark : " is not set") + "]";
return "[LongBuffer position=" + position + ", limit=" + limit + ", capacity=" + capacity + ", mark "
+ (mark >= 0 ? " at " + mark : " is not set") + "]";
}
@Override

View File

@ -33,14 +33,14 @@ class TLongBufferOverByteBufferBigEndian extends TLongBufferOverByteBuffer {
@Override
long getElement(int index) {
return (((long)byteByffer.array[start + index * 8] & 0xFF) << 56) |
(((long)byteByffer.array[start + index * 8 + 1] & 0xFF) << 48) |
(((long)byteByffer.array[start + index * 8 + 2] & 0xFF) << 40) |
(((long)byteByffer.array[start + index * 8 + 3] & 0xFF) << 32) |
(((long)byteByffer.array[start + index * 8 + 4] & 0xFF) << 24) |
(((long)byteByffer.array[start + index * 8 + 5] & 0xFF) << 16) |
(((long)byteByffer.array[start + index * 8 + 6] & 0xFF) << 8) |
(byteByffer.array[start + index * 8 + 7] & 0xFF);
return (((long) byteByffer.array[start + index * 8] & 0xFF) << 56)
| (((long) byteByffer.array[start + index * 8 + 1] & 0xFF) << 48)
| (((long) byteByffer.array[start + index * 8 + 2] & 0xFF) << 40)
| (((long) byteByffer.array[start + index * 8 + 3] & 0xFF) << 32)
| (((long) byteByffer.array[start + index * 8 + 4] & 0xFF) << 24)
| (((long) byteByffer.array[start + index * 8 + 5] & 0xFF) << 16)
| (((long) byteByffer.array[start + index * 8 + 6] & 0xFF) << 8)
| (byteByffer.array[start + index * 8 + 7] & 0xFF);
}
@Override

View File

@ -33,14 +33,14 @@ class TLongBufferOverByteBufferLittleEndian extends TLongBufferOverByteBuffer {
@Override
long getElement(int index) {
return (byteByffer.array[start + index * 8] & 0xFF) |
(((long)byteByffer.array[start + index * 8 + 1] & 0xFF) << 8) |
(((long)byteByffer.array[start + index * 8 + 2] & 0xFF) << 16) |
(((long)byteByffer.array[start + index * 8 + 3] & 0xFF) << 24) |
(((long)byteByffer.array[start + index * 8 + 4] & 0xFF) << 32) |
(((long)byteByffer.array[start + index * 8 + 5] & 0xFF) << 40) |
(((long)byteByffer.array[start + index * 8 + 6] & 0xFF) << 48) |
(((long)byteByffer.array[start + index * 8 + 7] & 0xFF) << 56);
return (byteByffer.array[start + index * 8] & 0xFF)
| (((long) byteByffer.array[start + index * 8 + 1] & 0xFF) << 8)
| (((long) byteByffer.array[start + index * 8 + 2] & 0xFF) << 16)
| (((long) byteByffer.array[start + index * 8 + 3] & 0xFF) << 24)
| (((long) byteByffer.array[start + index * 8 + 4] & 0xFF) << 32)
| (((long) byteByffer.array[start + index * 8 + 5] & 0xFF) << 40)
| (((long) byteByffer.array[start + index * 8 + 6] & 0xFF) << 48)
| (((long) byteByffer.array[start + index * 8 + 7] & 0xFF) << 56);
}
@Override

View File

@ -1,3 +1,18 @@
/*
* Copyright 2015 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.nio;
import org.teavm.classlib.java.lang.TUnsupportedOperationException;

View File

@ -64,8 +64,8 @@ public abstract class TShortBuffer extends TBuffer implements Comparable<TShortB
throw new IndexOutOfBoundsException("Offset " + offset + " is outside of range [0;" + dst.length + ")");
}
if (offset + length > dst.length) {
throw new IndexOutOfBoundsException("The last short in dst " + (offset + length) + " is outside " +
"of array of size " + dst.length);
throw new IndexOutOfBoundsException("The last short in dst " + (offset + length) + " is outside "
+ "of array of size " + dst.length);
}
if (remaining() < length) {
throw new TBufferUnderflowException();
@ -113,8 +113,8 @@ public abstract class TShortBuffer extends TBuffer implements Comparable<TShortB
throw new IndexOutOfBoundsException("Offset " + offset + " is outside of range [0;" + src.length + ")");
}
if (offset + length > src.length) {
throw new IndexOutOfBoundsException("The last short in src " + (offset + length) + " is outside " +
"of array of size " + src.length);
throw new IndexOutOfBoundsException("The last short in src " + (offset + length) + " is outside "
+ "of array of size " + src.length);
}
if (length < 0) {
throw new IndexOutOfBoundsException("Length " + length + " must be non-negative");
@ -159,8 +159,8 @@ public abstract class TShortBuffer extends TBuffer implements Comparable<TShortB
@Override
public String toString() {
return "[ShortBuffer position=" + position + ", limit=" + limit + ", capacity=" + capacity + ", mark " +
(mark >= 0 ? " at " + mark : " is not set") + "]";
return "[ShortBuffer position=" + position + ", limit=" + limit + ", capacity=" + capacity + ", mark "
+ (mark >= 0 ? " at " + mark : " is not set") + "]";
}
@Override

View File

@ -33,8 +33,8 @@ class TShortBufferOverByteBufferBigEndian extends TShortBufferOverByteBuffer {
@Override
short getElement(int index) {
int value = ((byteByffer.array[start + index * 2] & 0xFF) << 8) |
(byteByffer.array[start + index * 2 + 1] & 0xFF);
int value = ((byteByffer.array[start + index * 2] & 0xFF) << 8)
| (byteByffer.array[start + index * 2 + 1] & 0xFF);
return (short) value;
}

View File

@ -33,8 +33,8 @@ class TShortBufferOverByteBufferLittleEndian extends TShortBufferOverByteBuffer
@Override
short getElement(int index) {
int value = (byteByffer.array[start + index * 2] & 0xFF) |
((byteByffer.array[start + index * 2 + 1] & 0xFF) << 8);
int value = (byteByffer.array[start + index * 2] & 0xFF)
| ((byteByffer.array[start + index * 2 + 1] & 0xFF) << 8);
return (short) value;
}

View File

@ -38,12 +38,12 @@ public abstract class TCharsetDecoder {
protected TCharsetDecoder(TCharset cs, float averageCharsPerByte, float maxCharsPerByte) {
if (averageCharsPerByte <= 0) {
throw new IllegalArgumentException("averageCharsPerByte must be positive. Actual value is " +
averageCharsPerByte);
throw new IllegalArgumentException("averageCharsPerByte must be positive. Actual value is "
+ averageCharsPerByte);
}
if (maxCharsPerByte <= 0) {
throw new IllegalArgumentException("maxCharsPerByte must be positive. Actual value is " +
maxCharsPerByte);
throw new IllegalArgumentException("maxCharsPerByte must be positive. Actual value is "
+ maxCharsPerByte);
}
this.charset = cs;
this.averageCharsPerByte = averageCharsPerByte;

View File

@ -1,10 +1,9 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You 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
* Copyright 2015 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
*
@ -14,7 +13,6 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.teavm.classlib.java.text;
public class TAnnotation {

View File

@ -1,10 +1,9 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You 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
* Copyright 2015 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
*
@ -14,7 +13,6 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.teavm.classlib.java.text;
import org.teavm.classlib.java.io.TSerializable;
@ -64,7 +62,7 @@ public interface TAttributedCharacterIterator extends TCharacterIterator {
*
* @return a set of attribute keys; may be empty.
*/
public TSet<Attribute> getAllAttributeKeys();
TSet<Attribute> getAllAttributeKeys();
/**
* Returns the value stored in the attribute for the current character. If
@ -74,7 +72,7 @@ public interface TAttributedCharacterIterator extends TCharacterIterator {
* @return the value of the requested attribute for the current character or
* {@code null} if it was not defined.
*/
public Object getAttribute(Attribute attribute);
Object getAttribute(Attribute attribute);
/**
* Returns a map of all attributes of the current character. If no
@ -84,7 +82,7 @@ public interface TAttributedCharacterIterator extends TCharacterIterator {
* @return a map of all attributes for the current character or an empty
* map.
*/
public TMap<Attribute, Object> getAttributes();
TMap<Attribute, Object> getAttributes();
/**
* Returns the index of the last character in the run having the same
@ -92,7 +90,7 @@ public interface TAttributedCharacterIterator extends TCharacterIterator {
*
* @return the index of the last character of the current run.
*/
public int getRunLimit();
int getRunLimit();
/**
* Returns the index of the last character in the run that has the same
@ -102,7 +100,7 @@ public interface TAttributedCharacterIterator extends TCharacterIterator {
* the attribute which the run is based on.
* @return the index of the last character of the current run.
*/
public int getRunLimit(Attribute attribute);
int getRunLimit(Attribute attribute);
/**
* Returns the index of the last character in the run that has the same
@ -112,7 +110,7 @@ public interface TAttributedCharacterIterator extends TCharacterIterator {
* the set of attributes which the run is based on.
* @return the index of the last character of the current run.
*/
public int getRunLimit(TSet<? extends Attribute> attributes);
int getRunLimit(TSet<? extends Attribute> attributes);
/**
* Returns the index of the first character in the run that has the same
@ -120,7 +118,7 @@ public interface TAttributedCharacterIterator extends TCharacterIterator {
*
* @return the index of the last character of the current run.
*/
public int getRunStart();
int getRunStart();
/**
* Returns the index of the first character in the run that has the same
@ -130,7 +128,7 @@ public interface TAttributedCharacterIterator extends TCharacterIterator {
* the attribute which the run is based on.
* @return the index of the last character of the current run.
*/
public int getRunStart(Attribute attribute);
int getRunStart(Attribute attribute);
/**
* Returns the index of the first character in the run that has the same
@ -140,5 +138,5 @@ public interface TAttributedCharacterIterator extends TCharacterIterator {
* the set of attributes which the run is based on.
* @return the index of the last character of the current run.
*/
public int getRunStart(TSet<? extends Attribute> attributes);
int getRunStart(TSet<? extends Attribute> attributes);
}

View File

@ -1,20 +1,18 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You 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
* Copyright 2015 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.
* 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.text;
import org.teavm.classlib.java.text.TAttributedCharacterIterator.Attribute;
@ -42,7 +40,9 @@ public class TAttributedString {
static class AttributedIterator implements TAttributedCharacterIterator {
private int begin, end, offset;
private int begin;
private int end;
private int offset;
private TAttributedString attrString;
@ -393,8 +393,8 @@ public class TAttributedString {
Object value = iterator.getAttribute(attribute);
int runStart = iterator.getRunStart(attribute);
int limit = iterator.getRunLimit(attribute);
if ((value instanceof TAnnotation && runStart >= start && limit <= end) ||
(value != null && !(value instanceof TAnnotation))) {
if ((value instanceof TAnnotation && runStart >= start && limit <= end)
|| (value != null && !(value instanceof TAnnotation))) {
addAttribute(attribute, value, (runStart < start ? start : runStart) - start, (limit > end ? end
: limit) - start);
}
@ -513,7 +513,8 @@ public class TAttributedString {
it.previous();
break;
} else if (start < range.end || (start == range.end && value.equals(range.value))) {
Range r1 = null, r3;
Range r1 = null;
Range r3;
it.remove();
r1 = new Range(range.start, start, range.value);
r3 = new Range(end, range.end, range.value);
@ -575,7 +576,8 @@ public class TAttributedString {
* if {@code start < 0}, {@code end} is greater than the length
* of this string, or if {@code start >= end}.
*/
public void addAttributes(TMap<? extends TAttributedCharacterIterator.Attribute, ?> attributes, int start, int end) {
public void addAttributes(TMap<? extends TAttributedCharacterIterator.Attribute, ?> attributes,
int start, int end) {
TIterator<?> it = attributes.entrySet().iterator();
while (it.hasNext()) {
TMap.Entry<?, ?> entry = (TMap.Entry<?, ?>) it.next();

View File

@ -1,10 +1,9 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You 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
* Copyright 2015 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
*
@ -14,29 +13,28 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.teavm.classlib.java.text;
public interface TCharacterIterator extends Cloneable {
public static final char DONE = '\uffff';
char DONE = '\uffff';
public Object clone();
Object clone();
public char current();
char current();
public char first();
char first();
public int getBeginIndex();
int getBeginIndex();
public int getEndIndex();
int getEndIndex();
public int getIndex();
int getIndex();
public char last();
char last();
public char next();
char next();
public char previous();
char previous();
public char setIndex(int location);
char setIndex(int location);
}

View File

@ -1,10 +1,9 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You 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
* Copyright 2015 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
*
@ -14,7 +13,6 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.teavm.classlib.java.text;
import org.teavm.classlib.impl.unicode.CLDRHelper;
@ -67,9 +65,9 @@ public abstract class TDateFormat extends TFormat {
return false;
}
TDateFormat dateFormat = (TDateFormat) object;
return calendar.getFirstDayOfWeek() == dateFormat.calendar.getFirstDayOfWeek() &&
calendar.getMinimalDaysInFirstWeek() == dateFormat.calendar.getMinimalDaysInFirstWeek() &&
calendar.isLenient() == dateFormat.calendar.isLenient();
return calendar.getFirstDayOfWeek() == dateFormat.calendar.getFirstDayOfWeek()
&& calendar.getMinimalDaysInFirstWeek() == dateFormat.calendar.getMinimalDaysInFirstWeek()
&& calendar.isLenient() == dateFormat.calendar.isLenient();
}
@Override
@ -219,8 +217,8 @@ public abstract class TDateFormat extends TFormat {
@Override
public int hashCode() {
return calendar.getFirstDayOfWeek() + calendar.getMinimalDaysInFirstWeek() +
(calendar.isLenient() ? 1231 : 1237);
return calendar.getFirstDayOfWeek() + calendar.getMinimalDaysInFirstWeek()
+ (calendar.isLenient() ? 1231 : 1237);
}
public boolean isLenient() {

View File

@ -588,10 +588,9 @@ abstract class TDateFormatElement {
}
}
int sign = signChar == '-' ? -1 : 1;
int hours = 10 * Character.digit(text.charAt(index), 10) +
Character.digit(text.charAt(index + 1), 10);
int minutes = 10 * Character.digit(text.charAt(index + 2), 10) +
Character.digit(text.charAt(index + 3), 10);
int hours = 10 * Character.digit(text.charAt(index), 10) + Character.digit(text.charAt(index + 1), 10);
int minutes = 10 * Character.digit(text.charAt(index + 2), 10)
+ Character.digit(text.charAt(index + 3), 10);
date.setTimeZone(getStaticTimeZone(sign * hours, minutes));
return true;
}
@ -623,8 +622,8 @@ abstract class TDateFormatElement {
}
++index;
if (index + 2 > text.length() || !Character.isDigit(text.charAt(index)) ||
!Character.isDigit(text.charAt(index + 1))) {
if (index + 2 > text.length() || !Character.isDigit(text.charAt(index))
|| !Character.isDigit(text.charAt(index + 1))) {
position.setErrorIndex(index);
return;
}
@ -635,8 +634,8 @@ abstract class TDateFormatElement {
}
static TTimeZone getStaticTimeZone(int hours, int minutes) {
return TTimeZone.getTimeZone("GMT" + (hours > 0 ? '+' : '-') + Math.abs(hours) +
":" + (minutes / 10) + (minutes % 10));
return TTimeZone.getTimeZone("GMT" + (hours > 0 ? '+' : '-') + Math.abs(hours)
+ ":" + (minutes / 10) + (minutes % 10));
}
static class TrieNode {

View File

@ -1,10 +1,9 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You 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
* 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
*
@ -25,7 +24,12 @@ import org.teavm.classlib.java.util.TLocale;
public class TDateFormatSymbols implements TSerializable, TCloneable {
private TLocale locale;
private String localPatternChars;
String[] ampms, eras, months, shortMonths, shortWeekdays, weekdays;
String[] ampms;
String[] eras;
String[] months;
String[] shortMonths;
String[] shortWeekdays;
String[] weekdays;
String[][] zoneStrings;

View File

@ -38,7 +38,7 @@ public class TDecimalFormat extends TNumberFormat {
private static final double[] POW10_FRAC_ARRAY = { 1E1, 1E2, 1E4, 1E8, 1E16, 1E32, 1E64, 1E128, 1E256 };
private static final double[] POWM10_FRAC_ARRAY = { 1E-1, 1E-2, 1E-4, 1E-8, 1E-16, 1E-32, 1E-64, 1E-128, 1E-256 };
private static final int DOUBLE_MAX_EXPONENT = 308;
private static long MAX_LONG_DIV_10 = Long.MAX_VALUE / 10;
private static final long MAX_LONG_DIV_10 = Long.MAX_VALUE / 10;
TDecimalFormatSymbols symbols;
FormatField[] positivePrefix = {};
FormatField[] negativePrefix = { new TextField("-") };
@ -172,15 +172,15 @@ public class TDecimalFormat extends TNumberFormat {
if (!super.equals(obj)) {
return false;
}
return positivePrefix.equals(other.positivePrefix) &&
positiveSuffix.equals(other.positiveSuffix) &&
negativePrefix.equals(other.negativePrefix) &&
negativeSuffix.equals(other.negativeSuffix) &&
multiplier == other.multiplier &&
groupingSize == other.groupingSize &&
decimalSeparatorAlwaysShown == other.decimalSeparatorAlwaysShown &&
parseBigDecimal == other.parseBigDecimal &&
exponentDigits == other.exponentDigits;
return positivePrefix.equals(other.positivePrefix)
&& positiveSuffix.equals(other.positiveSuffix)
&& negativePrefix.equals(other.negativePrefix)
&& negativeSuffix.equals(other.negativeSuffix)
&& multiplier == other.multiplier
&& groupingSize == other.groupingSize
&& decimalSeparatorAlwaysShown == other.decimalSeparatorAlwaysShown
&& parseBigDecimal == other.parseBigDecimal
&& exponentDigits == other.exponentDigits;
}
@Override
@ -848,8 +848,8 @@ public class TDecimalFormat extends TNumberFormat {
fieldsToText(positiveSuffix, buffer);
}
} else {
fieldsToText(negativeSuffix != null ? negativeSuffix :
positiveSuffix != null ? positiveSuffix : new FormatField[0], buffer);
fieldsToText(negativeSuffix != null ? negativeSuffix
: positiveSuffix != null ? positiveSuffix : new FormatField[0], buffer);
}
}

View File

@ -81,8 +81,8 @@ class TDecimalFormatParser {
format.negativeSuffix = negativeSuffix != null ? negativeSuffix : positiveSuffix;
format.setGroupingSize(groupSize);
format.setGroupingUsed(groupSize > 0);
format.setMinimumIntegerDigits(!decimalSeparatorRequired ? minimumIntLength :
Math.max(1, minimumIntLength));
format.setMinimumIntegerDigits(!decimalSeparatorRequired ? minimumIntLength
: Math.max(1, minimumIntLength));
format.setMaximumIntegerDigits(intLength);
format.setMinimumFractionDigits(minimumFracLength);
format.setMaximumFractionDigits(fracLength);
@ -100,26 +100,26 @@ class TDecimalFormatParser {
case '#':
case '0':
if (suffix) {
throw new IllegalArgumentException("Prefix contains special character at " + index + " in " +
string);
throw new IllegalArgumentException("Prefix contains special character at " + index + " in "
+ string);
}
break loop;
case ';':
if (end) {
throw new IllegalArgumentException("Prefix contains special character at " + index + " in " +
string);
throw new IllegalArgumentException("Prefix contains special character at " + index + " in "
+ string);
}
break loop;
case '.':
case 'E':
throw new IllegalArgumentException("Prefix contains special character at " + index + " in " +
string);
throw new IllegalArgumentException("Prefix contains special character at " + index + " in "
+ string);
case '\'': {
++index;
int next = string.indexOf('\'', index);
if (next < 0) {
throw new IllegalArgumentException("Quote opened at " + index + " was not closed in " +
string);
throw new IllegalArgumentException("Quote opened at " + index + " was not closed in "
+ string);
}
if (next == index) {
sb.append('\'');
@ -199,8 +199,8 @@ class TDecimalFormatParser {
switch (string.charAt(index)) {
case '#':
if (!optionalDigits) {
throw new IllegalArgumentException("Unexpected '#' at non-optional digit part at " + index +
" in " + string);
throw new IllegalArgumentException("Unexpected '#' at non-optional digit part at " + index
+ " in " + string);
}
++length;
break;
@ -224,8 +224,8 @@ class TDecimalFormatParser {
++index;
}
if (length == 0) {
throw new IllegalArgumentException("Pattern does not specify integer digits at " + index +
" in " + string);
throw new IllegalArgumentException("Pattern does not specify integer digits at " + index
+ " in " + string);
}
if (lastGroup == index) {
throw new IllegalArgumentException("Group separator at the end of number at " + index + " in " + string);
@ -250,19 +250,19 @@ class TDecimalFormatParser {
optionalDigits = true;
break;
case ',':
throw new IllegalArgumentException("Group separator found at fractional part at " + index +
" in " + string);
throw new IllegalArgumentException("Group separator found at fractional part at " + index
+ " in " + string);
case '0':
if (optionalDigits) {
throw new IllegalArgumentException("Unexpected '0' at optional digit part at " + index +
" in " + string);
throw new IllegalArgumentException("Unexpected '0' at optional digit part at " + index
+ " in " + string);
}
++length;
++minimumLength;
break;
case '.':
throw new IllegalArgumentException("Unexpected second decimal separator at " + index +
" in " + string);
throw new IllegalArgumentException("Unexpected second decimal separator at " + index
+ " in " + string);
default:
break loop;
}
@ -283,8 +283,7 @@ class TDecimalFormatParser {
case ',':
case '.':
case 'E':
throw new IllegalArgumentException("Unexpected char at exponent at " + index +
" in " + string);
throw new IllegalArgumentException("Unexpected char at exponent at " + index + " in " + string);
case '0':
++length;
break;
@ -294,8 +293,8 @@ class TDecimalFormatParser {
++index;
}
if (length == 0) {
throw new IllegalArgumentException("Pattern does not specify exponent digits at " + index +
" in " + string);
throw new IllegalArgumentException("Pattern does not specify exponent digits at " + index
+ " in " + string);
}
if (apply) {
exponentLength = length;

View File

@ -15,8 +15,8 @@
*/
package org.teavm.classlib.java.text;
import org.teavm.classlib.impl.unicode.DecimalData;
import org.teavm.classlib.impl.unicode.CLDRHelper;
import org.teavm.classlib.impl.unicode.DecimalData;
import org.teavm.classlib.java.util.TLocale;
/**
@ -32,7 +32,7 @@ public class TDecimalFormatSymbols implements Cloneable {
private char percent;
private char digit;
private char patternSeparator;
private String NaN;
private String nan;
private String infinity;
private char minusSign;
private char monetaryDecimalSeparator;
@ -56,7 +56,7 @@ public class TDecimalFormatSymbols implements Cloneable {
percent = (char) data.getPercent();
digit = '#';
patternSeparator = ';';
NaN = data.getNaN();
nan = data.getNaN();
infinity = data.getInfinity();
minusSign = (char) data.getMinusSign();
monetaryDecimalSeparator = (char) data.getDecimalSeparator();
@ -136,11 +136,11 @@ public class TDecimalFormatSymbols implements Cloneable {
}
public String getNaN() {
return NaN;
return nan;
}
public void setNaN(String naN) {
NaN = naN;
nan = naN;
}
public String getInfinity() {

View File

@ -1,10 +1,9 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You 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
* Copyright 2015 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
*
@ -14,11 +13,12 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.teavm.classlib.java.text;
public class TFieldPosition {
private int myField, beginIndex, endIndex;
private int myField;
private int beginIndex;
private int endIndex;
private TFormat.Field myAttribute;
public TFieldPosition(int field) {
@ -36,7 +36,8 @@ public class TFieldPosition {
}
void clear() {
beginIndex = endIndex = 0;
beginIndex = 0;
endIndex = 0;
}
@Override
@ -45,8 +46,8 @@ public class TFieldPosition {
return false;
}
TFieldPosition pos = (TFieldPosition) object;
return myField == pos.myField && myAttribute == pos.myAttribute && beginIndex == pos.beginIndex &&
endIndex == pos.endIndex;
return myField == pos.myField && myAttribute == pos.myAttribute && beginIndex == pos.beginIndex
&& endIndex == pos.endIndex;
}
public int getBeginIndex() {
@ -81,7 +82,7 @@ public class TFieldPosition {
@Override
public String toString() {
return getClass().getName() + "[attribute=" + myAttribute + ", field=" + myField + ", beginIndex=" +
beginIndex + ", endIndex=" + endIndex + "]";
return getClass().getName() + "[attribute=" + myAttribute + ", field=" + myField + ", beginIndex="
+ beginIndex + ", endIndex=" + endIndex + "]";
}
}

View File

@ -1,10 +1,9 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You 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
* Copyright 2015 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
*
@ -14,7 +13,6 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.teavm.classlib.java.text;
import org.teavm.classlib.java.io.TSerializable;
@ -46,7 +44,8 @@ public abstract class TFormat implements TSerializable, TCloneable {
if (next == '\'') {
quote = !quote;
}
if (!quote && (index = fromChars.indexOf(next)) != -1) {
index = fromChars.indexOf(next);
if (!quote && index != -1) {
output.append(toChars.charAt(index));
} else if (check && !quote && ((next >= 'a' && next <= 'z') || (next >= 'A' && next <= 'Z'))) {
throw new IllegalArgumentException("Invalid pattern char" + next + " in " + template);
@ -82,8 +81,10 @@ public abstract class TFormat implements TSerializable, TCloneable {
public abstract Object parseObject(String string, TParsePosition position);
static boolean upTo(String string, TParsePosition position, StringBuffer buffer, char stop) {
int index = position.getIndex(), length = string.length();
boolean lastQuote = false, quote = false;
int index = position.getIndex();
int length = string.length();
boolean lastQuote = false;
boolean quote = false;
while (index < length) {
char ch = string.charAt(index++);
if (ch == '\'') {
@ -105,7 +106,9 @@ public abstract class TFormat implements TSerializable, TCloneable {
}
static boolean upToWithQuotes(String string, TParsePosition position, StringBuffer buffer, char stop, char start) {
int index = position.getIndex(), length = string.length(), count = 1;
int index = position.getIndex();
int length = string.length();
int count = 1;
boolean quote = false;
while (index < length) {
char ch = string.charAt(index++);

View File

@ -28,9 +28,12 @@ import org.teavm.classlib.java.util.TLocale;
public abstract class TNumberFormat extends TFormat {
public static final int INTEGER_FIELD = 0;
public static final int FRACTION_FIELD = 1;
private boolean groupingUsed = true, parseIntegerOnly;
private int maximumIntegerDigits = 40, minimumIntegerDigits = 1,
maximumFractionDigits = 3, minimumFractionDigits = 0;
private boolean groupingUsed = true;
private boolean parseIntegerOnly;
private int maximumIntegerDigits = 40;
private int minimumIntegerDigits = 1;
private int maximumFractionDigits = 3;
private int minimumFractionDigits;
private TRoundingMode roundingMode = TRoundingMode.HALF_EVEN;
TCurrency currency = TCurrency.getInstance(TLocale.getDefault());
@ -167,8 +170,8 @@ public abstract class TNumberFormat extends TFormat {
public int hashCode() {
return (groupingUsed ? 1231 : 1237) + (parseIntegerOnly ? 1231 : 1237)
+ maximumFractionDigits + maximumIntegerDigits
+ minimumFractionDigits + minimumIntegerDigits +
roundingMode.hashCode() + Objects.hashCode(currency);
+ minimumFractionDigits + minimumIntegerDigits
+ roundingMode.hashCode() + Objects.hashCode(currency);
}
public boolean isGroupingUsed() {

View File

@ -1,10 +1,9 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You 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
* Copyright 2015 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
*
@ -14,7 +13,6 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.teavm.classlib.java.text;
/**

View File

@ -1,10 +1,9 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You 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
* Copyright 2015 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
*
@ -14,12 +13,11 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.teavm.classlib.java.text;
public class TParsePosition {
private int currentPosition, errorIndex = -1;
private int currentPosition;
private int errorIndex = -1;
public TParsePosition(int index) {
currentPosition = index;

View File

@ -54,15 +54,15 @@ public class TBitSet extends TObject implements TCloneable, TSerializable {
int[] ints = new int[(bytes.length + 3) / 4];
int fullInts = bytes.length / 4;
for (int i = 0; i < fullInts; ++i) {
ints[i] = (bytes[i * 4] & 0xFF) | ((bytes[i * 4 + 1] & 0xFF) << 8) | ((bytes[i * 4 + 2] & 0xFF) << 16) |
((bytes[i * 4 + 3] & 0xFF) << 24);
ints[i] = (bytes[i * 4] & 0xFF) | ((bytes[i * 4 + 1] & 0xFF) << 8) | ((bytes[i * 4 + 2] & 0xFF) << 16)
| ((bytes[i * 4 + 3] & 0xFF) << 24);
}
int lastInt = ints.length - 1;
int lastByte = lastInt * 4;
switch (bytes.length % 4) {
case 3:
ints[lastInt] = (bytes[lastByte] & 0xFF) | ((bytes[lastByte + 1] & 0xFF) << 8) |
((bytes[lastByte + 2] & 0xFF) << 16);
ints[lastInt] = (bytes[lastByte] & 0xFF) | ((bytes[lastByte + 1] & 0xFF) << 8)
| ((bytes[lastByte + 2] & 0xFF) << 16);
break;
case 2:
ints[lastInt] = (bytes[lastByte] & 0xFF) | ((bytes[lastByte + 1] & 0xFF) << 8);
@ -286,7 +286,7 @@ public class TBitSet extends TObject implements TCloneable, TSerializable {
}
int index = fromIndex / 32;
int val = data[index];
val >>>= (fromIndex % 32);
val >>>= fromIndex % 32;
if (val != 0) {
return TInteger.numberOfTrailingZeros(val) + fromIndex;
}
@ -305,7 +305,7 @@ public class TBitSet extends TObject implements TCloneable, TSerializable {
}
int index = fromIndex / 32;
int val = ~data[index];
val >>>= (fromIndex % 32);
val >>>= fromIndex % 32;
if (val != 0) {
return TInteger.numberOfTrailingZeros(val) + fromIndex;
}

Some files were not shown because too many files have changed in this diff Show More