diff --git a/checkstyle.xml b/checkstyle.xml
index 076a1982b..52f882855 100644
--- a/checkstyle.xml
+++ b/checkstyle.xml
@@ -13,14 +13,13 @@
+
-
-
@@ -49,7 +48,9 @@
-
+
+
+
diff --git a/license-regexp.txt b/license-regexp.txt
index 05bf0b063..fe582dd7b 100644
--- a/license-regexp.txt
+++ b/license-regexp.txt
@@ -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.
diff --git a/pom.xml b/pom.xml
index 8f1458297..5bc9cf01f 100644
--- a/pom.xml
+++ b/pom.xml
@@ -123,27 +123,27 @@
org.ow2.asm
asm-debug-all
- 5.0.3
+ 5.0.4
org.apache.maven
maven-plugin-api
- 3.0
+ 3.3.3
org.apache.maven.plugin-tools
maven-plugin-annotations
- 3.0
+ 3.3
org.apache.maven
maven-core
- 3.0
+ 3.3.3
org.apache.maven
maven-artifact
- 3.0
+ 3.3.3
javax.websocket
@@ -165,11 +165,13 @@
slf4j-api
${slf4j.version}
+
@@ -225,7 +227,7 @@
org.apache.maven.plugins
maven-checkstyle-plugin
- 2.11
+ 2.15
validate
diff --git a/teavm-classlib/pom.xml b/teavm-classlib/pom.xml
index 06043e3e7..2b389ecb2 100644
--- a/teavm-classlib/pom.xml
+++ b/teavm-classlib/pom.xml
@@ -78,6 +78,15 @@
+
org.apache.felix
maven-bundle-plugin
diff --git a/teavm-classlib/src/main/java/org/teavm/classlib/impl/Base46.java b/teavm-classlib/src/main/java/org/teavm/classlib/impl/Base46.java
index 9315e1c54..bbc3afc25 100644
--- a/teavm-classlib/src/main/java/org/teavm/classlib/impl/Base46.java
+++ b/teavm-classlib/src/main/java/org/teavm/classlib/impl/Base46.java
@@ -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 {
@@ -47,7 +50,7 @@ public class Base46 {
public static void encodeUnsigned(StringBuilder sb, long number) {
boolean hasMore;
do {
- int digit = (int)(number % 46);
+ int digit = (int) (number % 46);
number /= 46;
hasMore = number > 0;
digit = digit * 2 + (hasMore ? 1 : 0);
@@ -105,11 +108,11 @@ public class Base46 {
public static char encodeDigit(int digit) {
if (digit < 2) {
- return (char)(digit + ' ');
+ return (char) (digit + ' ');
} else if (digit < 59) {
- return (char)(digit + 1 + ' ');
+ return (char) (digit + 1 + ' ');
} else {
- return (char)(digit + 2 + ' ');
+ return (char) (digit + 2 + ' ');
}
}
diff --git a/teavm-classlib/src/main/java/org/teavm/classlib/impl/currency/CountriesGenerator.java b/teavm-classlib/src/main/java/org/teavm/classlib/impl/currency/CountriesGenerator.java
index 2f2d58dfe..dcb712422 100644
--- a/teavm-classlib/src/main/java/org/teavm/classlib/impl/currency/CountriesGenerator.java
+++ b/teavm-classlib/src/main/java/org/teavm/classlib/impl/currency/CountriesGenerator.java
@@ -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 {
diff --git a/teavm-classlib/src/main/java/org/teavm/classlib/impl/currency/CurrenciesGenerator.java b/teavm-classlib/src/main/java/org/teavm/classlib/impl/currency/CurrenciesGenerator.java
index e301e2bdd..f399d7181 100644
--- a/teavm-classlib/src/main/java/org/teavm/classlib/impl/currency/CurrenciesGenerator.java
+++ b/teavm-classlib/src/main/java/org/teavm/classlib/impl/currency/CurrenciesGenerator.java
@@ -101,7 +101,7 @@ public class CurrenciesGenerator implements MetadataGenerator {
}
@Override
public Element next() {
- Element result = (Element)nodes.item(index);
+ Element result = (Element) nodes.item(index);
following();
return result;
}
@@ -129,11 +129,11 @@ public class CurrenciesGenerator implements MetadataGenerator {
switch (child.getNodeType()) {
case Node.TEXT_NODE:
case Node.CDATA_SECTION_NODE:
- CharacterData cdata = (CharacterData)child;
+ CharacterData cdata = (CharacterData) child;
sb.append(cdata.getData());
break;
case Node.ENTITY_REFERENCE_NODE:
- EntityReference ref = (EntityReference)child;
+ EntityReference ref = (EntityReference) child;
sb.append(ref.getNodeValue());
break;
}
diff --git a/teavm-classlib/src/main/java/org/teavm/classlib/impl/currency/CurrencyHelper.java b/teavm-classlib/src/main/java/org/teavm/classlib/impl/currency/CurrencyHelper.java
index 7cb7cc824..fa75ac287 100644
--- a/teavm-classlib/src/main/java/org/teavm/classlib/impl/currency/CurrencyHelper.java
+++ b/teavm-classlib/src/main/java/org/teavm/classlib/impl/currency/CurrencyHelper.java
@@ -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 getCurrencies();
diff --git a/teavm-classlib/src/main/java/org/teavm/classlib/impl/report/JCLComparisonVisitor.java b/teavm-classlib/src/main/java/org/teavm/classlib/impl/report/JCLComparisonVisitor.java
index 3e8ebf29b..1ee97fe51 100644
--- a/teavm-classlib/src/main/java/org/teavm/classlib/impl/report/JCLComparisonVisitor.java
+++ b/teavm-classlib/src/main/java/org/teavm/classlib/impl/report/JCLComparisonVisitor.java
@@ -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;
diff --git a/teavm-classlib/src/main/java/org/teavm/classlib/impl/tz/CachedDateTimeZone.java b/teavm-classlib/src/main/java/org/teavm/classlib/impl/tz/CachedDateTimeZone.java
index f7f3d5989..c7af08d1f 100644
--- a/teavm-classlib/src/main/java/org/teavm/classlib/impl/tz/CachedDateTimeZone.java
+++ b/teavm-classlib/src/main/java/org/teavm/classlib/impl/tz/CachedDateTimeZone.java
@@ -5,7 +5,7 @@
* 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
+ * 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,
@@ -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;
@@ -38,7 +38,7 @@ public class CachedDateTimeZone extends StorableDateTimeZone {
*/
public static CachedDateTimeZone forZone(StorableDateTimeZone zone) {
if (zone instanceof CachedDateTimeZone) {
- return (CachedDateTimeZone)zone;
+ return (CachedDateTimeZone) zone;
}
return new CachedDateTimeZone(zone);
}
@@ -101,11 +101,11 @@ public class CachedDateTimeZone extends StorableDateTimeZone {
// synchronized.
private Info getInfo(long millis) {
- int period = (int)(millis >> 32);
+ int period = (int) (millis >> 32);
Info[] cache = iInfoCache;
int index = period & cInfoCacheMask;
Info info = cache[index];
- if (info == null || (int)((info.iPeriodStart >> 32)) != period) {
+ if (info == null || (int) ((info.iPeriodStart >> 32)) != period) {
info = createInfo(millis);
cache[index] = info;
}
@@ -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;
diff --git a/teavm-classlib/src/main/java/org/teavm/classlib/impl/tz/DateTimeZone.java b/teavm-classlib/src/main/java/org/teavm/classlib/impl/tz/DateTimeZone.java
index 09ae82a25..0fcd6dfd7 100644
--- a/teavm-classlib/src/main/java/org/teavm/classlib/impl/tz/DateTimeZone.java
+++ b/teavm-classlib/src/main/java/org/teavm/classlib/impl/tz/DateTimeZone.java
@@ -5,7 +5,7 @@
* 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
+ * 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,
diff --git a/teavm-classlib/src/main/java/org/teavm/classlib/impl/tz/DateTimeZoneBuilder.java b/teavm-classlib/src/main/java/org/teavm/classlib/impl/tz/DateTimeZoneBuilder.java
index 18cce899b..1f9b29ae8 100644
--- a/teavm-classlib/src/main/java/org/teavm/classlib/impl/tz/DateTimeZoneBuilder.java
+++ b/teavm-classlib/src/main/java/org/teavm/classlib/impl/tz/DateTimeZoneBuilder.java
@@ -5,7 +5,7 @@
* 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
+ * 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,
@@ -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);
@@ -204,7 +195,7 @@ public class DateTimeZoneBuilder {
int saveMillis = 0;
int ruleSetCount = iRuleSets.size();
- for (int i=0; i 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;
@@ -1058,7 +1039,7 @@ public class DateTimeZoneBuilder {
}
public static DSTZone readZone(String id, CharFlow flow) {
- int standardOffset = (int)readTime(flow);
+ int standardOffset = (int) readTime(flow);
Recurrence startRecurrence = Recurrence.read(flow);
Recurrence endRecurrence = Recurrence.read(flow);
return new DSTZone(id, standardOffset, startRecurrence, endRecurrence);
@@ -1075,7 +1056,7 @@ public class DateTimeZoneBuilder {
* @param tailZone optional zone for getting info beyond precalculated tables
*/
static PrecalculatedZone create(String id, boolean outputID, ArrayList transitions,
- DSTZone tailZone) {
+ DSTZone tailZone) {
int size = transitions.size();
if (size == 0) {
throw new IllegalArgumentException();
@@ -1086,7 +1067,7 @@ public class DateTimeZoneBuilder {
int[] standardOffsets = new int[size];
Transition last = null;
- for (int i=0; i cache = new HashMap<>();
+ private DateTimeZoneProvider() {
+ }
+
public static DateTimeZone getTimeZone(String id) {
if (!cache.containsKey(id)) {
cache.put(id, createTimeZone(id));
@@ -142,7 +145,7 @@ public class DateTimeZoneProvider {
Score score = scoreTable.get(i);
int tzOffset = score.tz.getOffset(time) / 60_000;
if (tzOffset != offset) {
- score.value += (int)((last - time) / 60_000) * (Math.abs(tzOffset - offset)) / 30;
+ score.value += (int) ((last - time) / 60_000) * (Math.abs(tzOffset - offset)) / 30;
}
int j = i + 1;
while (j < scoreTable.size() && score.value > scoreTable.get(j).value) {
diff --git a/teavm-classlib/src/main/java/org/teavm/classlib/impl/tz/FixedDateTimeZone.java b/teavm-classlib/src/main/java/org/teavm/classlib/impl/tz/FixedDateTimeZone.java
index 21e2a780c..72025bc83 100644
--- a/teavm-classlib/src/main/java/org/teavm/classlib/impl/tz/FixedDateTimeZone.java
+++ b/teavm-classlib/src/main/java/org/teavm/classlib/impl/tz/FixedDateTimeZone.java
@@ -5,7 +5,7 @@
* 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
+ * 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,
@@ -74,8 +74,8 @@ public final class FixedDateTimeZone extends StorableDateTimeZone {
}
public static FixedDateTimeZone readZone(String id, CharFlow flow) {
- int wallOffset = (int)readTime(flow);
- int standardOffset = (int)readTime(flow);
+ int wallOffset = (int) readTime(flow);
+ int standardOffset = (int) readTime(flow);
return new FixedDateTimeZone(id, wallOffset, standardOffset);
}
}
diff --git a/teavm-classlib/src/main/java/org/teavm/classlib/impl/tz/StorableDateTimeZone.java b/teavm-classlib/src/main/java/org/teavm/classlib/impl/tz/StorableDateTimeZone.java
index 025d8c905..1e5b2cabe 100644
--- a/teavm-classlib/src/main/java/org/teavm/classlib/impl/tz/StorableDateTimeZone.java
+++ b/teavm-classlib/src/main/java/org/teavm/classlib/impl/tz/StorableDateTimeZone.java
@@ -38,9 +38,9 @@ public abstract class StorableDateTimeZone extends DateTimeZone {
public static void writeTime(StringBuilder sb, long time) {
if (time % 1800_000 == 0) {
- Base46.encode(sb, (int)((time / 1800_000) << 1));
+ Base46.encode(sb, (int) ((time / 1800_000) << 1));
} else {
- Base46.encode(sb, (int)(((time / 60_000) << 1) | 1));
+ Base46.encode(sb, (int) (((time / 60_000) << 1) | 1));
}
}
@@ -55,9 +55,9 @@ public abstract class StorableDateTimeZone extends DateTimeZone {
public static void writeUnsignedTime(StringBuilder sb, long time) {
if (time % 1800_000 == 0) {
- Base46.encodeUnsigned(sb, (int)((time / 1800_000) << 1));
+ Base46.encodeUnsigned(sb, (int) ((time / 1800_000) << 1));
} else {
- Base46.encodeUnsigned(sb, (int)(((time / 60_000) << 1) | 1));
+ Base46.encodeUnsigned(sb, (int) (((time / 60_000) << 1) | 1));
}
}
@@ -105,14 +105,14 @@ public abstract class StorableDateTimeZone extends DateTimeZone {
while (index < array.length) {
int count = Base46.decode(flow);
if (count >= 0) {
- int t = (int)readTime(flow);
+ int t = (int) readTime(flow);
while (count-- > 0) {
array[index++] = t;
}
} else {
count = ~count;
while (count-- > 0) {
- array[index++] = (int)readTime(flow);
+ array[index++] = (int) readTime(flow);
}
}
}
diff --git a/teavm-classlib/src/main/java/org/teavm/classlib/impl/tz/ZoneInfoCompiler.java b/teavm-classlib/src/main/java/org/teavm/classlib/impl/tz/ZoneInfoCompiler.java
index df59f31b9..5030a58d5 100644
--- a/teavm-classlib/src/main/java/org/teavm/classlib/impl/tz/ZoneInfoCompiler.java
+++ b/teavm-classlib/src/main/java/org/teavm/classlib/impl/tz/ZoneInfoCompiler.java
@@ -5,7 +5,7 @@
* 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
+ * 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,
@@ -106,7 +106,7 @@ public class ZoneInfoCompiler {
if (newPos == ~pos) {
throw new IllegalArgumentException(str);
}
- int millis = (int)mdt.getMillis();
+ int millis = (int) mdt.getMillis();
if (pos == 1) {
millis = -millis;
}
@@ -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;
@@ -172,7 +170,7 @@ public class ZoneInfoCompiler {
millis = ISOChronology.getInstanceUTC().year().set(0, 2050);
end = ISOChronology.getInstanceUTC().year().set(0, 1850);
- for (int i=transitions.size(); --i>= 0; ) {
+ for (int i = transitions.size(); --i >= 0;) {
long prev = tz.previousTransition(millis);
if (prev == millis || prev < end) {
break;
@@ -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";
}
}
@@ -531,7 +516,7 @@ public class ZoneInfoCompiler {
* Adds recurring savings rules to the builder.
*/
public void addRecurring(DateTimeZoneBuilder builder) {
- for (int i=0; i ruleSets)
- {
+ private static void addToBuilder(Zone zone, DateTimeZoneBuilder builder, Map 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;
diff --git a/teavm-classlib/src/main/java/org/teavm/classlib/impl/unicode/CLDRDecimalData.java b/teavm-classlib/src/main/java/org/teavm/classlib/impl/unicode/CLDRDecimalData.java
index 0f7a48b5f..7cec74757 100644
--- a/teavm-classlib/src/main/java/org/teavm/classlib/impl/unicode/CLDRDecimalData.java
+++ b/teavm-classlib/src/main/java/org/teavm/classlib/impl/unicode/CLDRDecimalData.java
@@ -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() {
diff --git a/teavm-classlib/src/main/java/org/teavm/classlib/impl/unicode/CLDRHelper.java b/teavm-classlib/src/main/java/org/teavm/classlib/impl/unicode/CLDRHelper.java
index 524e9020d..0d5f2efa7 100644
--- a/teavm-classlib/src/main/java/org/teavm/classlib/impl/unicode/CLDRHelper.java
+++ b/teavm-classlib/src/main/java/org/teavm/classlib/impl/unicode/CLDRHelper.java
@@ -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> map, String language,
String country) {
String localeCode = getCode(language, country);
- ResourceArray arrayRes = map.has(localeCode) ? map.get(localeCode) :
- map.has(language) ? map.get(language) : map.get("root");
+ ResourceArray 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 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 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)
diff --git a/teavm-classlib/src/main/java/org/teavm/classlib/impl/unicode/CLDRReader.java b/teavm-classlib/src/main/java/org/teavm/classlib/impl/unicode/CLDRReader.java
index 965c3cc22..9c453341e 100644
--- a/teavm-classlib/src/main/java/org/teavm/classlib/impl/unicode/CLDRReader.java
+++ b/teavm-classlib/src/main/java/org/teavm/classlib/impl/unicode/CLDRReader.java
@@ -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;
/**
*
@@ -115,7 +123,7 @@ public class CLDRReader {
readTimeZones(localeName, localeInfo, input);
break;
case "ca-gregorian.json": {
- JsonObject root = (JsonObject)new JsonParser().parse(new InputStreamReader(input));
+ JsonObject root = (JsonObject) new JsonParser().parse(new InputStreamReader(input));
readEras(localeName, localeInfo, root);
readAmPms(localeName, localeInfo, root);
readMonths(localeName, localeInfo, root);
@@ -141,7 +149,7 @@ public class CLDRReader {
}
private void readLanguages(String localeCode, CLDRLocale locale, InputStream input) {
- JsonObject root = (JsonObject)new JsonParser().parse(new InputStreamReader(input));
+ JsonObject root = (JsonObject) new JsonParser().parse(new InputStreamReader(input));
JsonObject languagesJson = root.get("main").getAsJsonObject().get(localeCode).getAsJsonObject()
.get("localeDisplayNames").getAsJsonObject().get("languages").getAsJsonObject();
for (Map.Entry property : languagesJson.entrySet()) {
@@ -153,7 +161,7 @@ public class CLDRReader {
}
private void readCountries(String localeCode, CLDRLocale locale, InputStream input) {
- JsonObject root = (JsonObject)new JsonParser().parse(new InputStreamReader(input));
+ JsonObject root = (JsonObject) new JsonParser().parse(new InputStreamReader(input));
JsonObject countriesJson = root.get("main").getAsJsonObject().get(localeCode).getAsJsonObject()
.get("localeDisplayNames").getAsJsonObject().get("territories").getAsJsonObject();
for (Map.Entry property : countriesJson.entrySet()) {
@@ -165,7 +173,7 @@ public class CLDRReader {
}
private void readTimeZones(String localeCode, CLDRLocale locale, InputStream input) {
- JsonObject root = (JsonObject)new JsonParser().parse(new InputStreamReader(input));
+ JsonObject root = (JsonObject) new JsonParser().parse(new InputStreamReader(input));
JsonObject zonesJson = root.get("main").getAsJsonObject().get(localeCode).getAsJsonObject()
.get("dates").getAsJsonObject().get("timeZoneNames").getAsJsonObject().get("zone")
.getAsJsonObject();
@@ -195,7 +203,7 @@ public class CLDRReader {
}
private void readCurrencies(String localeCode, CLDRLocale locale, InputStream input) {
- JsonObject root = (JsonObject)new JsonParser().parse(new InputStreamReader(input));
+ JsonObject root = (JsonObject) new JsonParser().parse(new InputStreamReader(input));
JsonObject currenciesJson = root.get("main").getAsJsonObject().get(localeCode).getAsJsonObject()
.get("numbers").getAsJsonObject().get("currencies").getAsJsonObject();
for (Map.Entry currencyEntry : currenciesJson.entrySet()) {
@@ -211,7 +219,7 @@ public class CLDRReader {
}
private void readNumbers(String localeCode, CLDRLocale locale, InputStream input) {
- JsonObject root = (JsonObject)new JsonParser().parse(new InputStreamReader(input));
+ JsonObject root = (JsonObject) new JsonParser().parse(new InputStreamReader(input));
JsonObject numbersJson = root.get("main").getAsJsonObject().get(localeCode).getAsJsonObject()
.get("numbers").getAsJsonObject();
String numbering = numbersJson.get("defaultNumberingSystem").getAsString();
@@ -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();
@@ -327,7 +335,7 @@ public class CLDRReader {
}
private void readWeekData(InputStream input) {
- JsonObject root = (JsonObject)new JsonParser().parse(new InputStreamReader(input));
+ JsonObject root = (JsonObject) new JsonParser().parse(new InputStreamReader(input));
JsonObject weekJson = root.get("supplemental").getAsJsonObject().get("weekData").getAsJsonObject();
JsonObject minDaysJson = weekJson.get("minDays").getAsJsonObject();
for (Map.Entry property : minDaysJson.entrySet()) {
@@ -340,7 +348,7 @@ public class CLDRReader {
}
private void readLikelySubtags(InputStream input) {
- JsonObject root = (JsonObject)new JsonParser().parse(new InputStreamReader(input));
+ JsonObject root = (JsonObject) new JsonParser().parse(new InputStreamReader(input));
JsonObject likelySubtagsJson = root.get("supplemental").getAsJsonObject().get("likelySubtags")
.getAsJsonObject();
for (Map.Entry property : likelySubtagsJson.entrySet()) {
diff --git a/teavm-classlib/src/main/java/org/teavm/classlib/impl/unicode/DateSymbolsMetadataGenerator.java b/teavm-classlib/src/main/java/org/teavm/classlib/impl/unicode/DateSymbolsMetadataGenerator.java
index 424c9f9d4..3591a2bce 100644
--- a/teavm-classlib/src/main/java/org/teavm/classlib/impl/unicode/DateSymbolsMetadataGenerator.java
+++ b/teavm-classlib/src/main/java/org/teavm/classlib/impl/unicode/DateSymbolsMetadataGenerator.java
@@ -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);
}
}
diff --git a/teavm-classlib/src/main/java/org/teavm/classlib/impl/unicode/UnicodeHelper.java b/teavm-classlib/src/main/java/org/teavm/classlib/impl/unicode/UnicodeHelper.java
index 94d69ad79..c5e8f4f93 100644
--- a/teavm-classlib/src/main/java/org/teavm/classlib/impl/unicode/UnicodeHelper.java
+++ b/teavm-classlib/src/main/java/org/teavm/classlib/impl/unicode/UnicodeHelper.java
@@ -24,9 +24,12 @@ 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);
+ return value < 10 ? (char) ('0' + value) : (char) ('A' + value);
}
static int valueOfHexDigit(char digit) {
@@ -66,21 +69,21 @@ public class UnicodeHelper {
public static char encodeByte(byte b) {
if (b < '\"' - ' ') {
- return (char)(b + ' ');
+ return (char) (b + ' ');
} else if (b < '\\' - ' ' - 1) {
- return (char)(b + ' ' + 1);
+ return (char) (b + ' ' + 1);
} else {
- return (char)(b + ' ' + 2);
+ return (char) (b + ' ' + 2);
}
}
public static byte decodeByte(char c) {
if (c > '\\') {
- return (byte)(c - ' ' - 2);
+ return (byte) (c - ' ' - 2);
} else if (c > '"') {
- return (byte)(c - ' ' - 1);
+ return (byte) (c - ' ' - 1);
} else {
- return (byte)(c - ' ');
+ return (byte) (c - ' ');
}
}
@@ -95,13 +98,13 @@ public class UnicodeHelper {
}
i += count;
if (count < 80) {
- sb.append(UnicodeHelper.encodeByte((byte)(b + 32)));
- sb.append(UnicodeHelper.encodeByte((byte)count));
+ sb.append(UnicodeHelper.encodeByte((byte) (b + 32)));
+ sb.append(UnicodeHelper.encodeByte((byte) count));
} else {
- sb.append(UnicodeHelper.encodeByte((byte)64));
+ sb.append(UnicodeHelper.encodeByte((byte) 64));
sb.append(UnicodeHelper.encodeByte(b));
for (int j = 0; j < 3; ++j) {
- sb.append(UnicodeHelper.encodeByte((byte)(count & 0x3F)));
+ sb.append(UnicodeHelper.encodeByte((byte) (count & 0x3F)));
count /= 0x40;
}
}
diff --git a/teavm-classlib/src/main/java/org/teavm/classlib/impl/unicode/UnicodeSupport.java b/teavm-classlib/src/main/java/org/teavm/classlib/impl/unicode/UnicodeSupport.java
index 296b99b0c..f7cd1358a 100644
--- a/teavm-classlib/src/main/java/org/teavm/classlib/impl/unicode/UnicodeSupport.java
+++ b/teavm-classlib/src/main/java/org/teavm/classlib/impl/unicode/UnicodeSupport.java
@@ -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);
@@ -119,7 +122,7 @@ public class UnicodeSupport {
UnicodeSupport.digitValues = mergePairs(digitValues.getAll(), letterDigitValues.getAll());
UnicodeSupport.classes = new byte[classes.size()];
for (int i = 0; i < classes.size(); ++i) {
- UnicodeSupport.classes[i] = (byte)classes.get(i);
+ UnicodeSupport.classes[i] = (byte) classes.get(i);
}
}
diff --git a/teavm-classlib/src/main/java/org/teavm/classlib/java/io/TBufferedInputStream.java b/teavm-classlib/src/main/java/org/teavm/classlib/java/io/TBufferedInputStream.java
index a69ee9e86..7fefe7193 100644
--- a/teavm-classlib/src/main/java/org/teavm/classlib/java/io/TBufferedInputStream.java
+++ b/teavm-classlib/src/main/java/org/teavm/classlib/java/io/TBufferedInputStream.java
@@ -1,12 +1,11 @@
/*
- * 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.
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * 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,
@@ -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;
}
diff --git a/teavm-classlib/src/main/java/org/teavm/classlib/java/io/TBufferedReader.java b/teavm-classlib/src/main/java/org/teavm/classlib/java/io/TBufferedReader.java
index b745f7fcd..fe5b6b0b8 100644
--- a/teavm-classlib/src/main/java/org/teavm/classlib/java/io/TBufferedReader.java
+++ b/teavm-classlib/src/main/java/org/teavm/classlib/java/io/TBufferedReader.java
@@ -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);
diff --git a/teavm-classlib/src/main/java/org/teavm/classlib/java/io/TByteArrayInputStream.java b/teavm-classlib/src/main/java/org/teavm/classlib/java/io/TByteArrayInputStream.java
index b6963a49e..1243d5056 100644
--- a/teavm-classlib/src/main/java/org/teavm/classlib/java/io/TByteArrayInputStream.java
+++ b/teavm-classlib/src/main/java/org/teavm/classlib/java/io/TByteArrayInputStream.java
@@ -54,7 +54,7 @@ public class TByteArrayInputStream extends TInputStream {
@Override
public long skip(long n) {
- int bytesSkipped = (int)TMath.min(n, count - pos);
+ int bytesSkipped = (int) TMath.min(n, count - pos);
pos += bytesSkipped;
return bytesSkipped;
}
diff --git a/teavm-classlib/src/main/java/org/teavm/classlib/java/io/TByteArrayOutputStream.java b/teavm-classlib/src/main/java/org/teavm/classlib/java/io/TByteArrayOutputStream.java
index 69c991994..afdc4c4dd 100644
--- a/teavm-classlib/src/main/java/org/teavm/classlib/java/io/TByteArrayOutputStream.java
+++ b/teavm-classlib/src/main/java/org/teavm/classlib/java/io/TByteArrayOutputStream.java
@@ -38,7 +38,7 @@ public class TByteArrayOutputStream extends TOutputStream {
@Override
public void write(int b) {
ensureCapacity(count + 1);
- buf[count++] = (byte)b;
+ buf[count++] = (byte) b;
}
@Override
diff --git a/teavm-classlib/src/main/java/org/teavm/classlib/java/io/TCloseable.java b/teavm-classlib/src/main/java/org/teavm/classlib/java/io/TCloseable.java
index 52735c541..1a0c5c117 100644
--- a/teavm-classlib/src/main/java/org/teavm/classlib/java/io/TCloseable.java
+++ b/teavm-classlib/src/main/java/org/teavm/classlib/java/io/TCloseable.java
@@ -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;
}
diff --git a/teavm-classlib/src/main/java/org/teavm/classlib/java/io/TDataInputStream.java b/teavm-classlib/src/main/java/org/teavm/classlib/java/io/TDataInputStream.java
index acbf748b6..f0471eff5 100644
--- a/teavm-classlib/src/main/java/org/teavm/classlib/java/io/TDataInputStream.java
+++ b/teavm-classlib/src/main/java/org/teavm/classlib/java/io/TDataInputStream.java
@@ -54,14 +54,16 @@ public class TDataInputStream extends TFilterInputStream implements TDataInput {
if (temp < 0) {
throw new TEOFException();
}
- return (byte)temp;
+ return (byte) temp;
}
private int readToBuff(int count) throws TIOException {
int offset = 0;
- while(offset < count) {
+ 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;
@@ -69,7 +71,7 @@ public class TDataInputStream extends TFilterInputStream implements TDataInput {
@Override
public final char readChar() throws TIOException {
- if (readToBuff(2) < 0){
+ if (readToBuff(2) < 0) {
throw new TEOFException();
}
return (char) (((buff[0] & 0xff) << 8) | (buff[1] & 0xff));
@@ -120,7 +122,7 @@ public class TDataInputStream extends TFilterInputStream implements TDataInput {
@Override
public final int readInt() throws TIOException {
- if (readToBuff(4) < 0){
+ if (readToBuff(4) < 0) {
throw new TEOFException();
}
return ((buff[0] & 0xff) << 24) | ((buff[1] & 0xff) << 16) | ((buff[2] & 0xff) << 8) | (buff[3] & 0xff);
@@ -141,7 +143,7 @@ public class TDataInputStream extends TFilterInputStream implements TDataInput {
return TString.wrap(line.toString());
case (byte) '\r':
if (foundTerminator) {
- ((TPushbackInputStream)in).unread(nextByte);
+ ((TPushbackInputStream) in).unread(nextByte);
return TString.wrap(line.toString());
}
foundTerminator = true;
@@ -154,7 +156,7 @@ public class TDataInputStream extends TFilterInputStream implements TDataInput {
return TString.wrap(line.toString());
default:
if (foundTerminator) {
- ((TPushbackInputStream)in).unread(nextByte);
+ ((TPushbackInputStream) in).unread(nextByte);
return TString.wrap(line.toString());
}
line.append((char) nextByte);
@@ -164,19 +166,19 @@ public class TDataInputStream extends TFilterInputStream implements TDataInput {
@Override
public final long readLong() throws TIOException {
- if (readToBuff(8) < 0){
+ 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);
}
@Override
public final short readShort() throws TIOException {
- if (readToBuff(2) < 0){
+ if (readToBuff(2) < 0) {
throw new TEOFException();
}
return (short) (((buff[0] & 0xff) << 8) | (buff[1] & 0xff));
@@ -193,7 +195,7 @@ public class TDataInputStream extends TFilterInputStream implements TDataInput {
@Override
public final int readUnsignedShort() throws TIOException {
- if (readToBuff(2) < 0){
+ if (readToBuff(2) < 0) {
throw new TEOFException();
}
return (char) (((buff[0] & 0xff) << 8) | (buff[1] & 0xff));
@@ -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) {
@@ -239,11 +245,12 @@ public class TDataInputStream extends TFilterInputStream implements TDataInput {
int s = 0;
int a;
while (count < utfSize) {
- char ch = (char)buf[offset + count++];
+ 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"));
}
@@ -261,7 +268,7 @@ public class TDataInputStream extends TFilterInputStream implements TDataInput {
if (((b & 0xC0) != 0x80) || ((c & 0xC0) != 0x80)) {
throw new TUTFDataFormatException(TString.wrap("Malformed UTF-8 sequence"));
}
- out[s++] = (char)(((a & 0x0F) << 12) | ((b & 0x3F) << 6) | (c & 0x3F));
+ out[s++] = (char) (((a & 0x0F) << 12) | ((b & 0x3F) << 6) | (c & 0x3F));
} else {
throw new TUTFDataFormatException(TString.wrap("Malformed UTF-8 sequence"));
}
diff --git a/teavm-classlib/src/main/java/org/teavm/classlib/java/io/TDataOutput.java b/teavm-classlib/src/main/java/org/teavm/classlib/java/io/TDataOutput.java
index 9ec31e277..c1f442e94 100644
--- a/teavm-classlib/src/main/java/org/teavm/classlib/java/io/TDataOutput.java
+++ b/teavm-classlib/src/main/java/org/teavm/classlib/java/io/TDataOutput.java
@@ -18,7 +18,7 @@ package org.teavm.classlib.java.io;
import org.teavm.classlib.java.lang.TString;
-public interface TDataOutput{
+public interface TDataOutput {
void write(int b) throws TIOException;
void write(byte[] b) throws TIOException;
diff --git a/teavm-classlib/src/main/java/org/teavm/classlib/java/io/TDataOutputStream.java b/teavm-classlib/src/main/java/org/teavm/classlib/java/io/TDataOutputStream.java
index 709d613da..906e0a568 100644
--- a/teavm-classlib/src/main/java/org/teavm/classlib/java/io/TDataOutputStream.java
+++ b/teavm-classlib/src/main/java/org/teavm/classlib/java/io/TDataOutputStream.java
@@ -1,12 +1,11 @@
/*
- * 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.
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * 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,
@@ -14,16 +13,15 @@
* 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.*;
-public class TDataOutputStream extends TFilterOutputStream implements TDataOutput{
+public class TDataOutputStream extends TFilterOutputStream implements TDataOutput {
/**
* 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;
@@ -170,7 +166,7 @@ public class TDataOutputStream extends TFilterOutputStream implements TDataOutpu
if (utfCount > 65535) {
throw new TIOException(TString.wrap("UTF Error"));
}
- byte[] buffer = new byte[(int)utfCount + 2];
+ byte[] buffer = new byte[(int) utfCount + 2];
int offset = 0;
offset = writeShortToBuffer((int) utfCount, buffer, offset);
offset = writeUTFBytesToBuffer(str, buffer, 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) {
diff --git a/teavm-classlib/src/main/java/org/teavm/classlib/java/io/TFilterInputStream.java b/teavm-classlib/src/main/java/org/teavm/classlib/java/io/TFilterInputStream.java
index fe7d27796..79e662448 100644
--- a/teavm-classlib/src/main/java/org/teavm/classlib/java/io/TFilterInputStream.java
+++ b/teavm-classlib/src/main/java/org/teavm/classlib/java/io/TFilterInputStream.java
@@ -1,12 +1,11 @@
/*
- * 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.
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * 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,
diff --git a/teavm-classlib/src/main/java/org/teavm/classlib/java/io/TInputStream.java b/teavm-classlib/src/main/java/org/teavm/classlib/java/io/TInputStream.java
index b920d370f..02ac0b362 100644
--- a/teavm-classlib/src/main/java/org/teavm/classlib/java/io/TInputStream.java
+++ b/teavm-classlib/src/main/java/org/teavm/classlib/java/io/TInputStream.java
@@ -38,14 +38,14 @@ public abstract class TInputStream extends TObject implements TCloseable {
if (bt < 0) {
return i == 0 ? -1 : i;
}
- b[off++] = (byte)bt;
+ b[off++] = (byte) bt;
}
return len > 0 ? len : -1;
}
public long skip(long n) throws TIOException {
if (n < TInteger.MAX_VALUE) {
- return skip((int)n);
+ return skip((int) n);
} else {
for (long i = 0; i < n; ++i) {
if (read() < 0) {
diff --git a/teavm-classlib/src/main/java/org/teavm/classlib/java/io/TOutputStreamWriter.java b/teavm-classlib/src/main/java/org/teavm/classlib/java/io/TOutputStreamWriter.java
index 9ced7e453..6c40fc466 100644
--- a/teavm-classlib/src/main/java/org/teavm/classlib/java/io/TOutputStreamWriter.java
+++ b/teavm-classlib/src/main/java/org/teavm/classlib/java/io/TOutputStreamWriter.java
@@ -117,7 +117,7 @@ public class TOutputStreamWriter extends TWriter {
@Override
public void write(int oneChar) throws TIOException {
- char[] array = { (char)oneChar };
+ char[] array = { (char) oneChar };
write(array, 0, array.length);
}
diff --git a/teavm-classlib/src/main/java/org/teavm/classlib/java/io/TPushbackInputStream.java b/teavm-classlib/src/main/java/org/teavm/classlib/java/io/TPushbackInputStream.java
index 6b3ca3c3f..eb17e6aad 100644
--- a/teavm-classlib/src/main/java/org/teavm/classlib/java/io/TPushbackInputStream.java
+++ b/teavm-classlib/src/main/java/org/teavm/classlib/java/io/TPushbackInputStream.java
@@ -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;
diff --git a/teavm-classlib/src/main/java/org/teavm/classlib/java/io/TReader.java b/teavm-classlib/src/main/java/org/teavm/classlib/java/io/TReader.java
index 7d028ba89..eb6064f53 100644
--- a/teavm-classlib/src/main/java/org/teavm/classlib/java/io/TReader.java
+++ b/teavm-classlib/src/main/java/org/teavm/classlib/java/io/TReader.java
@@ -48,7 +48,7 @@ public abstract class TReader implements TCloseable {
char[] buffer = new char[1024];
long skipped = 0;
while (skipped < n) {
- int charsRead = read(buffer, 0, (int)TMath.min(n, buffer.length));
+ int charsRead = read(buffer, 0, (int) TMath.min(n, buffer.length));
if (charsRead < 0) {
break;
}
diff --git a/teavm-classlib/src/main/java/org/teavm/classlib/java/io/TStringReader.java b/teavm-classlib/src/main/java/org/teavm/classlib/java/io/TStringReader.java
index 74f99efe7..34396ba3d 100644
--- a/teavm-classlib/src/main/java/org/teavm/classlib/java/io/TStringReader.java
+++ b/teavm-classlib/src/main/java/org/teavm/classlib/java/io/TStringReader.java
@@ -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) {
diff --git a/teavm-classlib/src/main/java/org/teavm/classlib/java/io/TWriter.java b/teavm-classlib/src/main/java/org/teavm/classlib/java/io/TWriter.java
index 4155d3b57..a68ec6881 100644
--- a/teavm-classlib/src/main/java/org/teavm/classlib/java/io/TWriter.java
+++ b/teavm-classlib/src/main/java/org/teavm/classlib/java/io/TWriter.java
@@ -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);
diff --git a/teavm-classlib/src/main/java/org/teavm/classlib/java/lang/TAbstractStringBuilder.java b/teavm-classlib/src/main/java/org/teavm/classlib/java/lang/TAbstractStringBuilder.java
index 4a45b92ec..8c9e22f0b 100644
--- a/teavm-classlib/src/main/java/org/teavm/classlib/java/lang/TAbstractStringBuilder.java
+++ b/teavm-classlib/src/main/java/org/teavm/classlib/java/lang/TAbstractStringBuilder.java
@@ -54,7 +54,7 @@ class TAbstractStringBuilder extends TObject implements TSerializable, TCharSequ
}
public TAbstractStringBuilder(TString value) {
- this((TCharSequence)value);
+ this((TCharSequence) value);
}
public TAbstractStringBuilder(TCharSequence value) {
@@ -164,7 +164,7 @@ class TAbstractStringBuilder extends TObject implements TSerializable, TCharSequ
} else {
insertSpace(target, target + 1);
}
- buffer[target++] = Character.forDigit((int)value, radix);
+ buffer[target++] = Character.forDigit((int) value, radix);
} else {
int sz = 1;
long pos = 1;
@@ -180,7 +180,7 @@ class TAbstractStringBuilder extends TObject implements TSerializable, TCharSequ
buffer[target++] = '-';
}
while (pos > 0) {
- buffer[target++] = TCharacter.forDigit((int)(value / pos), radix);
+ buffer[target++] = TCharacter.forDigit((int) (value / pos), radix);
value %= pos;
pos /= radix;
}
@@ -254,7 +254,7 @@ class TAbstractStringBuilder extends TObject implements TSerializable, TCharSequ
}
bit >>= 1;
}
- mantissa = (int)((value / (digit / FLOAT_DECIMAL_FACTOR)) + 0.5f);
+ mantissa = (int) ((value / (digit / FLOAT_DECIMAL_FACTOR)) + 0.5f);
} else {
int bit = 32;
exp = 0;
@@ -267,7 +267,7 @@ class TAbstractStringBuilder extends TObject implements TSerializable, TCharSequ
bit >>= 1;
}
exp = -exp;
- mantissa = (int)(((value * FLOAT_MAX_POS) / digit) + 0.5f);
+ mantissa = (int) (((value * FLOAT_MAX_POS) / digit) + 0.5f);
}
// Remove trailing zeros
@@ -320,7 +320,7 @@ class TAbstractStringBuilder extends TObject implements TSerializable, TCharSequ
} else {
intDigit = 0;
}
- buffer[target++] = (char)('0' + intDigit);
+ buffer[target++] = (char) ('0' + intDigit);
if (--intPart == 0) {
buffer[target++] = '.';
}
@@ -335,9 +335,9 @@ class TAbstractStringBuilder extends TObject implements TSerializable, TCharSequ
buffer[target++] = '-';
}
if (exp >= 10) {
- buffer[target++] = (char)('0' + exp / 10);
+ buffer[target++] = (char) ('0' + exp / 10);
}
- buffer[target++] = (char)('0' + exp % 10);
+ buffer[target++] = (char) ('0' + exp % 10);
}
return this;
}
@@ -408,7 +408,7 @@ class TAbstractStringBuilder extends TObject implements TSerializable, TCharSequ
}
bit >>= 1;
}
- mantissa = (long)(((value / digit) * DOUBLE_DECIMAL_FACTOR) + 0.5);
+ mantissa = (long) (((value / digit) * DOUBLE_DECIMAL_FACTOR) + 0.5);
} else {
int bit = 256;
exp = 0;
@@ -421,7 +421,7 @@ class TAbstractStringBuilder extends TObject implements TSerializable, TCharSequ
bit >>= 1;
}
exp = -exp;
- mantissa = (long)(((value * DOUBLE_MAX_POS) / digit) + 0.5);
+ mantissa = (long) (((value * DOUBLE_MAX_POS) / digit) + 0.5);
}
// Remove trailing zeros
@@ -472,12 +472,12 @@ class TAbstractStringBuilder extends TObject implements TSerializable, TCharSequ
for (int i = 0; i < digits; ++i) {
int intDigit;
if (pos > 0) {
- intDigit = (int)(mantissa / pos);
+ intDigit = (int) (mantissa / pos);
mantissa %= pos;
} else {
intDigit = 0;
}
- buffer[target++] = (char)('0' + intDigit);
+ buffer[target++] = (char) ('0' + intDigit);
if (--intPart == 0) {
buffer[target++] = '.';
}
@@ -492,13 +492,13 @@ class TAbstractStringBuilder extends TObject implements TSerializable, TCharSequ
buffer[target++] = '-';
}
if (exp >= 100) {
- buffer[target++] = (char)('0' + exp / 100);
+ buffer[target++] = (char) ('0' + exp / 100);
exp %= 100;
- buffer[target++] = (char)('0' + exp / 10);
+ buffer[target++] = (char) ('0' + exp / 10);
} else if (exp >= 10) {
- buffer[target++] = (char)('0' + exp / 10);
+ buffer[target++] = (char) ('0' + exp / 10);
}
- buffer[target++] = (char)('0' + exp % 10);
+ buffer[target++] = (char) ('0' + exp % 10);
}
return this;
}
@@ -553,7 +553,7 @@ class TAbstractStringBuilder extends TObject implements TSerializable, TCharSequ
protected TAbstractStringBuilder appendCodePoint(int codePoint) {
if (codePoint < TCharacter.MIN_SUPPLEMENTARY_CODE_POINT) {
- return append((char)codePoint);
+ return append((char) codePoint);
}
ensureCapacity(length + 2);
buffer[length++] = TCharacter.highSurrogate(codePoint);
@@ -632,7 +632,7 @@ class TAbstractStringBuilder extends TObject implements TSerializable, TCharSequ
}
protected TAbstractStringBuilder append(TStringBuffer s) {
- return append((TCharSequence)s);
+ return append((TCharSequence) s);
}
protected TAbstractStringBuilder insert(int index, TCharSequence s) {
diff --git a/teavm-classlib/src/main/java/org/teavm/classlib/java/lang/TBoolean.java b/teavm-classlib/src/main/java/org/teavm/classlib/java/lang/TBoolean.java
index 14c3772c9..e5ed70733 100644
--- a/teavm-classlib/src/main/java/org/teavm/classlib/java/lang/TBoolean.java
+++ b/teavm-classlib/src/main/java/org/teavm/classlib/java/lang/TBoolean.java
@@ -88,7 +88,7 @@ public class TBoolean extends TObject implements TSerializable, TComparable {
@Override
public boolean equals(Object other) {
- return other instanceof TByte && ((TByte)other).value == value;
+ return other instanceof TByte && ((TByte) other).value == value;
}
@Override
@@ -101,7 +101,7 @@ public class TByte extends TNumber implements TComparable {
if (value < MIN_VALUE || value >= MAX_VALUE) {
throw new TNumberFormatException();
}
- return (byte)value;
+ return (byte) value;
}
public static TByte valueOf(TString s, int radix) throws TNumberFormatException {
@@ -117,6 +117,6 @@ public class TByte extends TNumber implements TComparable {
if (value.intValue() < MIN_VALUE || value.intValue() >= MAX_VALUE) {
throw new TNumberFormatException();
}
- return TByte.valueOf((byte)value.intValue());
+ return TByte.valueOf((byte) value.intValue());
}
}
diff --git a/teavm-classlib/src/main/java/org/teavm/classlib/java/lang/TCharacter.java b/teavm-classlib/src/main/java/org/teavm/classlib/java/lang/TCharacter.java
index 03fa1f083..35a406d14 100644
--- a/teavm-classlib/src/main/java/org/teavm/classlib/java/lang/TCharacter.java
+++ b/teavm-classlib/src/main/java/org/teavm/classlib/java/lang/TCharacter.java
@@ -133,7 +133,7 @@ public class TCharacter extends TObject implements TComparable {
if (this == other) {
return true;
}
- return other instanceof TCharacter && ((TCharacter)other).value == value;
+ return other instanceof TCharacter && ((TCharacter) other).value == value;
}
@Override
@@ -178,13 +178,13 @@ public class TCharacter extends TObject implements TComparable {
}
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));
@@ -224,15 +224,15 @@ public class TCharacter extends TObject implements TComparable {
public static char highSurrogate(int codePoint) {
codePoint -= MIN_SUPPLEMENTARY_CODE_POINT;
- return (char)(HIGH_SURROGATE_BITS | (codePoint >> MEANINGFUL_SURROGATE_BITS) & SURROGATE_BIT_INV_MASK);
+ return (char) (HIGH_SURROGATE_BITS | (codePoint >> MEANINGFUL_SURROGATE_BITS) & SURROGATE_BIT_INV_MASK);
}
public static char lowSurrogate(int codePoint) {
- return (char)(LOW_SURROGATE_BITS | codePoint & SURROGATE_BIT_INV_MASK);
+ return (char) (LOW_SURROGATE_BITS | codePoint & SURROGATE_BIT_INV_MASK);
}
public static char toLowerCase(char ch) {
- return (char)toLowerCase((int)ch);
+ return (char) toLowerCase((int) ch);
}
public static int toLowerCase(int ch) {
@@ -240,7 +240,7 @@ public class TCharacter extends TObject implements TComparable {
}
public static char toUpperCase(char ch) {
- return (char)toUpperCase((int)ch);
+ return (char) toUpperCase((int) ch);
}
public static int toUpperCase(int codePoint) {
@@ -248,7 +248,7 @@ public class TCharacter extends TObject implements TComparable {
}
public static int digit(char ch, int radix) {
- return digit((int)ch, radix);
+ return digit((int) ch, radix);
}
public static int digit(int codePoint, int radix) {
@@ -260,7 +260,7 @@ public class TCharacter extends TObject implements TComparable {
}
public static int getNumericValue(char ch) {
- return getNumericValue((int)ch);
+ return getNumericValue((int) ch);
}
public static int getNumericValue(int codePoint) {
@@ -285,11 +285,11 @@ public class TCharacter extends TObject implements TComparable {
if (radix < MIN_RADIX || radix > MAX_RADIX || digit >= radix) {
return '\0';
}
- return digit < 10 ? (char)('0' + digit) : (char)('a' + digit - 10);
+ return digit < 10 ? (char) ('0' + digit) : (char) ('a' + digit - 10);
}
public static boolean isDigit(char ch) {
- return isDigit((int)ch);
+ return isDigit((int) ch);
}
public static boolean isDigit(int codePoint) {
@@ -322,7 +322,7 @@ public class TCharacter extends TObject implements TComparable {
dst[dstIndex + 1] = lowSurrogate(codePoint);
return 2;
} else {
- dst[dstIndex] = (char)codePoint;
+ dst[dstIndex] = (char) codePoint;
return 1;
}
}
@@ -331,7 +331,7 @@ public class TCharacter extends TObject implements TComparable {
if (codePoint >= MIN_SUPPLEMENTARY_CODE_POINT) {
return new char[] { highSurrogate(codePoint), lowSurrogate(codePoint) };
} else {
- return new char[] { (char)codePoint };
+ return new char[] { (char) codePoint };
}
}
@@ -361,8 +361,8 @@ public class TCharacter extends TObject implements TComparable {
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++;
@@ -383,7 +383,7 @@ public class TCharacter extends TObject implements TComparable {
}
public static boolean isISOControl(char ch) {
- return isISOControl((int)ch);
+ return isISOControl((int) ch);
}
public static boolean isISOControl(int codePoint) {
@@ -391,11 +391,11 @@ public class TCharacter extends TObject implements TComparable {
}
public static int getType(char c) {
- return getType((int)c);
+ return getType((int) c);
}
public static int getType(int codePoint) {
- if (isBmpCodePoint(codePoint) && isSurrogate((char)codePoint)) {
+ if (isBmpCodePoint(codePoint) && isSurrogate((char) codePoint)) {
return SURROGATE;
}
UnicodeHelper.Range[] classes = getClasses();
@@ -416,7 +416,7 @@ public class TCharacter extends TObject implements TComparable {
}
public static boolean isLowerCase(char ch) {
- return isLowerCase((int)ch);
+ return isLowerCase((int) ch);
}
public static boolean isLowerCase(int codePoint) {
@@ -424,7 +424,7 @@ public class TCharacter extends TObject implements TComparable {
}
public static boolean isUpperCase(char ch) {
- return isUpperCase((int)ch);
+ return isUpperCase((int) ch);
}
public static boolean isUpperCase(int codePoint) {
@@ -432,7 +432,7 @@ public class TCharacter extends TObject implements TComparable {
}
public static boolean isTitleCase(char ch) {
- return isTitleCase((int)ch);
+ return isTitleCase((int) ch);
}
public static boolean isTitleCase(int codePoint) {
@@ -440,7 +440,7 @@ public class TCharacter extends TObject implements TComparable {
}
public static boolean isDefined(char ch) {
- return isDefined((int)ch);
+ return isDefined((int) ch);
}
public static boolean isDefined(int codePoint) {
@@ -448,7 +448,7 @@ public class TCharacter extends TObject implements TComparable {
}
public static boolean isLetter(char ch) {
- return isLetter((int)ch);
+ return isLetter((int) ch);
}
public static boolean isLetter(int codePoint) {
@@ -465,7 +465,7 @@ public class TCharacter extends TObject implements TComparable {
}
public static boolean isLetterOrDigit(char ch) {
- return isLetterOrDigit((int)ch);
+ return isLetterOrDigit((int) ch);
}
public static boolean isLetterOrDigit(int codePoint) {
@@ -488,7 +488,7 @@ public class TCharacter extends TObject implements TComparable {
}
public static boolean isJavaIdentifierStart(char ch) {
- return isJavaIdentifierStart((int)ch);
+ return isJavaIdentifierStart((int) ch);
}
public static boolean isJavaIdentifierStart(int codePoint) {
@@ -513,7 +513,7 @@ public class TCharacter extends TObject implements TComparable {
}
public static boolean isJavaIdentifierPart(char ch) {
- return isJavaIdentifierPart((int)ch);
+ return isJavaIdentifierPart((int) ch);
}
public static boolean isJavaIdentifierPart(int codePoint) {
@@ -550,7 +550,7 @@ public class TCharacter extends TObject implements TComparable {
}
public static boolean isUnicodeIdentifierStart(char ch) {
- return isUnicodeIdentifierStart((int)ch);
+ return isUnicodeIdentifierStart((int) ch);
}
public static boolean isUnicodeIdentifierStart(int codePoint) {
@@ -568,7 +568,7 @@ public class TCharacter extends TObject implements TComparable {
}
public static boolean isUnicodeIdentifierPart(char ch) {
- return isUnicodeIdentifierPart((int)ch);
+ return isUnicodeIdentifierPart((int) ch);
}
public static boolean isUnicodeIdentifierPart(int codePoint) {
@@ -590,12 +590,12 @@ public class TCharacter extends TObject implements TComparable {
}
public static boolean isIdentifierIgnorable(char ch) {
- return isIdentifierIgnorable((int)ch);
+ return isIdentifierIgnorable((int) ch);
}
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;
@@ -616,7 +616,7 @@ public class TCharacter extends TObject implements TComparable {
}
public static boolean isSpaceChar(char ch) {
- return isSpaceChar((int)ch);
+ return isSpaceChar((int) ch);
}
public static boolean isSpaceChar(int codePoint) {
@@ -631,7 +631,7 @@ public class TCharacter extends TObject implements TComparable {
}
public static boolean isWhitespace(char ch) {
- return isWhitespace((int)ch);
+ return isWhitespace((int) ch);
}
public static boolean isWhitespace(int codePoint) {
@@ -668,6 +668,6 @@ public class TCharacter extends TObject implements TComparable {
}
public static char reverseBytes(char ch) {
- return (char)((ch >> 8) | (ch << 8));
+ return (char) ((ch >> 8) | (ch << 8));
}
}
diff --git a/teavm-classlib/src/main/java/org/teavm/classlib/java/lang/TClass.java b/teavm-classlib/src/main/java/org/teavm/classlib/java/lang/TClass.java
index 4c6251fba..8aa91e7e5 100644
--- a/teavm-classlib/src/main/java/org/teavm/classlib/java/lang/TClass.java
+++ b/teavm-classlib/src/main/java/org/teavm/classlib/java/lang/TClass.java
@@ -49,7 +49,7 @@ public class TClass extends TObject implements TAnnotatedElement {
if (cls == null) {
return null;
}
- TClass> result = (TClass>)(Object)Platform.asJavaClass(cls.getJavaClass());
+ TClass> result = (TClass>) (Object) Platform.asJavaClass(cls.getJavaClass());
if (result == null) {
result = new TClass<>(cls);
}
@@ -122,47 +122,47 @@ public class TClass extends TObject implements TAnnotatedElement {
@SuppressWarnings("unchecked")
static TClass voidClass() {
- return (TClass)getClass(Platform.getPrimitives().getVoidClass());
+ return (TClass) getClass(Platform.getPrimitives().getVoidClass());
}
@SuppressWarnings("unchecked")
static TClass booleanClass() {
- return (TClass)getClass(Platform.getPrimitives().getBooleanClass());
+ return (TClass) getClass(Platform.getPrimitives().getBooleanClass());
}
@SuppressWarnings("unchecked")
static TClass charClass() {
- return (TClass)getClass(Platform.getPrimitives().getCharClass());
+ return (TClass) getClass(Platform.getPrimitives().getCharClass());
}
@SuppressWarnings("unchecked")
static TClass byteClass() {
- return (TClass)getClass(Platform.getPrimitives().getByteClass());
+ return (TClass) getClass(Platform.getPrimitives().getByteClass());
}
@SuppressWarnings("unchecked")
static TClass shortClass() {
- return (TClass)getClass(Platform.getPrimitives().getShortClass());
+ return (TClass) getClass(Platform.getPrimitives().getShortClass());
}
@SuppressWarnings("unchecked")
static TClass intClass() {
- return (TClass)getClass(Platform.getPrimitives().getIntClass());
+ return (TClass) getClass(Platform.getPrimitives().getIntClass());
}
@SuppressWarnings("unchecked")
static TClass longClass() {
- return (TClass)getClass(Platform.getPrimitives().getLongClass());
+ return (TClass) getClass(Platform.getPrimitives().getLongClass());
}
@SuppressWarnings("unchecked")
static TClass floatClass() {
- return (TClass)getClass(Platform.getPrimitives().getFloatClass());
+ return (TClass) getClass(Platform.getPrimitives().getFloatClass());
}
@SuppressWarnings("unchecked")
static TClass doubleClass() {
- return (TClass)getClass(Platform.getPrimitives().getDoubleClass());
+ return (TClass) getClass(Platform.getPrimitives().getDoubleClass());
}
public boolean desiredAssertionStatus() {
@@ -171,21 +171,21 @@ public class TClass extends TObject implements TAnnotatedElement {
@SuppressWarnings("unchecked")
public TClass super T> getSuperclass() {
- return (TClass super T>)getClass(platformClass.getMetadata().getSuperclass());
+ return (TClass super T>) getClass(platformClass.getMetadata().getSuperclass());
}
@SuppressWarnings("unchecked")
public T[] getEnumConstants() {
- return isEnum() ? (T[])Platform.getEnumConstants(platformClass) : null;
+ return isEnum() ? (T[]) Platform.getEnumConstants(platformClass) : null;
}
@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));
+ if (obj != null && !isAssignableFrom((TClass>) (Object) obj.getClass())) {
+ throw new TClassCastException(TString.wrap(obj.getClass().getName()
+ + " is not subtype of " + name));
}
- return (T)obj;
+ return (T) obj;
}
public TClassLoader getClassLoader() {
@@ -212,7 +212,7 @@ public class TClass extends TObject implements TAnnotatedElement {
if (instance == null) {
throw new TInstantiationException();
}
- return (T)instance;
+ return (T) instance;
}
public TClass> getDeclaringClass() {
@@ -228,7 +228,7 @@ public class TClass extends TObject implements TAnnotatedElement {
if (!clazz.isAssignableFrom(this)) {
throw new TClassCastException();
}
- return (TClass extends U>)this;
+ return (TClass extends U>) this;
}
@Override
@@ -241,13 +241,13 @@ public class TClass extends TObject implements TAnnotatedElement {
@Override
public S getAnnotation(TClass annotationClass) {
ensureAnnotationsByType();
- return (S)annotationsByType.get(annotationClass);
+ return (S) annotationsByType.get(annotationClass);
}
@Override
public TAnnotation[] getAnnotations() {
if (annotationsCache == null) {
- annotationsCache = (TAnnotation[])Platform.getAnnotations(getPlatformClass());
+ annotationsCache = (TAnnotation[]) Platform.getAnnotations(getPlatformClass());
}
return annotationsCache.clone();
}
@@ -263,7 +263,7 @@ public class TClass extends TObject implements TAnnotatedElement {
}
annotationsByType = new HashMap<>();
for (TAnnotation annot : getAnnotations()) {
- annotationsByType.put((TClass>)(Object)annot.annotationType(), annot);
+ annotationsByType.put((TClass>) (Object) annot.annotationType(), annot);
}
}
}
diff --git a/teavm-classlib/src/main/java/org/teavm/classlib/java/lang/TConsoleOutputStream_stderr.java b/teavm-classlib/src/main/java/org/teavm/classlib/java/lang/TConsoleOutputStreamStderr.java
similarity index 94%
rename from teavm-classlib/src/main/java/org/teavm/classlib/java/lang/TConsoleOutputStream_stderr.java
rename to teavm-classlib/src/main/java/org/teavm/classlib/java/lang/TConsoleOutputStreamStderr.java
index 09038fd60..269d3104d 100644
--- a/teavm-classlib/src/main/java/org/teavm/classlib/java/lang/TConsoleOutputStream_stderr.java
+++ b/teavm-classlib/src/main/java/org/teavm/classlib/java/lang/TConsoleOutputStreamStderr.java
@@ -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);
diff --git a/teavm-classlib/src/main/java/org/teavm/classlib/java/lang/TConsoleOutputStream_stdout.java b/teavm-classlib/src/main/java/org/teavm/classlib/java/lang/TConsoleOutputStreamStdout.java
similarity index 94%
rename from teavm-classlib/src/main/java/org/teavm/classlib/java/lang/TConsoleOutputStream_stdout.java
rename to teavm-classlib/src/main/java/org/teavm/classlib/java/lang/TConsoleOutputStreamStdout.java
index 4c816bfb4..769a2cf05 100644
--- a/teavm-classlib/src/main/java/org/teavm/classlib/java/lang/TConsoleOutputStream_stdout.java
+++ b/teavm-classlib/src/main/java/org/teavm/classlib/java/lang/TConsoleOutputStreamStdout.java
@@ -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);
diff --git a/teavm-classlib/src/main/java/org/teavm/classlib/java/lang/TDouble.java b/teavm-classlib/src/main/java/org/teavm/classlib/java/lang/TDouble.java
index 1062bdd76..00a822924 100644
--- a/teavm-classlib/src/main/java/org/teavm/classlib/java/lang/TDouble.java
+++ b/teavm-classlib/src/main/java/org/teavm/classlib/java/lang/TDouble.java
@@ -50,17 +50,17 @@ public class TDouble extends TNumber implements TComparable {
@Override
public int intValue() {
- return (int)value;
+ return (int) value;
}
@Override
public long longValue() {
- return (long)value;
+ return (long) value;
}
@Override
public float floatValue() {
- return (float)value;
+ return (float) value;
}
public static TDouble valueOf(double d) {
@@ -198,13 +198,13 @@ public class TDouble extends TNumber implements TComparable {
if (this == other) {
return true;
}
- return other instanceof TDouble && ((TDouble)other).value == value;
+ return other instanceof TDouble && ((TDouble) other).value == value;
}
@Override
public int hashCode() {
long h = doubleToLongBits(value);
- return (int)(h >>> 32) ^ ((int)h | 0);
+ return (int) (h >>> 32) ^ ((int) h | 0);
}
public static int compare(double a, double b) {
@@ -258,7 +258,7 @@ public class TDouble extends TNumber implements TComparable {
} else {
doubleMantissa = abs * 0x1p1022 * binaryExponent(negExp - 1022);
}
- long mantissa = (long)(doubleMantissa + 0.5) & 0xFFFFFFFFFFFFFL;
+ long mantissa = (long) (doubleMantissa + 0.5) & 0xFFFFFFFFFFFFFL;
return mantissa | ((exp + 1023L) << 52) | (value < 0 || 1 / value == NEGATIVE_INFINITY ? (1L << 63) : 0);
}
@@ -273,12 +273,12 @@ public class TDouble extends TNumber implements TComparable {
}
}
boolean negative = (bits & (1L << 63)) != 0;
- int rawExp = (int)((bits >> 52) & 0x7FFL);
+ int rawExp = (int) ((bits >> 52) & 0x7FFL);
long mantissa = bits & 0xFFFFFFFFFFFFFL;
if (rawExp == 0) {
mantissa <<= 1;
} else {
- mantissa |= (1L << 52);
+ mantissa |= 1L << 52;
}
double value = mantissa * binaryExponent(rawExp - 1023 - 52);
return !negative ? value : -value;
@@ -294,14 +294,14 @@ public class TDouble extends TNumber implements TComparable {
int sz = 0;
long bits = doubleToLongBits(d);
boolean subNormal = false;
- int exp = (int)((bits >>> 52) & 0x7FF) - 1023;
+ int exp = (int) ((bits >>> 52) & 0x7FF) - 1023;
long mantissa = bits & 0xFFFFFFFFFFFFFL;
if (exp == -1023) {
++exp;
subNormal = true;
}
for (int i = 0; i < 13; ++i) {
- int digit = (int)(mantissa & 0xF);
+ int digit = (int) (mantissa & 0xF);
if (digit > 0 || sz > 0) {
buffer[sz++] = TCharacter.forDigit(digit, 16);
}
diff --git a/teavm-classlib/src/main/java/org/teavm/classlib/java/lang/TEnum.java b/teavm-classlib/src/main/java/org/teavm/classlib/java/lang/TEnum.java
index df445cbfa..8738ee980 100644
--- a/teavm-classlib/src/main/java/org/teavm/classlib/java/lang/TEnum.java
+++ b/teavm-classlib/src/main/java/org/teavm/classlib/java/lang/TEnum.java
@@ -62,15 +62,14 @@ public abstract class TEnum> extends TObject implements TComp
@SuppressWarnings("unchecked")
public final TClass getDeclaringClass() {
- return (TClass)(Object)getClass();
+ return (TClass) (Object) getClass();
}
@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> 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"));
}
}
diff --git a/teavm-classlib/src/main/java/org/teavm/classlib/java/lang/TFloat.java b/teavm-classlib/src/main/java/org/teavm/classlib/java/lang/TFloat.java
index 916dcc159..571c66c77 100644
--- a/teavm-classlib/src/main/java/org/teavm/classlib/java/lang/TFloat.java
+++ b/teavm-classlib/src/main/java/org/teavm/classlib/java/lang/TFloat.java
@@ -39,7 +39,7 @@ public class TFloat extends TNumber implements TComparable {
}
public TFloat(double value) {
- this((float)value);
+ this((float) value);
}
public TFloat(TString value) throws TNumberFormatException {
@@ -48,12 +48,12 @@ public class TFloat extends TNumber implements TComparable {
@Override
public int intValue() {
- return (int)value;
+ return (int) value;
}
@Override
public long longValue() {
- return (long)value;
+ return (long) value;
}
@Override
@@ -84,7 +84,7 @@ public class TFloat extends TNumber implements TComparable {
if (this == other) {
return true;
}
- return other instanceof TFloat && ((TFloat)other).value == value;
+ return other instanceof TFloat && ((TFloat) other).value == value;
}
@Override
@@ -260,7 +260,7 @@ public class TFloat extends TNumber implements TComparable {
} else {
doubleMantissa = abs * 0x1p126f * binaryExponent(negExp - 126);
}
- int mantissa = (int)(doubleMantissa + 0.5f) & 0x7FFFFF;
+ int mantissa = (int) (doubleMantissa + 0.5f) & 0x7FFFFF;
return mantissa | ((exp + 127) << 23) | (value < 0 || 1 / value == NEGATIVE_INFINITY ? (1 << 31) : 0);
}
@@ -280,7 +280,7 @@ public class TFloat extends TNumber implements TComparable {
if (rawExp == 0) {
mantissa <<= 1;
} else {
- mantissa |= (1L << 23);
+ mantissa |= 1L << 23;
}
float value = mantissa * binaryExponent(rawExp - 127 - 23);
return !negative ? value : -value;
diff --git a/teavm-classlib/src/main/java/org/teavm/classlib/java/lang/TInteger.java b/teavm-classlib/src/main/java/org/teavm/classlib/java/lang/TInteger.java
index 144f696e2..5ff399c0f 100644
--- a/teavm-classlib/src/main/java/org/teavm/classlib/java/lang/TInteger.java
+++ b/teavm-classlib/src/main/java/org/teavm/classlib/java/lang/TInteger.java
@@ -86,8 +86,8 @@ public class TInteger extends TNumber implements TComparable {
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) {
@@ -164,7 +164,7 @@ public class TInteger extends TNumber implements TComparable {
if (this == other) {
return true;
}
- return other instanceof TInteger && ((TInteger)other).value == value;
+ return other instanceof TInteger && ((TInteger) other).value == value;
}
public static TInteger getInteger(TString nm) {
diff --git a/teavm-classlib/src/main/java/org/teavm/classlib/java/lang/TLong.java b/teavm-classlib/src/main/java/org/teavm/classlib/java/lang/TLong.java
index b5ae62169..d105ca31f 100644
--- a/teavm-classlib/src/main/java/org/teavm/classlib/java/lang/TLong.java
+++ b/teavm-classlib/src/main/java/org/teavm/classlib/java/lang/TLong.java
@@ -65,8 +65,8 @@ public class TLong extends TNumber implements TComparable {
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) {
@@ -155,7 +155,7 @@ public class TLong extends TNumber implements TComparable {
}
@Override
public int intValue() {
- return (int)value;
+ return (int) value;
}
@Override
@@ -211,7 +211,7 @@ public class TLong extends TNumber implements TComparable {
if (this == other) {
return true;
}
- return other instanceof TLong && ((TLong)other).value == value;
+ return other instanceof TLong && ((TLong) other).value == value;
}
@GeneratedBy(LongNativeGenerator.class)
@@ -315,7 +315,7 @@ public class TLong extends TNumber implements TComparable {
i = ((i & 0x0700070007000700L) >> 8) + (i & 0x0007000700070007L);
i = ((i & 0x000F0000000F0000L) >> 16) + (i & 0x0000000F0000000FL);
i = ((i & 0x0000001F00000000L) >> 32) + (i & 0x000000000000001FL);
- return (int)i;
+ return (int) i;
}
public static long rotateLeft(long i, int distance) {
@@ -346,6 +346,6 @@ public class TLong extends TNumber implements TComparable {
}
public static int signum(long i) {
- return (int)((i >> 63) | (-i >>> 63));
+ return (int) ((i >> 63) | (-i >>> 63));
}
}
diff --git a/teavm-classlib/src/main/java/org/teavm/classlib/java/lang/TMath.java b/teavm-classlib/src/main/java/org/teavm/classlib/java/lang/TMath.java
index dcbc6cefb..14b343a03 100644
--- a/teavm-classlib/src/main/java/org/teavm/classlib/java/lang/TMath.java
+++ b/teavm-classlib/src/main/java/org/teavm/classlib/java/lang/TMath.java
@@ -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() {
}
@@ -72,7 +72,7 @@ public final class TMath extends TObject {
}
public static double IEEEremainder(double f1, double f2) {
- int n = (int)(f1 / f2);
+ int n = (int) (f1 / f2);
return f1 - n * f2;
}
@@ -93,11 +93,11 @@ public final class TMath extends TObject {
public static native double atan2(double y, double x);
public static int round(float a) {
- return (int)(a + signum(a) * 0.5f);
+ return (int) (a + signum(a) * 0.5f);
}
public static long round(double a) {
- return (long)(a + signum(a) * 0.5);
+ return (long) (a + signum(a) * 0.5);
}
@GeneratedBy(MathNativeGenerator.class)
@@ -156,7 +156,7 @@ public final class TMath extends TObject {
}
public static float ulp(float d) {
- return (float)pow(2, getExponent(d) - 23);
+ return (float) pow(2, getExponent(d) - 23);
}
public static double signum(double d) {
diff --git a/teavm-classlib/src/main/java/org/teavm/classlib/java/lang/TNumber.java b/teavm-classlib/src/main/java/org/teavm/classlib/java/lang/TNumber.java
index 99b18f32f..380384b94 100644
--- a/teavm-classlib/src/main/java/org/teavm/classlib/java/lang/TNumber.java
+++ b/teavm-classlib/src/main/java/org/teavm/classlib/java/lang/TNumber.java
@@ -31,10 +31,10 @@ public abstract class TNumber extends TObject implements TSerializable {
public abstract double doubleValue();
public byte byteValue() {
- return (byte)intValue();
+ return (byte) intValue();
}
public short shortValue() {
- return (short)intValue();
+ return (short) intValue();
}
}
diff --git a/teavm-classlib/src/main/java/org/teavm/classlib/java/lang/TObject.java b/teavm-classlib/src/main/java/org/teavm/classlib/java/lang/TObject.java
index 366fbf6a5..55cb5bd76 100644
--- a/teavm-classlib/src/main/java/org/teavm/classlib/java/lang/TObject.java
+++ b/teavm-classlib/src/main/java/org/teavm/classlib/java/lang/TObject.java
@@ -238,7 +238,7 @@ public class TObject {
}
@Rename("wait")
- public final void wait0(long timeout) throws TInterruptedException{
+ public final void wait0(long timeout) throws TInterruptedException {
try {
wait(timeout, 0);
} catch (InterruptedException ex) {
@@ -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 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();
}
@@ -343,6 +343,6 @@ public class TObject {
}
public static TObject wrap(Object obj) {
- return (TObject)obj;
+ return (TObject) obj;
}
}
diff --git a/teavm-classlib/src/main/java/org/teavm/classlib/java/lang/TRuntime.java b/teavm-classlib/src/main/java/org/teavm/classlib/java/lang/TRuntime.java
index c1f514467..66375de9e 100644
--- a/teavm-classlib/src/main/java/org/teavm/classlib/java/lang/TRuntime.java
+++ b/teavm-classlib/src/main/java/org/teavm/classlib/java/lang/TRuntime.java
@@ -1,17 +1,17 @@
/*
- * 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.
- * You may obtain a copy of the License at
+ * 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
+ * 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.
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
*/
package org.teavm.classlib.java.lang;
@@ -35,7 +35,7 @@ public class TRuntime {
* Returns the amount of free memory in the system. Calling the gc method
* may result in increasing the value returned by freeMemory.
*/
- public long freeMemory(){
+ public long freeMemory() {
return Integer.MAX_VALUE;
}
diff --git a/teavm-classlib/src/main/java/org/teavm/classlib/java/lang/TShort.java b/teavm-classlib/src/main/java/org/teavm/classlib/java/lang/TShort.java
index 7920995e1..bbbf5e80a 100644
--- a/teavm-classlib/src/main/java/org/teavm/classlib/java/lang/TShort.java
+++ b/teavm-classlib/src/main/java/org/teavm/classlib/java/lang/TShort.java
@@ -74,7 +74,7 @@ public class TShort extends TNumber implements TComparable {
@Override
public boolean equals(Object other) {
- return other instanceof TShort && ((TShort)other).value == value;
+ return other instanceof TShort && ((TShort) other).value == value;
}
@Override
@@ -96,7 +96,7 @@ public class TShort extends TNumber implements TComparable {
if (value < MIN_VALUE || value > MAX_VALUE) {
throw new TNumberFormatException();
}
- return (short)value;
+ return (short) value;
}
public static short parseShort(TString s) throws TNumberFormatException {
@@ -116,10 +116,10 @@ public class TShort extends TNumber implements TComparable {
if (value < MIN_VALUE || value > MAX_VALUE) {
throw new TNumberFormatException();
}
- return valueOf((short)value);
+ return valueOf((short) value);
}
public static short reverseBytes(short i) {
- return (short)((i << 8) | (i >>> 8));
+ return (short) ((i << 8) | (i >>> 8));
}
}
diff --git a/teavm-classlib/src/main/java/org/teavm/classlib/java/lang/TStackTraceElement.java b/teavm-classlib/src/main/java/org/teavm/classlib/java/lang/TStackTraceElement.java
index 2ae62814a..bf609ee65 100644
--- a/teavm-classlib/src/main/java/org/teavm/classlib/java/lang/TStackTraceElement.java
+++ b/teavm-classlib/src/main/java/org/teavm/classlib/java/lang/TStackTraceElement.java
@@ -72,11 +72,11 @@ public final class TStackTraceElement extends TObject implements TSerializable {
if (!(obj instanceof TStackTraceElement)) {
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;
+ TStackTraceElement other = (TStackTraceElement) obj;
+ return TObjects.equals(declaringClass, other.declaringClass)
+ && TObjects.equals(methodName, other.methodName)
+ && TObjects.equals(fileName, other.fileName)
+ && lineNumber == other.lineNumber;
}
@Override
diff --git a/teavm-classlib/src/main/java/org/teavm/classlib/java/lang/TStrictMath.java b/teavm-classlib/src/main/java/org/teavm/classlib/java/lang/TStrictMath.java
index 6f564147a..4d5e76f4f 100644
--- a/teavm-classlib/src/main/java/org/teavm/classlib/java/lang/TStrictMath.java
+++ b/teavm-classlib/src/main/java/org/teavm/classlib/java/lang/TStrictMath.java
@@ -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() {
}
diff --git a/teavm-classlib/src/main/java/org/teavm/classlib/java/lang/TString.java b/teavm-classlib/src/main/java/org/teavm/classlib/java/lang/TString.java
index cec922c01..a65e3babf 100644
--- a/teavm-classlib/src/main/java/org/teavm/classlib/java/lang/TString.java
+++ b/teavm-classlib/src/main/java/org/teavm/classlib/java/lang/TString.java
@@ -96,7 +96,7 @@ public class TString extends TObject implements TSerializable, TComparable 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) {
@@ -286,7 +286,7 @@ public class TString extends TObject implements TSerializable, TComparable= 0; --i) {
if (characters[i] == bmpChar) {
return i;
@@ -458,7 +458,7 @@ public class TString extends TObject implements TSerializable, TComparable 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) {
@@ -52,7 +52,7 @@ public final class TSystem extends TObject {
}
if (srcType != targetType) {
if (!srcType.isPrimitive() && !targetType.isPrimitive()) {
- Object[] srcArray = (Object[])(Object)src;
+ Object[] srcArray = (Object[]) (Object) src;
int pos = srcPos;
for (int i = 0; i < length; ++i) {
Object elem = srcArray[pos++];
@@ -108,7 +108,7 @@ public final class TSystem extends TObject {
}
public static int identityHashCode(Object x) {
- return ((TObject)x).identity();
+ return ((TObject) x).identity();
}
public static TString lineSeparator() {
diff --git a/teavm-classlib/src/main/java/org/teavm/classlib/java/lang/TThread.java b/teavm-classlib/src/main/java/org/teavm/classlib/java/lang/TThread.java
index 52e97cd90..7d3c5c31d 100644
--- a/teavm-classlib/src/main/java/org/teavm/classlib/java/lang/TThread.java
+++ b/teavm-classlib/src/main/java/org/teavm/classlib/java/lang/TThread.java
@@ -27,13 +27,13 @@ import org.teavm.platform.async.AsyncCallback;
* @author Alexey Andreev
*/
public class TThread extends TObject implements TRunnable {
- private static Window window = (Window)JS.getGlobal();
+ private static Window window = (Window) JS.getGlobal();
private static TThread mainThread = new TThread(TString.wrap("main"));
private static TThread currentThread = mainThread;
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();
@@ -52,10 +52,10 @@ public class TThread extends TObject implements TRunnable {
}
public TThread(TRunnable target) {
- this(target, null );
+ this(target, null);
}
- public TThread(TRunnable target, TString name ) {
+ public TThread(TRunnable target, TString name) {
this.name = name;
this.target = target;
id = nextId++;
@@ -84,7 +84,7 @@ public class TThread extends TObject implements TRunnable {
currentThread.timeSliceStart = System.currentTimeMillis();
}
- static TThread getMainThread(){
+ static TThread getMainThread() {
return mainThread;
}
@@ -93,7 +93,7 @@ public class TThread extends TObject implements TRunnable {
if (target != null) {
target.run();
}
- synchronized(finishedLock) {
+ synchronized (finishedLock) {
finishedLock.notifyAll();
}
}
@@ -182,7 +182,7 @@ public class TThread extends TObject implements TRunnable {
private static void sleep(long millis, final AsyncCallback callback) {
final TThread current = currentThread();
- int intMillis = millis < Integer.MAX_VALUE ? (int)millis : Integer.MAX_VALUE;
+ int intMillis = millis < Integer.MAX_VALUE ? (int) millis : Integer.MAX_VALUE;
SleepHandler handler = new SleepHandler(current, callback);
handler.scheduleId = Platform.schedule(handler, intMillis);
current.interruptHandler = handler;
@@ -221,11 +221,11 @@ public class TThread extends TObject implements TRunnable {
}
}
- public final void setPriority(int newPriority){
+ public final void setPriority(int newPriority) {
this.priority = newPriority;
}
- public final int getPriority(){
+ public final int getPriority() {
return this.priority;
}
diff --git a/teavm-classlib/src/main/java/org/teavm/classlib/java/lang/reflect/AnnotationDependencyListener.java b/teavm-classlib/src/main/java/org/teavm/classlib/java/lang/reflect/AnnotationDependencyListener.java
index 9d201ef1b..e8df3d21f 100644
--- a/teavm-classlib/src/main/java/org/teavm/classlib/java/lang/reflect/AnnotationDependencyListener.java
+++ b/teavm-classlib/src/main/java/org/teavm/classlib/java/lang/reflect/AnnotationDependencyListener.java
@@ -134,18 +134,18 @@ public class AnnotationDependencyListener extends AbstractDependencyListener {
public void methodReached(DependencyAgent agent, MethodDependency method, CallLocation location) {
ValueType type = method.getMethod().getResultType();
while (type instanceof ValueType.Array) {
- type = ((ValueType.Array)type).getItemType();
+ type = ((ValueType.Array) type).getItemType();
}
if (type instanceof ValueType.Object) {
- String className = ((ValueType.Object)type).getClassName();
+ String className = ((ValueType.Object) type).getClassName();
ClassReader cls = agent.getClassSource().get(className);
if (cls != null && cls.hasModifier(ElementModifier.ANNOTATION)) {
agent.linkClass(className, location);
}
}
- 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()) {
@@ -259,7 +259,7 @@ public class AnnotationDependencyListener extends AbstractDependencyListener {
return pe.constant(value.getString());
case AnnotationValue.LIST: {
List list = value.getList();
- ValueType itemType = ((ValueType.Array)type).getItemType();
+ ValueType itemType = ((ValueType.Array) type).getItemType();
ValueEmitter array = pe.constructArray(itemType, list.size());
for (int i = 0; i < list.size(); ++i) {
array.unwrapArray(ArrayElementType.OBJECT).setElement(i,
diff --git a/teavm-classlib/src/main/java/org/teavm/classlib/java/math/TBigDecimal.java b/teavm-classlib/src/main/java/org/teavm/classlib/java/math/TBigDecimal.java
index b2d1fb0bb..e14fccc1e 100644
--- a/teavm-classlib/src/main/java/org/teavm/classlib/java/math/TBigDecimal.java
+++ b/teavm-classlib/src/main/java/org/teavm/classlib/java/math/TBigDecimal.java
@@ -1,12 +1,11 @@
/*
- * 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.
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * 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,
@@ -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, Seri
private static final double LOG10_2 = 0.3010299956639812;
/** The String
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 long
* (5^0,5^1,...,5^27
).
*/
- private static final TBigInteger FIVE_POW[];
+ private static final TBigInteger[] FIVE_POW;
/**
* An array with powers of ten that fit in the type long
* (10^0,10^1,...,10^18
).
*/
- private static final TBigInteger TEN_POW[];
+ private static final TBigInteger[] TEN_POW;
/**
* An array with powers of ten that fit in the type long
@@ -198,13 +196,13 @@ public class TBigDecimal extends Number implements Comparable, Seri
* An array with the first BigInteger
scaled by zero.
* ([0,0],[1,0],...,[10,0]
).
*/
- 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.
* (0*10^0, 0*10^1, ..., 0*10^10
).
*/
- 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 '0'
. */
private static final char[] CH_ZEROS = new char[100];
@@ -222,10 +220,10 @@ public class TBigDecimal extends Number implements Comparable, Seri
for (; i < CH_ZEROS.length; i++) {
CH_ZEROS[i] = '0';
}
- for(int j=0; j, Seri
* @see #precision()
* @see #inplaceRound(TMathContext)
*/
- private transient int precision = 0;
+ private transient int precision;
private TBigDecimal(long smallValue, int scale) {
this.smallValue = smallValue;
@@ -344,7 +342,7 @@ public class TBigDecimal extends Number implements Comparable, Seri
}
}
scale = offset - begin;
- bufLength +=scale;
+ bufLength += scale;
unscaledBuffer.append(in, begin, scale);
} else {
scale = 0;
@@ -363,8 +361,8 @@ public class TBigDecimal extends Number implements Comparable, Seri
// Accumulating all remaining digits
scaleString = String.valueOf(in, begin, last + 1 - begin);
// Checking if the scale is defined
- newScale = (long)scale - Integer.parseInt(scaleString);
- scale = (int)newScale;
+ newScale = (long) scale - Integer.parseInt(scaleString);
+ scale = (int) newScale;
if (newScale != scale) {
throw new NumberFormatException("Scale out of range.");
}
@@ -378,7 +376,7 @@ public class TBigDecimal extends Number implements Comparable, Seri
}
precision = unscaledBuffer.length() - counter;
if (unscaledBuffer.charAt(0) == '-') {
- precision --;
+ precision--;
}
}
@@ -516,7 +514,7 @@ public class TBigDecimal extends Number implements Comparable, Seri
long mantisa;
int trailingZeros;
// Extracting the exponent, note that the bias is 1023
- scale = 1075 - (int)((bits >> 52) & 0x7FFL);
+ scale = 1075 - (int) ((bits >> 52) & 0x7FFL);
// Extracting the 52 bits of the mantisa.
mantisa = scale == 1075 ? (bits & 0xFFFFFFFFFFFFFL) << 1 : (bits & 0xFFFFFFFFFFFFFL) | 0x10000000000000L;
if (mantisa == 0) {
@@ -530,13 +528,13 @@ public class TBigDecimal extends Number implements Comparable, Seri
scale -= trailingZeros;
}
// Calculating the new unscaled value and the new scale
- if((bits >> 63) != 0) {
+ if ((bits >> 63) != 0) {
mantisa = -mantisa;
}
int mantisaBits = bitLength(mantisa);
if (scale < 0) {
bitLength = mantisaBits == 0 ? 0 : mantisaBits - scale;
- if(bitLength < 64) {
+ if (bitLength < 64) {
smallValue = mantisa << (-scale);
} else {
intVal = TBigInteger.valueOf(mantisa).shiftLeft(-scale);
@@ -544,7 +542,7 @@ public class TBigDecimal extends Number implements Comparable, Seri
scale = 0;
} else if (scale > 0) {
// m * 2^e = (m * 5^(-e)) * 10^e
- if(scale < LONG_FIVE_POW.length && mantisaBits + LONG_FIVE_POW_BIT_LENGTH[scale] < 64) {
+ if (scale < LONG_FIVE_POW.length && mantisaBits + LONG_FIVE_POW_BIT_LENGTH[scale] < 64) {
smallValue = mantisa * LONG_FIVE_POW[scale];
bitLength = bitLength(smallValue);
} else {
@@ -667,7 +665,7 @@ public class TBigDecimal extends Number implements Comparable, Seri
* int value to be converted to a {@code BigDecimal} instance.
*/
public TBigDecimal(int val) {
- this(val,0);
+ this(val, 0);
}
/**
@@ -685,7 +683,7 @@ public class TBigDecimal extends Number implements Comparable, Seri
* within the given precision without rounding.
*/
public TBigDecimal(int val, TMathContext mc) {
- this(val,0);
+ this(val, 0);
inplaceRound(mc);
}
@@ -697,7 +695,7 @@ public class TBigDecimal extends Number implements Comparable, Seri
* long value to be converted to a {@code BigDecimal} instance.
*/
public TBigDecimal(long val) {
- this(val,0);
+ this(val, 0);
}
/**
@@ -756,9 +754,9 @@ public class TBigDecimal extends Number implements Comparable, Seri
*/
public static TBigDecimal valueOf(long unscaledVal) {
if ((unscaledVal >= 0) && (unscaledVal < BI_SCALED_BY_ZERO_LENGTH)) {
- return BI_SCALED_BY_ZERO[(int)unscaledVal];
+ return BI_SCALED_BY_ZERO[(int) unscaledVal];
}
- return new TBigDecimal(unscaledVal,0);
+ return new TBigDecimal(unscaledVal, 0);
}
/**
@@ -822,18 +820,19 @@ public class TBigDecimal extends Number implements Comparable, 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) {
+ 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) {
return valueOf(thisValue.smallValue + augend.smallValue * LONG_TEN_POW[diffScale], thisValue.scale);
}
return new TBigDecimal(thisValue.getUnscaledValue().add(
- TMultiplication.multiplyByTenPow(augend.getUnscaledValue(),diffScale)), thisValue.scale);
+ TMultiplication.multiplyByTenPow(augend.getUnscaledValue(), diffScale)), thisValue.scale);
}
/**
@@ -852,7 +851,7 @@ public class TBigDecimal extends Number implements Comparable, Seri
TBigDecimal larger; // operand with the largest unscaled value
TBigDecimal smaller; // operand with the smallest unscaled value
TBigInteger tempBI;
- long diffScale = (long)this.scale - augend.scale;
+ long diffScale = (long) this.scale - augend.scale;
int largerSignum;
// Some operand is zero or the precision is infinity
if ((augend.isZero()) || (this.isZero()) || (mc.getPrecision() == 0)) {
@@ -865,7 +864,7 @@ public class TBigDecimal extends Number implements Comparable, 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()) {
@@ -915,22 +914,23 @@ public class TBigDecimal extends Number implements Comparable, Seri
if (diffScale == 0) {
// case s1 = s2 : [u1 - u2 , s1]
if (Math.max(this.bitLength, subtrahend.bitLength) + 1 < 64) {
- return valueOf(this.smallValue - subtrahend.smallValue,this.scale);
+ return valueOf(this.smallValue - subtrahend.smallValue, this.scale);
}
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 ]
+ TMultiplication.multiplyByTenPow(subtrahend.getUnscaledValue(), diffScale)), this.scale);
+ } 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) {
- return valueOf(this.smallValue * LONG_TEN_POW[diffScale] - subtrahend.smallValue,subtrahend.scale);
+ 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)
.subtract(subtrahend.getUnscaledValue()), subtrahend.scale);
@@ -950,7 +950,7 @@ public class TBigDecimal extends Number implements Comparable, Seri
* if {@code subtrahend == null} or {@code mc == null}.
*/
public TBigDecimal subtract(TBigDecimal subtrahend, TMathContext mc) {
- long diffScale = subtrahend.scale - (long)this.scale;
+ long diffScale = subtrahend.scale - (long) this.scale;
int thisSignum;
TBigDecimal leftOperand; // it will be only the left operand (this)
TBigInteger tempBI;
@@ -992,15 +992,15 @@ public class TBigDecimal extends Number implements Comparable, Seri
* if {@code multiplicand == null}.
*/
public TBigDecimal multiply(TBigDecimal multiplicand) {
- long newScale = (long)this.scale + multiplicand.scale;
+ long newScale = (long) this.scale + multiplicand.scale;
if (isZero() || multiplicand.isZero()) {
return zeroScaledBy(newScale);
}
/* Let be: this = [u1,s1] and multiplicand = [u2,s2] so:
* this x multiplicand = [ s1 * s2 , s1 + s2 ] */
- if(this.bitLength + multiplicand.bitLength < 64) {
- return valueOf(this.smallValue*multiplicand.smallValue, toIntScale(newScale));
+ if (this.bitLength + multiplicand.bitLength < 64) {
+ return valueOf(this.smallValue * multiplicand.smallValue, toIntScale(newScale));
}
return new TBigDecimal(this.getUnscaledValue().multiply(
multiplicand.getUnscaledValue()), toIntScale(newScale));
@@ -1086,22 +1086,22 @@ public class TBigDecimal extends Number implements Comparable, Seri
throw new ArithmeticException("Division by zero");
}
- long diffScale = ((long)this.scale - divisor.scale) - scale;
- if(this.bitLength < 64 && divisor.bitLength < 64 ) {
- if(diffScale == 0) {
+ long diffScale = ((long) this.scale - divisor.scale) - scale;
+ if (this.bitLength < 64 && divisor.bitLength < 64) {
+ 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) {
+ } else if (diffScale > 0) {
+ 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],
+ 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) {
- return dividePrimitiveLongs(this.smallValue*LONG_TEN_POW[(int)-diffScale],
+ 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);
}
}
@@ -1111,10 +1111,10 @@ public class TBigDecimal extends Number implements Comparable, Seri
if (diffScale > 0) {
// Multiply 'u2' by: 10^((s1 - s2) - scale)
- scaledDivisor = TMultiplication.multiplyByTenPow(scaledDivisor, (int)diffScale);
+ scaledDivisor = TMultiplication.multiplyByTenPow(scaledDivisor, (int) diffScale);
} else if (diffScale < 0) {
// Multiply 'u1' by: 10^(scale - (s1 - s2))
- scaledDividend = TMultiplication.multiplyByTenPow(scaledDividend, (int)-diffScale);
+ scaledDividend = TMultiplication.multiplyByTenPow(scaledDividend, (int) -diffScale);
}
return divideBigIntegers(scaledDividend, scaledDivisor, scale, roundingMode);
}
@@ -1130,10 +1130,11 @@ public class TBigDecimal extends Number implements Comparable, 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));
+ compRem = longCompareTo(Math.abs(rem) << 1, Math.abs(divisor));
// To look if there is a carry
compRem = roundingBehavior(quotient.testBit(0) ? 1 : 0,
sign * (5 + compRem), roundingMode);
@@ -1144,8 +1145,8 @@ public class TBigDecimal extends Number implements Comparable, Seri
compRem = roundingBehavior(quotient.testBit(0) ? 1 : 0, sign * (5 + compRem), roundingMode);
}
if (compRem != 0) {
- if(quotient.bitLength() < 63) {
- return valueOf(quotient.longValue() + compRem,scale);
+ if (quotient.bitLength() < 63) {
+ return valueOf(quotient.longValue() + compRem, scale);
}
quotient = quotient.add(TBigInteger.valueOf(compRem));
return new TBigDecimal(quotient, scale);
@@ -1158,13 +1159,13 @@ public class TBigDecimal extends Number implements Comparable, Seri
TRoundingMode roundingMode) {
long quotient = scaledDividend / scaledDivisor;
long remainder = scaledDividend % scaledDivisor;
- int sign = Long.signum( scaledDividend ) * Long.signum(scaledDivisor);
+ int sign = Long.signum(scaledDividend) * Long.signum(scaledDivisor);
if (remainder != 0) {
// Checking if: remainder * 2 >= scaledDivisor
int compRem; // 'compare to remainder'
compRem = longCompareTo(Math.abs(remainder) << 1, Math.abs(scaledDivisor));
// To look if there is a carry
- quotient += roundingBehavior(((int)quotient) & 1, sign * (5 + compRem), roundingMode);
+ quotient += roundingBehavior(((int) quotient) & 1, sign * (5 + compRem), roundingMode);
}
// Constructing the result with the appropriate unscaled value
return valueOf(quotient, scale);
@@ -1241,8 +1242,8 @@ public class TBigDecimal extends Number implements Comparable, Seri
TBigInteger p = this.getUnscaledValue();
TBigInteger q = divisor.getUnscaledValue();
TBigInteger gcd; // greatest common divisor between 'p' and 'q'
- TBigInteger quotAndRem[];
- long diffScale = (long)scale - divisor.scale;
+ TBigInteger[] quotAndRem;
+ long diffScale = (long) scale - divisor.scale;
int newScale; // the new scale for final quotient
int k; // number of factors "2" in 'q'
int l = 0; // number of factors "5" in 'q'
@@ -1319,13 +1320,13 @@ public class TBigDecimal extends Number implements Comparable, Seri
/* Calculating how many zeros must be append to 'dividend'
* to obtain a quotient with at least 'mc.precision()' digits */
long traillingZeros = mc.getPrecision() + 2L + divisor.aproxPrecision() - aproxPrecision();
- long diffScale = (long)scale - divisor.scale;
+ long diffScale = (long) scale - divisor.scale;
long newScale = diffScale; // scale of the final quotient
int compRem; // to compare the remainder
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())) {
@@ -1333,15 +1334,15 @@ public class TBigDecimal extends Number implements Comparable, Seri
}
if (traillingZeros > 0) {
// To append trailing zeros at end of dividend
- quotAndRem[0] = getUnscaledValue().multiply( TMultiplication.powerOf10(traillingZeros) );
+ quotAndRem[0] = getUnscaledValue().multiply(TMultiplication.powerOf10(traillingZeros));
newScale += traillingZeros;
}
- quotAndRem = quotAndRem[0].divideAndRemainder( divisor.getUnscaledValue() );
+ quotAndRem = quotAndRem[0].divideAndRemainder(divisor.getUnscaledValue());
integerQuot = quotAndRem[0];
// Calculating the exact quotient with at least 'mc.precision()' digits
if (quotAndRem[1].signum() != 0) {
// Checking if: 2 * remainder >= divisor ?
- compRem = quotAndRem[1].shiftLeftOneBit().compareTo( divisor.getUnscaledValue() );
+ compRem = quotAndRem[1].shiftLeftOneBit().compareTo(divisor.getUnscaledValue());
// quot := quot * 10 + r; with 'r' in {-6,-5,-4, 0,+4,+5,+6}
integerQuot = integerQuot.multiply(TBigInteger.TEN)
.add(TBigInteger.valueOf(quotAndRem[0].signum() * (5 + compRem)));
@@ -1385,8 +1386,8 @@ public class TBigDecimal extends Number implements Comparable, Seri
public TBigDecimal divideToIntegralValue(TBigDecimal divisor) {
TBigInteger integralValue; // the integer of result
TBigInteger powerOfTen; // some power of ten
- TBigInteger quotAndRem[] = {getUnscaledValue()};
- long newScale = (long)this.scale - divisor.scale;
+ TBigInteger[] quotAndRem = {getUnscaledValue()};
+ long newScale = (long) this.scale - divisor.scale;
long tempScale = 0;
int i = 1;
int lastPow = TEN_POW.length - 1;
@@ -1395,19 +1396,20 @@ public class TBigDecimal extends Number implements Comparable, Seri
throw new ArithmeticException("Division by zero");
}
if ((divisor.aproxPrecision() + newScale > this.aproxPrecision() + 1L)
- || (this.isZero())) {
+ || (this.isZero())) {
/* If the divisor's integer part is greater than this's integer part,
* the result must be zero with the appropriate scale */
integralValue = TBigInteger.ZERO;
} else if (newScale == 0) {
- integralValue = getUnscaledValue().divide( divisor.getUnscaledValue() );
+ integralValue = getUnscaledValue().divide(divisor.getUnscaledValue());
} else if (newScale > 0) {
powerOfTen = TMultiplication.powerOf10(newScale);
- integralValue = getUnscaledValue().divide( divisor.getUnscaledValue().multiply(powerOfTen) );
+ 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() );
+ integralValue = getUnscaledValue().multiply(powerOfTen).divide(divisor.getUnscaledValue());
// To strip trailing zeros approximating to the preferred scale
while (!integralValue.testBit(0)) {
quotAndRem = integralValue.divideAndRemainder(TEN_POW[i]);
@@ -1427,9 +1429,9 @@ public class TBigDecimal extends Number implements Comparable, Seri
}
newScale = tempScale;
}
- return ((integralValue.signum() == 0)
- ? zeroScaledBy(newScale)
- : new TBigDecimal(integralValue, toIntScale(newScale)));
+ return integralValue.signum() == 0
+ ? zeroScaledBy(newScale)
+ : new TBigDecimal(integralValue, toIntScale(newScale));
}
/**
@@ -1457,10 +1459,10 @@ public class TBigDecimal extends Number implements Comparable, Seri
int mcPrecision = mc.getPrecision();
int diffPrecision = this.precision() - divisor.precision();
int lastPow = TEN_POW.length - 1;
- long diffScale = (long)this.scale - divisor.scale;
+ 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);
@@ -1470,19 +1472,20 @@ public class TBigDecimal extends Number implements Comparable, Seri
quotAndRem[0] = TBigInteger.ZERO;
} else if (diffScale == 0) {
// CASE s1 == s2: to calculate u1 / u2
- quotAndRem[0] = this.getUnscaledValue().divide( divisor.getUnscaledValue() );
+ quotAndRem[0] = this.getUnscaledValue().divide(divisor.getUnscaledValue());
} else if (diffScale > 0) {
// CASE s1 >= s2: to calculate u1 / (u2 * 10^(s1-s2)
quotAndRem[0] = this.getUnscaledValue().divide(
- divisor.getUnscaledValue().multiply(TMultiplication.powerOf10(diffScale)) );
+ divisor.getUnscaledValue().multiply(TMultiplication.powerOf10(diffScale)));
// To chose 10^newScale to get a quotient with at least 'mc.precision()' digits
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));
+ long exp = Math.min(-diffScale, Math.max((long) mcPrecision - diffPrecision, 0));
long compRemDiv;
// Let be: (u1 * 10^exp) / u2 = [q,r]
quotAndRem = this.getUnscaledValue().multiply(TMultiplication.powerOf10(exp)).
@@ -1517,9 +1520,9 @@ public class TBigDecimal extends Number implements Comparable, 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)
- || (newScale - i >= diffScale)) ) {
+ if ((quotAndRem[1].signum() == 0)
+ && ((resultPrecision - i >= mcPrecision)
+ || (newScale - i >= diffScale))) {
resultPrecision -= i;
newScale -= i;
if (i < lastPow) {
@@ -1604,10 +1607,10 @@ public class TBigDecimal extends Number implements Comparable, 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) );
+ quotAndRem[1] = this.subtract(quotAndRem[0].multiply(divisor));
return quotAndRem;
}
@@ -1634,10 +1637,10 @@ public class TBigDecimal extends Number implements Comparable, 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) );
+ quotAndRem[1] = this.subtract(quotAndRem[0].multiply(divisor));
return quotAndRem;
}
@@ -1663,11 +1666,11 @@ public class TBigDecimal extends Number implements Comparable, Seri
if ((n < 0) || (n > 999999999)) {
throw new ArithmeticException("Invalid Operation");
}
- long newScale = scale * (long)n;
+ long newScale = scale * (long) n;
// Let be: this = [u,s] so: this^n = [u^n, s*n]
- return ((isZero())
- ? zeroScaledBy(newScale)
- : new TBigDecimal(getUnscaledValue().pow(n), toIntScale(newScale)));
+ return isZero()
+ ? zeroScaledBy(newScale)
+ : new TBigDecimal(getUnscaledValue().pow(n), toIntScale(newScale));
}
/**
@@ -1689,7 +1692,7 @@ public class TBigDecimal extends Number implements Comparable, Seri
// The ANSI standard X3.274-1996 algorithm
int m = Math.abs(n);
int mcPrecision = mc.getPrecision();
- int elength = (int)Math.log10(m) + 1; // decimal digits in 'n'
+ int elength = (int) Math.log10(m) + 1; // decimal digits in 'n'
int oneBitMask; // mask of bits
TBigDecimal accum; // the single accumulator
TMathContext newPrecision = mc; // MathContext by default
@@ -1698,13 +1701,11 @@ public class TBigDecimal extends Number implements Comparable, 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, Seri
* @return {@code abs(this)}
*/
public TBigDecimal abs() {
- return ((signum() < 0) ? negate() : this);
+ return signum() < 0 ? negate() : this;
}
/**
@@ -1756,8 +1757,8 @@ public class TBigDecimal extends Number implements Comparable, Seri
* @return {@code -this}
*/
public TBigDecimal negate() {
- if(bitLength < 63 || (bitLength == 63 && smallValue!=Long.MIN_VALUE)) {
- return valueOf(-smallValue,scale);
+ if (bitLength < 63 || (bitLength == 63 && smallValue != Long.MIN_VALUE)) {
+ return valueOf(-smallValue, scale);
}
return new TBigDecimal(getUnscaledValue().negate(), scale);
}
@@ -1803,8 +1804,8 @@ public class TBigDecimal extends Number implements Comparable, Seri
* {@code 0} if {@code this == 0},
* {@code 1} if {@code this > 0}. */
public int signum() {
- if( bitLength < 64) {
- return Long.signum( this.smallValue );
+ if (bitLength < 64) {
+ return Long.signum(this.smallValue);
}
return getUnscaledValue().signum();
}
@@ -1851,7 +1852,8 @@ public class TBigDecimal extends Number implements Comparable, 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;
@@ -1926,25 +1928,26 @@ public class TBigDecimal extends Number implements Comparable, Seri
if (roundingMode == null) {
throw new NullPointerException();
}
- long diffScale = newScale - (long)scale;
+ long diffScale = newScale - (long) scale;
// Let be: 'this' = [u,s]
- if(diffScale == 0) {
+ if (diffScale == 0) {
return this;
}
- 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 ) {
- return valueOf(this.smallValue*LONG_TEN_POW[(int)diffScale],newScale);
+ 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) {
+ return valueOf(this.smallValue * LONG_TEN_POW[(int) diffScale], newScale);
}
- return new TBigDecimal(TMultiplication.multiplyByTenPow(getUnscaledValue(),(int)diffScale), newScale);
+ return new TBigDecimal(TMultiplication.multiplyByTenPow(getUnscaledValue(), (int) diffScale), newScale);
}
// diffScale < 0
// return [u,s] / [1,newScale] with the appropriate scale and rounding
- if(this.bitLength < 64 && -diffScale < LONG_TEN_POW.length) {
- return dividePrimitiveLongs(this.smallValue, LONG_TEN_POW[(int)-diffScale], newScale,roundingMode);
+ 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);
}
/**
@@ -2010,7 +2013,7 @@ public class TBigDecimal extends Number implements Comparable, Seri
* @return {@code this * 10^(-n}).
*/
public TBigDecimal movePointLeft(int n) {
- return movePoint(scale + (long)n);
+ return movePoint(scale + (long) n);
}
private TBigDecimal movePoint(long newScale) {
@@ -2019,17 +2022,17 @@ public class TBigDecimal extends Number implements Comparable, Seri
}
/* When: 'n'== Integer.MIN_VALUE isn't possible to call to movePointRight(-n)
* since -Integer.MIN_VALUE == Integer.MIN_VALUE */
- if(newScale >= 0) {
- if(bitLength < 64) {
- return valueOf(smallValue,toIntScale(newScale));
+ if (newScale >= 0) {
+ if (bitLength < 64) {
+ return valueOf(smallValue, toIntScale(newScale));
}
return new TBigDecimal(getUnscaledValue(), toIntScale(newScale));
}
- if(-newScale < LONG_TEN_POW.length &&
- bitLength + LONG_TEN_POW_BIT_LENGTH[(int)-newScale] < 64 ) {
- return valueOf(smallValue*LONG_TEN_POW[(int)-newScale],0);
+ 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);
+ return new TBigDecimal(TMultiplication.multiplyByTenPow(getUnscaledValue(), (int) -newScale), 0);
}
/**
@@ -2049,7 +2052,7 @@ public class TBigDecimal extends Number implements Comparable, Seri
* @return {@code this * 10^n}.
*/
public TBigDecimal movePointRight(int n) {
- return movePoint(scale - (long)n);
+ return movePoint(scale - (long) n);
}
/**
@@ -2065,13 +2068,13 @@ public class TBigDecimal extends Number implements Comparable, Seri
* @return {@code this * 10^n}
*/
public TBigDecimal scaleByPowerOfTen(int n) {
- long newScale = scale - (long)n;
- if(bitLength < 64) {
+ long newScale = scale - (long) n;
+ if (bitLength < 64) {
//Taking care when a 0 is to be scaled
- if( smallValue==0 ){
- return zeroScaledBy( newScale );
+ if (smallValue == 0) {
+ return zeroScaledBy(newScale);
}
- return valueOf(smallValue,toIntScale(newScale));
+ return valueOf(smallValue, toIntScale(newScale));
}
return new TBigDecimal(getUnscaledValue(), toIntScale(newScale));
}
@@ -2142,20 +2145,22 @@ public class TBigDecimal extends Number implements Comparable, Seri
int thisSign = signum();
int valueSign = val.signum();
- if( thisSign == valueSign) {
- if(this.scale == val.scale && this.bitLength<64 && val.bitLength<64 ) {
+ if (thisSign == valueSign) {
+ if (this.scale == val.scale && this.bitLength < 64 && val.bitLength < 64) {
return (smallValue < val.smallValue) ? -1 : (smallValue > val.smallValue) ? 1 : 0;
}
- long diffScale = (long)this.scale - val.scale;
+ long diffScale = (long) this.scale - val.scale;
int diffPrecision = this.aproxPrecision() - val.aproxPrecision();
if (diffPrecision > diffScale + 1) {
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) {
@@ -2165,7 +2170,7 @@ public class TBigDecimal extends Number implements Comparable, Seri
}
} else if (thisSign < valueSign) {
return -1;
- } else {
+ } else {
return 1;
}
}
@@ -2207,7 +2212,7 @@ public class TBigDecimal extends Number implements Comparable, 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, Seri
* if {@code val == null}.
*/
public TBigDecimal max(TBigDecimal val) {
- return ((compareTo(val) >= 0) ? this : val);
+ return compareTo(val) >= 0 ? this : val;
}
/**
@@ -2234,8 +2239,8 @@ public class TBigDecimal extends Number implements Comparable, Seri
return hashCode;
}
if (bitLength < 64) {
- hashCode = (int)(smallValue & 0xffffffff);
- hashCode = 33 * hashCode + (int)((smallValue >> 32) & 0xffffffff);
+ hashCode = (int) (smallValue & 0xffffffff);
+ hashCode = 33 * hashCode + (int) ((smallValue >> 32) & 0xffffffff);
hashCode = 17 * hashCode + scale;
return hashCode;
}
@@ -2260,7 +2265,7 @@ public class TBigDecimal extends Number implements Comparable, Seri
return toStringImage;
}
if (bitLength < 32) {
- toStringImage = TConversion.toDecimalScaledString(smallValue,scale);
+ toStringImage = TConversion.toDecimalScaledString(smallValue, scale);
return toStringImage;
}
String intString = getUnscaledValue().toString();
@@ -2269,7 +2274,7 @@ public class TBigDecimal extends Number implements Comparable, Seri
}
int begin = (getUnscaledValue().signum() < 0) ? 2 : 1;
int end = intString.length();
- long exponent = -(long)scale + end - begin;
+ long exponent = -(long) scale + end - begin;
StringBuilder result = new StringBuilder();
result.append(intString);
@@ -2278,7 +2283,7 @@ public class TBigDecimal extends Number implements Comparable, Seri
result.insert(end - scale, '.');
} else {
result.insert(begin - 1, "0.");
- result.insert(begin + 1, CH_ZEROS, 0, -(int)exponent - 1);
+ result.insert(begin + 1, CH_ZEROS, 0, -(int) exponent - 1);
}
} else {
if (end - begin >= 1) {
@@ -2314,19 +2319,19 @@ public class TBigDecimal extends Number implements Comparable, Seri
}
int begin = (getUnscaledValue().signum() < 0) ? 2 : 1;
int end = intString.length();
- long exponent = -(long)scale + end - begin;
+ long exponent = -(long) scale + end - begin;
StringBuilder result = new StringBuilder(intString);
if ((scale > 0) && (exponent >= -6)) {
if (exponent >= 0) {
result.insert(end - scale, '.');
} else {
- result.insert(begin - 1, "0."); //$NON-NLS-1$
- result.insert(begin + 1, CH_ZEROS, 0, -(int)exponent - 1);
+ result.insert(begin - 1, "0.");
+ result.insert(begin + 1, CH_ZEROS, 0, -(int) exponent - 1);
}
} else {
int delta = end - begin;
- int rem = (int)(exponent % 3);
+ int rem = (int) (exponent % 3);
if (rem != 0) {
// adjust exponent so it is a multiple of three
@@ -2391,7 +2396,7 @@ public class TBigDecimal extends Number implements Comparable, 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, 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) {
@@ -2427,8 +2433,9 @@ public class TBigDecimal extends Number implements Comparable, Seri
if ((scale == 0) || (isZero())) {
return getUnscaledValue();
} else if (scale < 0) {
- return getUnscaledValue().multiply(TMultiplication.powerOf10(-(long)scale));
- } else {// (scale > 0)
+ return getUnscaledValue().multiply(TMultiplication.powerOf10(-(long) scale));
+ } else {
+ // (scale > 0)
return getUnscaledValue().divide(TMultiplication.powerOf10(scale));
}
}
@@ -2446,8 +2453,9 @@ public class TBigDecimal extends Number implements Comparable, Seri
if ((scale == 0) || (isZero())) {
return getUnscaledValue();
} else if (scale < 0) {
- return getUnscaledValue().multiply(TMultiplication.powerOf10(-(long)scale));
- } else {// (scale > 0)
+ return getUnscaledValue().multiply(TMultiplication.powerOf10(-(long) scale));
+ } 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, 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, 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();
}
/**
@@ -2517,7 +2521,7 @@ public class TBigDecimal extends Number implements Comparable, Seri
* if rounding is necessary or the number doesn't fit in a int.
*/
public int intValueExact() {
- return (int)valueExact(32);
+ return (int) valueExact(32);
}
/**
@@ -2531,7 +2535,7 @@ public class TBigDecimal extends Number implements Comparable, Seri
* short.
*/
public short shortValueExact() {
- return (short)valueExact(16);
+ return (short) valueExact(16);
}
/**
@@ -2544,7 +2548,7 @@ public class TBigDecimal extends Number implements Comparable, Seri
* if rounding is necessary or the number doesn't fit in a byte.
*/
public byte byteValueExact() {
- return (byte)valueExact(8);
+ return (byte) valueExact(8);
}
/**
@@ -2570,7 +2574,7 @@ public class TBigDecimal extends Number implements Comparable, Seri
/* A similar code like in doubleValue() could be repeated here,
* but this simple implementation is quite efficient. */
float floatResult = signum();
- long powerOfTwo = this.bitLength - (long)(scale / LOG10_2);
+ long powerOfTwo = this.bitLength - (long) (scale / LOG10_2);
if ((powerOfTwo < -149) || (floatResult == 0.0f)) {
// Cases which 'this' is very small
floatResult *= 0.0f;
@@ -2578,7 +2582,7 @@ public class TBigDecimal extends Number implements Comparable, Seri
// Cases which 'this' is very large
floatResult *= Float.POSITIVE_INFINITY;
} else {
- floatResult = (float)doubleValue();
+ floatResult = (float) doubleValue();
}
return floatResult;
}
@@ -2608,27 +2612,28 @@ public class TBigDecimal extends Number implements Comparable, Seri
int exponent = 1076; // bias + 53
int lowestSetBit;
int discardedSize;
- long powerOfTwo = this.bitLength - (long)(scale / LOG10_2);
+ long powerOfTwo = this.bitLength - (long) (scale / LOG10_2);
long bits; // IEEE-754 Standard
long tempBits; // for temporal calculations
TBigInteger mantisa;
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 k = 100 - (int) powerOfTwo;
int compRem;
if (k > 0) {
@@ -2642,13 +2647,13 @@ public class TBigDecimal extends Number implements Comparable, 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, 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, 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))) {
@@ -2698,7 +2708,7 @@ public class TBigDecimal extends Number implements Comparable, Seri
bits >>= 1;
}
// Construct the 64 double bits: [sign(1), exponent(11), mantisa(52)]
- bits = (sign & 0x8000000000000000L) | ((long)exponent << 52) | (bits & 0xFFFFFFFFFFFFFL);
+ bits = (sign & 0x8000000000000000L) | ((long) exponent << 52) | (bits & 0xFFFFFFFFFFFFFL);
return Double.longBitsToDouble(bits);
}
@@ -2739,7 +2749,7 @@ public class TBigDecimal extends Number implements Comparable, 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
@@ -2750,15 +2760,15 @@ public class TBigDecimal extends Number implements Comparable, Seri
// Getting the integer part and the discarded fraction
TBigInteger sizeOfFraction = TMultiplication.powerOf10(discardedPrecision);
TBigInteger[] integerAndFraction = getUnscaledValue().divideAndRemainder(sizeOfFraction);
- long newScale = (long)scale - discardedPrecision;
+ long newScale = (long) scale - discardedPrecision;
int compRem;
TBigDecimal tempBD;
// 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,
+ compRem = roundingBehavior(integerAndFraction[0].testBit(0) ? 1 : 0,
integerAndFraction[1].signum() * (5 + compRem),
mc.getRoundingMode());
if (compRem != 0) {
@@ -2792,7 +2802,7 @@ public class TBigDecimal extends Number implements Comparable, Seri
*/
private void smallRound(TMathContext mc, int discardedPrecision) {
long sizeOfFraction = LONG_TEN_POW[discardedPrecision];
- long newScale = (long)scale - discardedPrecision;
+ long newScale = (long) scale - discardedPrecision;
long unscaledVal = smallValue;
// Getting the integer part and the discarded fraction
long integer = unscaledVal / sizeOfFraction;
@@ -2801,9 +2811,9 @@ public class TBigDecimal extends Number implements Comparable, Seri
// If the discarded fraction is non-zero perform rounding
if (fraction != 0) {
// To check if the discarded fraction >= 0.5
- compRem = longCompareTo(Math.abs(fraction) << 1,sizeOfFraction);
+ compRem = longCompareTo(Math.abs(fraction) << 1, sizeOfFraction);
// To look if there is a carry
- integer += roundingBehavior( ((int)integer) & 1,
+ integer += roundingBehavior(((int) integer) & 1,
Long.signum(fraction) * (5 + compRem),
mc.getRoundingMode());
// If after to add the increment the precision changed, we normalize the size
@@ -2928,7 +2938,7 @@ public class TBigDecimal extends Number implements Comparable, Seri
} else if (longScale > Integer.MAX_VALUE) {
throw new ArithmeticException("Underflow");
} else {
- return (int)longScale;
+ return (int) longScale;
}
}
@@ -2947,16 +2957,16 @@ public class TBigDecimal extends Number implements Comparable, Seri
*/
private static TBigDecimal zeroScaledBy(long longScale) {
if (longScale == (int) longScale) {
- return valueOf(0,(int)longScale);
- }
- if (longScale >= 0) {
- return new TBigDecimal( 0, Integer.MAX_VALUE);
+ return valueOf(0, (int) longScale);
}
- return new TBigDecimal( 0, Integer.MIN_VALUE);
+ if (longScale >= 0) {
+ return new TBigDecimal(0, Integer.MAX_VALUE);
+ }
+ return new TBigDecimal(0, Integer.MIN_VALUE);
}
private TBigInteger getUnscaledValue() {
- if(intVal == null) {
+ if (intVal == null) {
intVal = TBigInteger.valueOf(smallValue);
}
return intVal;
@@ -2965,20 +2975,20 @@ public class TBigDecimal extends Number implements Comparable, Seri
private void setUnscaledValue(TBigInteger unscaledValue) {
this.intVal = unscaledValue;
this.bitLength = unscaledValue.bitLength();
- if(this.bitLength < 64) {
+ if (this.bitLength < 64) {
this.smallValue = unscaledValue.longValue();
}
}
private static int bitLength(long smallValue) {
- if(smallValue < 0) {
+ if (smallValue < 0) {
smallValue = ~smallValue;
}
return 64 - Long.numberOfLeadingZeros(smallValue);
}
private static int bitLength(int smallValue) {
- if(smallValue < 0) {
+ if (smallValue < 0) {
smallValue = ~smallValue;
}
return 32 - Integer.numberOfLeadingZeros(smallValue);
diff --git a/teavm-classlib/src/main/java/org/teavm/classlib/java/math/TBigInteger.java b/teavm-classlib/src/main/java/org/teavm/classlib/java/math/TBigInteger.java
index c0121f4bb..def328152 100644
--- a/teavm-classlib/src/main/java/org/teavm/classlib/java/math/TBigInteger.java
+++ b/teavm-classlib/src/main/java/org/teavm/classlib/java/math/TBigInteger.java
@@ -1,12 +1,11 @@
/*
- * 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.
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * 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,
@@ -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, 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, 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
@@ -325,10 +323,10 @@ public class TBigInteger extends Number implements Comparable, Seri
if ((val & 0xFFFFFFFF00000000L) == 0) {
// It fits in one 'int'
numberLength = 1;
- digits = new int[] { (int)val };
+ digits = new int[] { (int) val };
} else {
numberLength = 2;
- digits = new int[] { (int)val, (int)(val >> 32) };
+ digits = new int[] { (int) val, (int) (val >> 32) };
}
}
@@ -342,7 +340,7 @@ public class TBigInteger extends Number implements Comparable, 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;
@@ -362,8 +360,9 @@ public class TBigInteger extends Number implements Comparable, Seri
}
return MINUS_ONE;
} else if (val <= 10) {
- return SMALL_VALUES[(int)val];
- } else {// (val > 10)
+ return SMALL_VALUES[(int) val];
+ } else {
+ // (val > 10)
return new TBigInteger(1, val);
}
}
@@ -395,7 +394,7 @@ public class TBigInteger extends Number implements Comparable, Seri
int hB;
if (bytesLen - (numberLength << 2) == 1) {
- bytes[0] = (byte)((sign < 0) ? -1 : 0);
+ bytes[0] = (byte) ((sign < 0) ? -1 : 0);
highBytes = 4;
firstByteNumber++;
} else {
@@ -413,7 +412,7 @@ public class TBigInteger extends Number implements Comparable, Seri
bytesInInteger = highBytes;
}
for (int i = 0; i < bytesInInteger; i++, digit >>= 8) {
- bytes[--bytesLen] = (byte)digit;
+ bytes[--bytesLen] = (byte) digit;
}
while (bytesLen > firstByteNumber) {
digit = ~temp.digits[digitIndex];
@@ -422,7 +421,7 @@ public class TBigInteger extends Number implements Comparable, Seri
bytesInInteger = highBytes;
}
for (int i = 0; i < bytesInInteger; i++, digit >>= 8) {
- bytes[--bytesLen] = (byte)digit;
+ bytes[--bytesLen] = (byte) digit;
}
}
} else {
@@ -433,7 +432,7 @@ public class TBigInteger extends Number implements Comparable, Seri
bytesInInteger = highBytes;
}
for (int i = 0; i < bytesInInteger; i++, digit >>= 8) {
- bytes[--bytesLen] = (byte)digit;
+ bytes[--bytesLen] = (byte) digit;
}
}
}
@@ -480,8 +479,8 @@ public class TBigInteger extends Number implements Comparable, 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, 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, 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, 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, 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, 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, Seri
digit = ~digit;
}
}
- return ((digit & n) != 0);
+ return (digit & n) != 0;
}
/**
@@ -730,7 +729,7 @@ public class TBigInteger extends Number implements Comparable, 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, Seri
*/
@Override
public int intValue() {
- return (sign * digits[0]);
+ return sign * digits[0];
}
/**
@@ -851,9 +850,9 @@ public class TBigInteger extends Number implements Comparable, Seri
*/
@Override
public long longValue() {
- long value = (numberLength > 1) ? (((long)digits[1]) << 32) | (digits[0] & 0xFFFFFFFFL)
+ long value = (numberLength > 1) ? (((long) digits[1]) << 32) | (digits[0] & 0xFFFFFFFFL)
: (digits[0] & 0xFFFFFFFFL);
- return (sign * value);
+ return sign * value;
}
/**
@@ -868,7 +867,7 @@ public class TBigInteger extends Number implements Comparable, Seri
*/
@Override
public float floatValue() {
- return (float)doubleValue();
+ return (float) doubleValue();
}
/**
@@ -913,7 +912,7 @@ public class TBigInteger extends Number implements Comparable, 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, 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, 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, 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;
@@ -974,7 +973,7 @@ public class TBigInteger extends Number implements Comparable, Seri
return true;
}
if (x instanceof TBigInteger) {
- TBigInteger x1 = (TBigInteger)x;
+ TBigInteger x1 = (TBigInteger) x;
return sign == x1.sign && numberLength == x1.numberLength && equalsArrays(x1.digits);
}
return false;
@@ -1038,8 +1037,8 @@ public class TBigInteger extends Number implements Comparable, 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, 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, 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, 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, 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, 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, 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, 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, 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, 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);
}
diff --git a/teavm-classlib/src/main/java/org/teavm/classlib/java/math/TBitLevel.java b/teavm-classlib/src/main/java/org/teavm/classlib/java/math/TBitLevel.java
index 653ba3409..9ede7ebf8 100644
--- a/teavm-classlib/src/main/java/org/teavm/classlib/java/math/TBitLevel.java
+++ b/teavm-classlib/src/main/java/org/teavm/classlib/java/math/TBitLevel.java
@@ -1,12 +1,11 @@
/*
- * 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.
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * 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,
@@ -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);
diff --git a/teavm-classlib/src/main/java/org/teavm/classlib/java/math/TConversion.java b/teavm-classlib/src/main/java/org/teavm/classlib/java/math/TConversion.java
index 2018b5e5d..988b2d86a 100644
--- a/teavm-classlib/src/main/java/org/teavm/classlib/java/math/TConversion.java
+++ b/teavm-classlib/src/main/java/org/teavm/classlib/java/math/TConversion.java
@@ -1,12 +1,11 @@
/*
- * 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.
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * 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,
@@ -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 radixdigitFitInInt[radix]
@@ -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,9 +283,9 @@ class TConversion {
static String toDecimalScaledString(long value, int scale) {
int resLengthInChars;
int currentChar;
- char result[];
+ char[] result;
boolean negNumber = value < 0;
- if(negNumber) {
+ if (negNumber) {
value = -value;
}
if (value == 0) {
@@ -313,7 +314,7 @@ class TConversion {
// +1 - one char for sign if needed.
// +7 - For "special case 2" (see below) we have 7 free chars for
// inserting necessary scaled digits.
- result = new char[resLengthInChars+1];
+ result = new char[resLengthInChars + 1];
// Allocated [resLengthInChars+1] characters.
// a free latest character may be used for "special case 1" (see below)
currentChar = resLengthInChars;
@@ -324,7 +325,7 @@ class TConversion {
result[--currentChar] = (char) (0x0030 + (prev - v * 10));
} while (v != 0);
- long exponent = (long)resLengthInChars - (long)currentChar - scale - 1L;
+ long exponent = (long) resLengthInChars - (long) currentChar - scale - 1L;
if (scale == 0) {
if (negNumber) {
result[--currentChar] = '-';
@@ -334,8 +335,8 @@ class TConversion {
if (scale > 0 && exponent >= -6) {
if (exponent >= 0) {
// special case 1
- int insertPoint = currentChar + (int)exponent;
- for(int j = resLengthInChars - 1; j >= insertPoint; j--) {
+ int insertPoint = currentChar + (int) exponent;
+ for (int j = resLengthInChars - 1; j >= insertPoint; j--) {
result[j + 1] = result[j];
}
result[++insertPoint] = '.';
@@ -364,7 +365,7 @@ class TConversion {
if (endPoint - startPoint >= 1) {
result1.append(result[currentChar]);
result1.append('.');
- result1.append(result, currentChar+1, resLengthInChars - currentChar-1);
+ result1.append(result, currentChar + 1, resLengthInChars - currentChar - 1);
} else {
result1.append(result, currentChar, resLengthInChars - currentChar);
}
@@ -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
diff --git a/teavm-classlib/src/main/java/org/teavm/classlib/java/math/TDivision.java b/teavm-classlib/src/main/java/org/teavm/classlib/java/math/TDivision.java
index 5662b4e6d..7acd3472b 100644
--- a/teavm-classlib/src/main/java/org/teavm/classlib/java/math/TDivision.java
+++ b/teavm-classlib/src/main/java/org/teavm/classlib/java/math/TDivision.java
@@ -1,12 +1,11 @@
/*
- * 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.
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * 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,
@@ -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;
*
*/
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;
diff --git a/teavm-classlib/src/main/java/org/teavm/classlib/java/math/TElementary.java b/teavm-classlib/src/main/java/org/teavm/classlib/java/math/TElementary.java
index 2b99855c1..08c79a326 100644
--- a/teavm-classlib/src/main/java/org/teavm/classlib/java/math/TElementary.java
+++ b/teavm-classlib/src/main/java/org/teavm/classlib/java/math/TElementary.java
@@ -1,12 +1,11 @@
/*
- * 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.
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * 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,
@@ -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);
}
}
-
}
diff --git a/teavm-classlib/src/main/java/org/teavm/classlib/java/math/TLogical.java b/teavm-classlib/src/main/java/org/teavm/classlib/java/math/TLogical.java
index 1096f2eb1..18374a618 100644
--- a/teavm-classlib/src/main/java/org/teavm/classlib/java/math/TLogical.java
+++ b/teavm-classlib/src/main/java/org/teavm/classlib/java/math/TLogical.java
@@ -1,12 +1,11 @@
/*
- * 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.
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * 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,
@@ -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;
@@ -83,7 +83,7 @@ class TLogical {
if (that.sign == 0 || val.sign == 0) {
return TBigInteger.ZERO;
}
- if (that.equals(TBigInteger.MINUS_ONE)){
+ if (that.equals(TBigInteger.MINUS_ONE)) {
return val;
}
if (val.equals(TBigInteger.MINUS_ONE)) {
@@ -117,8 +117,8 @@ class TLogical {
return TBigInteger.ZERO;
}
- int resDigits[] = new int[resLength];
- for ( ; i < resLength; i++) {
+ 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);
@@ -148,13 +148,13 @@ class TLogical {
i++;
}
int limit = Math.min(negative.numberLength, positive.numberLength);
- for ( ; i < limit; i++) {
+ for (; i < limit; i++) {
resDigits[i] = ~negative.digits[i] & positive.digits[i];
}
// if the negative was shorter must copy the remaining digits
// from positive
if (i >= negative.numberLength) {
- for ( ; i < positive.numberLength; i++) {
+ for (; i < positive.numberLength; i++) {
resDigits[i] = positive.digits[i];
}
} // else positive ended and must "copy" virtual 0's, do nothing then
@@ -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;
@@ -209,12 +215,12 @@ class TLogical {
resLength = longer.numberLength;
resDigits = new int[resLength];
resDigits[i] = -digit;
- for (i++; i < shorter.numberLength; i++){
+ for (i++; i < shorter.numberLength; i++) {
// resDigits[i] = ~(~longer.digits[i] & ~shorter.digits[i];)
resDigits[i] = longer.digits[i] | shorter.digits[i];
}
// shorter has only the remaining virtual sign bits
- for( ; i < longer.numberLength; i++){
+ for (; i < longer.numberLength; i++) {
resDigits[i] = longer.digits[i];
}
@@ -224,7 +230,7 @@ class TLogical {
/** @see TBigInteger#andNot(TBigInteger) */
static TBigInteger andNot(TBigInteger val, TBigInteger that) {
- if (that.sign == 0 ) {
+ if (that.sign == 0) {
return val;
}
if (val.sign == 0) {
@@ -233,7 +239,7 @@ class TLogical {
if (val.equals(TBigInteger.MINUS_ONE)) {
return that.not();
}
- if (that.equals(TBigInteger.MINUS_ONE)){
+ if (that.equals(TBigInteger.MINUS_ONE)) {
return TBigInteger.ZERO;
}
@@ -257,14 +263,14 @@ 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;
for (i = val.getFirstNonzeroDigit(); i < limit; i++) {
resDigits[i] = val.digits[i] & ~that.digits[i];
}
- for ( ; i < val.numberLength; i++) {
+ for (; i < val.numberLength; i++) {
resDigits[i] = val.digits[i];
}
@@ -284,11 +290,11 @@ 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;
- for ( ; i < iNeg; i++) {
+ for (; i < iNeg; i++) {
// resDigits[i] = positive.digits[i] & -1 (~0)
resDigits[i] = positive.digits[i];
}
@@ -296,7 +302,7 @@ class TLogical {
resDigits[i] = positive.digits[i] & (negative.digits[i] - 1);
i++;
}
- for ( ; i < resLength; i++) {
+ for (; i < resLength; i++) {
// resDigits[i] = positive.digits[i] & ~(~negative.digits[i]);
resDigits[i] = positive.digits[i] & negative.digits[i];
}
@@ -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;
@@ -326,7 +332,7 @@ class TLogical {
if (iPos > iNeg) {
resDigits = new int[resLength];
limit = Math.min(negative.numberLength, iPos);
- for ( ; i < limit; i++) {
+ for (; i < limit; i++) {
// 1st case: resDigits [i] = -(-negative.digits[i] & (~0))
// otherwise: resDigits[i] = ~(~negative.digits[i] & ~0) ;
resDigits[i] = negative.digits[i];
@@ -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 && (digit = ~negative.digits[i]) == 0; i++) {
- // do nothing
+ for (; i < negative.numberLength; i++) {
+ digit = ~negative.digits[i];
+ if (digit != 0) {
+ break;
+ }
}
if (digit == 0) {
resLength++;
@@ -368,15 +383,15 @@ class TLogical {
}
limit = Math.min(positive.numberLength, negative.numberLength);
- for ( ; i < limit; i++) {
+ for (; i < limit; i++) {
//resDigits[i] = ~(~negative.digits[i] & ~positive.digits[i]);
resDigits[i] = negative.digits[i] | positive.digits[i];
}
// Actually one of the next two cycles will be executed
- for ( ; i < negative.numberLength; i++) {
+ for (; i < negative.numberLength; i++) {
resDigits[i] = negative.digits[i];
}
- for ( ; i < positive.numberLength; i++) {
+ for (; i < positive.numberLength; i++) {
resDigits[i] = positive.digits[i];
}
@@ -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) {
@@ -407,7 +422,7 @@ class TLogical {
resDigits[i] = ~val.digits[i];
}
if (i == val.numberLength) {
- for ( ; i < iThat; i++) {
+ for (; i < iThat; i++) {
// resDigits[i] = -1 & -1;
resDigits[i] = -1;
}
@@ -417,7 +432,7 @@ class TLogical {
// resDigits[i] = ~val.digits[i] & ~-that.digits[i];
resDigits[i] = ~val.digits[i] & (that.digits[i] - 1);
}
- } else if (iThat < iVal ) {
+ } else if (iThat < iVal) {
// resDigits[i] = -val.digits[i] & ~~that.digits[i];
resDigits[i] = -val.digits[i] & that.digits[i];
} else {
@@ -430,7 +445,7 @@ class TLogical {
// resDigits[i] = ~val.digits[i] & ~~that.digits[i];
resDigits[i] = ~val.digits[i] & that.digits[i];
}
- for ( ; i < that.numberLength; i++) {
+ for (; i < that.numberLength; i++) {
// resDigits[i] = -1 & ~~that.digits[i];
resDigits[i] = that.digits[i];
}
@@ -478,13 +493,13 @@ 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++) {
resDigits[i] = longer.digits[i] | shorter.digits[i];
}
- for ( ; i < resLength; i++) {
+ for (; i < resLength; i++) {
resDigits[i] = longer.digits[i];
}
@@ -493,7 +508,7 @@ class TLogical {
}
/** @return sign = -1, magnitude = -(-val.magnitude | -that.magnitude) */
- static TBigInteger orNegative(TBigInteger val, TBigInteger that){
+ static TBigInteger orNegative(TBigInteger val, TBigInteger that) {
// PRE: val and that are negative;
// PRE: val has at least as many trailing zeros digits as that
int iThat = that.getFirstNonzeroDigit();
@@ -502,12 +517,12 @@ class TLogical {
if (iVal >= that.numberLength) {
return that;
- }else if (iThat >= val.numberLength) {
+ } else if (iThat >= val.numberLength) {
return val;
}
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) {
@@ -530,7 +545,7 @@ class TLogical {
}
/** @return sign = -1, magnitude = -(positive.magnitude | -negative.magnitude) */
- static TBigInteger orDiffSigns(TBigInteger positive, TBigInteger negative){
+ static TBigInteger orDiffSigns(TBigInteger positive, TBigInteger negative) {
// Jumping over the least significant zero bits
int iNeg = negative.getFirstNonzeroDigit();
int iPos = positive.getFirstNonzeroDigit();
@@ -543,9 +558,9 @@ class TLogical {
return negative;
}
int resLength = negative.numberLength;
- int resDigits[] = new int[resLength];
+ int[] resDigits = new int[resLength];
- if (iNeg < iPos ) {
+ if (iNeg < iPos) {
// We know for sure that this will
// be the first non zero digit in the result
for (i = iNeg; i < iPos; i++) {
@@ -555,20 +570,21 @@ class TLogical {
i = iPos;
resDigits[i] = -positive.digits[i];
limit = Math.min(positive.numberLength, iNeg);
- for(i++; i < limit; i++ ) {
+ for (i++; i < limit; i++) {
resDigits[i] = ~positive.digits[i];
}
if (i != positive.numberLength) {
resDigits[i] = ~(-negative.digits[i] | positive.digits[i]);
- } else{
- for (; i ~(~positive.digits[i])
resDigits[i] = positive.digits[i];
}
@@ -746,11 +762,11 @@ class TLogical {
} else {
//if the positive has no more elements must fill the remaining digits with
//the negative ones
- for ( ; i < iNeg; i++) {
+ for (; i < iNeg; i++) {
// resDigits[i] = ~(0 ^ 0)
resDigits[i] = -1;
}
- for ( ; i < negative.numberLength; i++) {
+ for (; i < negative.numberLength; i++) {
//resDigits[i] = ~(~negative.digits[i] ^ 0)
resDigits[i] = negative.digits[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 && (digit = ~negative.digits[i]) == 0; i++) {
- // do nothing
+ for (; i < negative.numberLength; i++) {
+ digit = ~negative.digits[i];
+ if (digit != 0) {
+ break;
+ }
}
if (digit == 0) {
resLength = resLength + 1;
@@ -789,14 +814,14 @@ class TLogical {
}
limit = Math.min(negative.numberLength, positive.numberLength);
- for ( ; i < limit; i++) {
+ for (; i < limit; i++) {
resDigits[i] = ~(~negative.digits[i] ^ positive.digits[i]);
}
- for ( ; i < positive.numberLength; i++) {
+ for (; i < positive.numberLength; i++) {
// resDigits[i] = ~(positive.digits[i] ^ -1)
resDigits[i] = positive.digits[i];
}
- for ( ; i < negative.numberLength; i++) {
+ for (; i < negative.numberLength; i++) {
// resDigits[i] = ~(0 ^ ~negative.digits[i])
resDigits[i] = negative.digits[i];
}
diff --git a/teavm-classlib/src/main/java/org/teavm/classlib/java/math/TMathContext.java b/teavm-classlib/src/main/java/org/teavm/classlib/java/math/TMathContext.java
index 5dec4fdd6..9794ae51e 100644
--- a/teavm-classlib/src/main/java/org/teavm/classlib/java/math/TMathContext.java
+++ b/teavm-classlib/src/main/java/org/teavm/classlib/java/math/TMathContext.java
@@ -1,12 +1,11 @@
/*
- * 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.
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * 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,
@@ -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();
}
/**
diff --git a/teavm-classlib/src/main/java/org/teavm/classlib/java/math/TMultiplication.java b/teavm-classlib/src/main/java/org/teavm/classlib/java/math/TMultiplication.java
index 837175468..83c9faf46 100644
--- a/teavm-classlib/src/main/java/org/teavm/classlib/java/math/TMultiplication.java
+++ b/teavm-classlib/src/main/java/org/teavm/classlib/java/math/TMultiplication.java
@@ -1,12 +1,11 @@
/*
- * 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.
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * 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,
@@ -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 = v1 * B + v0
*
*
- * u*v = (u1 * v1) * B2 + ((u1 - u0) * (v0 - v1) + u1 * v1 +
+ * u*v = (u1 * v1) * B2 + ((u1 - u0)
+ * * (v0 - v1) + u1 * v1 +
* u0 * v0 ) * B + u0 * v0
*
* @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);
@@ -229,15 +226,15 @@ class TMultiplication {
// A special case when both numbers don't exceed int
if (resLength == 2) {
long val = unsignedMultAddAdd(a.digits[0], b.digits[0], 0, 0);
- int valueLo = (int)val;
- int valueHi = (int)(val >>> 32);
- return ((valueHi == 0)
- ? new TBigInteger(resSign, valueLo)
- : new TBigInteger(resSign, 2, new int[]{valueLo, valueHi}));
+ int valueLo = (int) val;
+ int valueHi = (int) (val >>> 32);
+ return valueHi == 0
+ ? new TBigInteger(resSign, valueLo)
+ : 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,32 +243,34 @@ 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) {
+ if (aLen == 1) {
resDigits[bLen] = multiplyByInt(resDigits, bDigits, bLen, aDigits[0]);
- } else if(bLen == 1) {
+ } else if (bLen == 1) {
resDigits[aLen] = multiplyByInt(resDigits, aDigits, aLen, bDigits[0]);
} else {
multPAP(aDigits, bDigits, resDigits, aLen, bLen);
}
}
- static void multPAP(int a[], int b[], int t[], int aLen, int bLen) {
- if(a == b && aLen == bLen) {
+ static void multPAP(int[] a, int[] b, int[] t, int aLen, int bLen) {
+ if (a == b && aLen == bLen) {
square(a, aLen, t);
return;
}
- for(int i = 0; i < aLen; i++){
+ for (int i = 0; i < aLen; i++) {
long carry = 0;
int aI = a[i];
- for (int j = 0; j < bLen; j++){
- carry = unsignedMultAddAdd(aI, b[j], t[i+j], (int)carry);
- t[i+j] = (int) carry;
+ for (int j = 0; j < bLen; j++) {
+ carry = unsignedMultAddAdd(aI, b[j], t[i + j], (int) carry);
+ t[i + j] = (int) carry;
carry >>>= 32;
}
- t[i+bLen] = (int) carry;
+ t[i + bLen] = (int) carry;
}
}
@@ -283,14 +282,14 @@ 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);
- res[i] = (int)carry;
+ carry = unsignedMultAddAdd(a[i], factor, (int) carry, 0);
+ res[i] = (int) carry;
carry >>>= 32;
}
- return (int)carry;
+ return (int) carry;
}
@@ -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);
}
@@ -321,15 +320,15 @@ class TMultiplication {
if (aNumberLength == 1) {
long res = unsignedMultAddAdd(aDigits[0], factor, 0, 0);
- int resLo = (int)res;
- int resHi = (int)(res >>> 32);
- return ((resHi == 0)
- ? new TBigInteger(resSign, resLo)
- : new TBigInteger(resSign, 2, new int[]{resLo, resHi}));
+ int resLo = (int) res;
+ int resHi = (int) (res >>> 32);
+ return resHi == 0
+ ? new TBigInteger(resSign, resLo)
+ : 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);
@@ -349,11 +348,10 @@ class TMultiplication {
}
// acc = base^(2^i)
//a limit where karatsuba performs a faster square than the square algorithm
- if ( acc.numberLength == 1 ){
+ if (acc.numberLength == 1) {
acc = acc.multiply(acc); // square
- }
- else{
- acc = new TBigInteger(1, square(acc.digits, acc.numberLength, new int [acc.numberLength<<1]));
+ } else {
+ acc = new TBigInteger(1, square(acc.digits, acc.numberLength, new int[acc.numberLength << 1]));
}
}
// exponent == 1, multiply one more time
@@ -369,26 +367,26 @@ class TMultiplication {
static int[] square(int[] a, int aLen, int[] res) {
long carry;
- for(int i = 0; i < aLen; i++){
+ for (int i = 0; i < aLen; i++) {
carry = 0;
- for (int j = i+1; j < aLen; j++){
- carry = unsignedMultAddAdd(a[i], a[j], res[i+j], (int)carry);
- res[i+j] = (int) carry;
+ for (int j = i + 1; j < aLen; j++) {
+ carry = unsignedMultAddAdd(a[i], a[j], res[i + j], (int) carry);
+ res[i + j] = (int) carry;
carry >>>= 32;
}
- res[i+aLen] = (int) carry;
+ res[i + aLen] = (int) carry;
}
TBitLevel.shiftLeftOneBit(res, res, aLen << 1);
carry = 0;
- for(int i = 0, index = 0; i < aLen; i++, index++){
- carry = unsignedMultAddAdd(a[i], a[i], res[index],(int)carry);
+ for (int i = 0, index = 0; i < aLen; i++, index++) {
+ carry = unsignedMultAddAdd(a[i], a[i], res[index], (int) carry);
res[index] = (int) carry;
carry >>>= 32;
index++;
carry += res[index] & 0xFFFFFFFFL;
- res[index] = (int)carry;
+ res[index] = (int) carry;
carry >>>= 32;
}
return res;
@@ -403,9 +401,9 @@ class TMultiplication {
*/
static TBigInteger multiplyByTenPow(TBigInteger val, long exp) {
// PRE: exp >= 0
- return ((exp < tenPows.length)
- ? multiplyByPositiveInt(val, tenPows[(int)exp])
- : val.multiply(powerOf10(exp)));
+ return exp < tenPows.length
+ ? multiplyByPositiveInt(val, tenPows[(int) exp])
+ : val.multiply(powerOf10(exp));
}
/**
@@ -417,7 +415,7 @@ class TMultiplication {
*/
static TBigInteger powerOf10(long exp) {
// PRE: exp >= 0
- int intExp = (int)exp;
+ int intExp = (int) exp;
// "SMALL POWERS"
if (exp < bigTenPows.length) {
// The largest power that fit in 'long' type
@@ -434,7 +432,7 @@ class TMultiplication {
* To check if there is free memory to allocate a BigInteger of the
* estimated size, measured in bytes: 1 + [exp / log10(2)]
*/
- long byteArraySize = 1 + (long)(exp / 2.4082399653118496);
+ long byteArraySize = 1 + (long) (exp / 2.4082399653118496);
if (byteArraySize > 1000000) {
throw new ArithmeticException("power of ten too big");
@@ -454,7 +452,7 @@ class TMultiplication {
TBigInteger res = powerOfFive;
long longExp = exp - Integer.MAX_VALUE;
- intExp = (int)(exp % Integer.MAX_VALUE);
+ intExp = (int) (exp % Integer.MAX_VALUE);
while (longExp > Integer.MAX_VALUE) {
res = res.multiply(powerOfFive);
longExp -= Integer.MAX_VALUE;
@@ -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));
}
}
diff --git a/teavm-classlib/src/main/java/org/teavm/classlib/java/math/TPrimality.java b/teavm-classlib/src/main/java/org/teavm/classlib/java/math/TPrimality.java
index 2f6bbd78a..7686119a3 100644
--- a/teavm-classlib/src/main/java/org/teavm/classlib/java/math/TPrimality.java
+++ b/teavm-classlib/src/main/java/org/teavm/classlib/java/math/TPrimality.java
@@ -1,12 +1,11 @@
/*
- * 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.
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * 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,
@@ -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,32 +228,33 @@ 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
- * that all methods would call Miller-Rabin with t <= 50 so
- * this part is only to do more robust the algorithm
- */
+ } 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
+ */
do {
x = new TBigInteger(bitLength, rnd);
} 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;
}
}
diff --git a/teavm-classlib/src/main/java/org/teavm/classlib/java/math/TRoundingMode.java b/teavm-classlib/src/main/java/org/teavm/classlib/java/math/TRoundingMode.java
index e6fe46451..95e7bb110 100644
--- a/teavm-classlib/src/main/java/org/teavm/classlib/java/math/TRoundingMode.java
+++ b/teavm-classlib/src/main/java/org/teavm/classlib/java/math/TRoundingMode.java
@@ -1,12 +1,11 @@
/*
- * 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.
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * 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,
@@ -14,7 +13,6 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
package org.teavm.classlib.java.math;
/**
diff --git a/teavm-classlib/src/main/java/org/teavm/classlib/java/net/TURI.java b/teavm-classlib/src/main/java/org/teavm/classlib/java/net/TURI.java
index e4b5f34c0..5e39f72fa 100644
--- a/teavm-classlib/src/main/java/org/teavm/classlib/java/net/TURI.java
+++ b/teavm-classlib/src/main/java/org/teavm/classlib/java/net/TURI.java
@@ -1,12 +1,11 @@
/*
- * 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.
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * 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,
@@ -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, 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, 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, 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, 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, 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, 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, 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;
diff --git a/teavm-classlib/src/main/java/org/teavm/classlib/java/net/TURIEncoderDecoder.java b/teavm-classlib/src/main/java/org/teavm/classlib/java/net/TURIEncoderDecoder.java
index a932e582b..4eb3d3ac8 100644
--- a/teavm-classlib/src/main/java/org/teavm/classlib/java/net/TURIEncoderDecoder.java
+++ b/teavm-classlib/src/main/java/org/teavm/classlib/java/net/TURIEncoderDecoder.java
@@ -1,12 +1,11 @@
/*
- * 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.
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * 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,
@@ -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:
diff --git a/teavm-classlib/src/main/java/org/teavm/classlib/java/net/TURISyntaxException.java b/teavm-classlib/src/main/java/org/teavm/classlib/java/net/TURISyntaxException.java
index 1a688563b..5150ff70b 100644
--- a/teavm-classlib/src/main/java/org/teavm/classlib/java/net/TURISyntaxException.java
+++ b/teavm-classlib/src/main/java/org/teavm/classlib/java/net/TURISyntaxException.java
@@ -1,12 +1,11 @@
/*
- * 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.
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * 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,
@@ -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;
diff --git a/teavm-classlib/src/main/java/org/teavm/classlib/java/nio/TBuffer.java b/teavm-classlib/src/main/java/org/teavm/classlib/java/nio/TBuffer.java
index 7b59fc767..e6186e068 100644
--- a/teavm-classlib/src/main/java/org/teavm/classlib/java/nio/TBuffer.java
+++ b/teavm-classlib/src/main/java/org/teavm/classlib/java/nio/TBuffer.java
@@ -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;
diff --git a/teavm-classlib/src/main/java/org/teavm/classlib/java/nio/TBufferOverflowException.java b/teavm-classlib/src/main/java/org/teavm/classlib/java/nio/TBufferOverflowException.java
index b6d24d0e8..4944f3b80 100644
--- a/teavm-classlib/src/main/java/org/teavm/classlib/java/nio/TBufferOverflowException.java
+++ b/teavm-classlib/src/main/java/org/teavm/classlib/java/nio/TBufferOverflowException.java
@@ -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;
diff --git a/teavm-classlib/src/main/java/org/teavm/classlib/java/nio/TBufferUnderflowException.java b/teavm-classlib/src/main/java/org/teavm/classlib/java/nio/TBufferUnderflowException.java
index cc1d7b086..52b1bd7be 100644
--- a/teavm-classlib/src/main/java/org/teavm/classlib/java/nio/TBufferUnderflowException.java
+++ b/teavm-classlib/src/main/java/org/teavm/classlib/java/nio/TBufferUnderflowException.java
@@ -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;
/**
diff --git a/teavm-classlib/src/main/java/org/teavm/classlib/java/nio/TByteBuffer.java b/teavm-classlib/src/main/java/org/teavm/classlib/java/nio/TByteBuffer.java
index a7338fef4..2f194cba6 100644
--- a/teavm-classlib/src/main/java/org/teavm/classlib/java/nio/TByteBuffer.java
+++ b/teavm-classlib/src/main/java/org/teavm/classlib/java/nio/TByteBuffer.java
@@ -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 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 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= 0 ? " at " + mark : " is not set") + "]";
+ return "[ByteBuffer position=" + position + ", limit=" + limit + ", capacity=" + capacity + ", mark "
+ + (mark >= 0 ? " at " + mark : " is not set") + "]";
}
@Override
@@ -161,7 +176,7 @@ public abstract class TByteBuffer extends TBuffer implements TComparable> 8);
- array[start + position++] = (byte)value;
+ array[start + position++] = (byte) (value >> 8);
+ array[start + position++] = (byte) value;
} else {
- array[start + position++] = (byte)value;
- array[start + position++] = (byte)(value >> 8);
+ array[start + position++] = (byte) value;
+ array[start + position++] = (byte) (value >> 8);
}
return this;
}
@@ -144,9 +159,9 @@ class TByteBufferImpl extends TByteBuffer {
int a = array[start + index] & 0xFF;
int b = array[start + index + 1] & 0xFF;
if (order == TByteOrder.BIG_ENDIAN) {
- return (char)((a << 8) | b);
+ return (char) ((a << 8) | b);
} else {
- return (char)((b << 8) | a);
+ return (char) ((b << 8) | a);
}
}
@@ -159,11 +174,11 @@ class TByteBufferImpl extends TByteBuffer {
throw new IndexOutOfBoundsException("Index " + index + " is outside of range [0;" + (limit - 1) + ")");
}
if (order == TByteOrder.BIG_ENDIAN) {
- array[start + index] = (byte)(value >> 8);
- array[start + index + 1] = (byte)value;
+ array[start + index] = (byte) (value >> 8);
+ array[start + index + 1] = (byte) value;
} else {
- array[start + index] = (byte)value;
- array[start + index + 1] = (byte)(value >> 8);
+ array[start + index] = (byte) value;
+ array[start + index + 1] = (byte) (value >> 8);
}
return this;
}
@@ -187,9 +202,9 @@ class TByteBufferImpl extends TByteBuffer {
int b = array[start + position + 1] & 0xFF;
position += 2;
if (order == TByteOrder.BIG_ENDIAN) {
- return (short)((a << 8) | b);
+ return (short) ((a << 8) | b);
} else {
- return (short)((b << 8) | a);
+ return (short) ((b << 8) | a);
}
}
@@ -202,11 +217,11 @@ class TByteBufferImpl extends TByteBuffer {
throw new TBufferOverflowException();
}
if (order == TByteOrder.BIG_ENDIAN) {
- array[start + position++] = (byte)(value >> 8);
- array[start + position++] = (byte)value;
+ array[start + position++] = (byte) (value >> 8);
+ array[start + position++] = (byte) value;
} else {
- array[start + position++] = (byte)value;
- array[start + position++] = (byte)(value >> 8);
+ array[start + position++] = (byte) value;
+ array[start + position++] = (byte) (value >> 8);
}
return this;
}
@@ -219,9 +234,9 @@ class TByteBufferImpl extends TByteBuffer {
int a = array[start + index] & 0xFF;
int b = array[start + index + 1] & 0xFF;
if (order == TByteOrder.BIG_ENDIAN) {
- return (short)((a << 8) | b);
+ return (short) ((a << 8) | b);
} else {
- return (short)((b << 8) | a);
+ return (short) ((b << 8) | a);
}
}
@@ -234,11 +249,11 @@ class TByteBufferImpl extends TByteBuffer {
throw new IndexOutOfBoundsException("Index " + index + " is outside of range [0;" + (limit - 1) + ")");
}
if (order == TByteOrder.BIG_ENDIAN) {
- array[start + index] = (byte)(value >> 8);
- array[start + index + 1] = (byte)value;
+ array[start + index] = (byte) (value >> 8);
+ array[start + index + 1] = (byte) value;
} else {
- array[start + index] = (byte)value;
- array[start + index + 1] = (byte)(value >> 8);
+ array[start + index] = (byte) value;
+ array[start + index + 1] = (byte) (value >> 8);
}
return this;
}
@@ -279,15 +294,15 @@ class TByteBufferImpl extends TByteBuffer {
throw new TBufferOverflowException();
}
if (order == TByteOrder.BIG_ENDIAN) {
- array[start + position++] = (byte)(value >> 24);
- array[start + position++] = (byte)(value >> 16);
- array[start + position++] = (byte)(value >> 8);
- array[start + position++] = (byte)value;
+ array[start + position++] = (byte) (value >> 24);
+ array[start + position++] = (byte) (value >> 16);
+ array[start + position++] = (byte) (value >> 8);
+ array[start + position++] = (byte) value;
} else {
- array[start + position++] = (byte)value;
- array[start + position++] = (byte)(value >> 8);
- array[start + position++] = (byte)(value >> 16);
- array[start + position++] = (byte)(value >> 24);
+ array[start + position++] = (byte) value;
+ array[start + position++] = (byte) (value >> 8);
+ array[start + position++] = (byte) (value >> 16);
+ array[start + position++] = (byte) (value >> 24);
}
return this;
}
@@ -317,15 +332,15 @@ class TByteBufferImpl extends TByteBuffer {
throw new IndexOutOfBoundsException("Index " + index + " is outside of range [0;" + (limit - 3) + ")");
}
if (order == TByteOrder.BIG_ENDIAN) {
- array[start + index] = (byte)(value >> 24);
- array[start + index + 1] = (byte)(value >> 16);
- array[start + index + 2] = (byte)(value >> 8);
- array[start + index + 3] = (byte)value;
+ array[start + index] = (byte) (value >> 24);
+ array[start + index + 1] = (byte) (value >> 16);
+ array[start + index + 2] = (byte) (value >> 8);
+ array[start + index + 3] = (byte) value;
} else {
- array[start + index] = (byte)value;
- array[start + index + 1] = (byte)(value >> 8);
- array[start + index + 2] = (byte)(value >> 16);
- array[start + index + 3] = (byte)(value >> 24);
+ array[start + index] = (byte) value;
+ array[start + index + 1] = (byte) (value >> 8);
+ array[start + index + 2] = (byte) (value >> 16);
+ array[start + index + 3] = (byte) (value >> 24);
}
return this;
}
@@ -370,23 +385,23 @@ class TByteBufferImpl extends TByteBuffer {
throw new TBufferOverflowException();
}
if (order == TByteOrder.BIG_ENDIAN) {
- array[start + position++] = (byte)(value >> 56);
- array[start + position++] = (byte)(value >> 48);
- array[start + position++] = (byte)(value >> 40);
- array[start + position++] = (byte)(value >> 32);
- array[start + position++] = (byte)(value >> 24);
- array[start + position++] = (byte)(value >> 16);
- array[start + position++] = (byte)(value >> 8);
- array[start + position++] = (byte)value;
+ array[start + position++] = (byte) (value >> 56);
+ array[start + position++] = (byte) (value >> 48);
+ array[start + position++] = (byte) (value >> 40);
+ array[start + position++] = (byte) (value >> 32);
+ array[start + position++] = (byte) (value >> 24);
+ array[start + position++] = (byte) (value >> 16);
+ array[start + position++] = (byte) (value >> 8);
+ array[start + position++] = (byte) value;
} else {
- array[start + position++] = (byte)value;
- array[start + position++] = (byte)(value >> 8);
- array[start + position++] = (byte)(value >> 16);
- array[start + position++] = (byte)(value >> 24);
- array[start + position++] = (byte)(value >> 32);
- array[start + position++] = (byte)(value >> 40);
- array[start + position++] = (byte)(value >> 48);
- array[start + position++] = (byte)(value >> 56);
+ array[start + position++] = (byte) value;
+ array[start + position++] = (byte) (value >> 8);
+ array[start + position++] = (byte) (value >> 16);
+ array[start + position++] = (byte) (value >> 24);
+ array[start + position++] = (byte) (value >> 32);
+ array[start + position++] = (byte) (value >> 40);
+ array[start + position++] = (byte) (value >> 48);
+ array[start + position++] = (byte) (value >> 56);
}
return this;
}
@@ -421,23 +436,23 @@ class TByteBufferImpl extends TByteBuffer {
throw new IndexOutOfBoundsException("Index " + index + " is outside of range [0;" + (limit - 3) + ")");
}
if (order == TByteOrder.BIG_ENDIAN) {
- array[start + index + 0] = (byte)(value >> 56);
- array[start + index + 1] = (byte)(value >> 48);
- array[start + index + 2] = (byte)(value >> 40);
- array[start + index + 3] = (byte)(value >> 32);
- array[start + index + 4] = (byte)(value >> 24);
- array[start + index + 5] = (byte)(value >> 16);
- array[start + index + 6] = (byte)(value >> 8);
- array[start + index + 7] = (byte)value;
+ array[start + index + 0] = (byte) (value >> 56);
+ array[start + index + 1] = (byte) (value >> 48);
+ array[start + index + 2] = (byte) (value >> 40);
+ array[start + index + 3] = (byte) (value >> 32);
+ array[start + index + 4] = (byte) (value >> 24);
+ array[start + index + 5] = (byte) (value >> 16);
+ array[start + index + 6] = (byte) (value >> 8);
+ array[start + index + 7] = (byte) value;
} else {
- array[start + index + 0] = (byte)value;
- array[start + index + 1] = (byte)(value >> 8);
- array[start + index + 2] = (byte)(value >> 16);
- array[start + index + 3] = (byte)(value >> 24);
- array[start + index + 4] = (byte)(value >> 24);
- array[start + index + 5] = (byte)(value >> 24);
- array[start + index + 6] = (byte)(value >> 24);
- array[start + index + 7] = (byte)(value >> 24);
+ array[start + index + 0] = (byte) value;
+ array[start + index + 1] = (byte) (value >> 8);
+ array[start + index + 2] = (byte) (value >> 16);
+ array[start + index + 3] = (byte) (value >> 24);
+ array[start + index + 4] = (byte) (value >> 24);
+ array[start + index + 5] = (byte) (value >> 24);
+ array[start + index + 6] = (byte) (value >> 24);
+ array[start + index + 7] = (byte) (value >> 24);
}
return this;
}
diff --git a/teavm-classlib/src/main/java/org/teavm/classlib/java/nio/TCharBuffer.java b/teavm-classlib/src/main/java/org/teavm/classlib/java/nio/TCharBuffer.java
index 0a7bb69f7..c65762a27 100644
--- a/teavm-classlib/src/main/java/org/teavm/classlib/java/nio/TCharBuffer.java
+++ b/teavm-classlib/src/main/java/org/teavm/classlib/java/nio/TCharBuffer.java
@@ -97,8 +97,8 @@ public abstract class TCharBuffer extends TBuffer implements Comparable 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 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 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);
@@ -238,7 +238,7 @@ public abstract class TCharBuffer extends TBuffer implements Comparable> 8);
- byteByffer.array[start + index * 2 + 1] = (byte)value;
+ byteByffer.array[start + index * 2] = (byte) (value >> 8);
+ byteByffer.array[start + index * 2 + 1] = (byte) value;
}
@Override
diff --git a/teavm-classlib/src/main/java/org/teavm/classlib/java/nio/TCharBufferOverByteBufferLittleEndian.java b/teavm-classlib/src/main/java/org/teavm/classlib/java/nio/TCharBufferOverByteBufferLittleEndian.java
index 967f372cd..ca61ce744 100644
--- a/teavm-classlib/src/main/java/org/teavm/classlib/java/nio/TCharBufferOverByteBufferLittleEndian.java
+++ b/teavm-classlib/src/main/java/org/teavm/classlib/java/nio/TCharBufferOverByteBufferLittleEndian.java
@@ -27,15 +27,15 @@ 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);
- return (char)value;
+ int value = ((byteByffer.array[start + index * 2 + 1] & 0xFF) << 8)
+ | (byteByffer.array[start + index * 2] & 0xFF);
+ return (char) value;
}
@Override
void putChar(int index, char value) {
- byteByffer.array[start + index * 2] = (byte)value;
- byteByffer.array[start + index * 2 + 1] = (byte)(value >> 8);
+ byteByffer.array[start + index * 2] = (byte) value;
+ byteByffer.array[start + index * 2 + 1] = (byte) (value >> 8);
}
@Override
diff --git a/teavm-classlib/src/main/java/org/teavm/classlib/java/nio/TDoubleBuffer.java b/teavm-classlib/src/main/java/org/teavm/classlib/java/nio/TDoubleBuffer.java
index 776f5d55a..45ce91d24 100644
--- a/teavm-classlib/src/main/java/org/teavm/classlib/java/nio/TDoubleBuffer.java
+++ b/teavm-classlib/src/main/java/org/teavm/classlib/java/nio/TDoubleBuffer.java
@@ -64,8 +64,8 @@ public abstract class TDoubleBuffer extends TBuffer implements Comparable 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 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= 0 ? " at " + mark : " is not set") + "]";
+ return "[DoubleBuffer position=" + position + ", limit=" + limit + ", capacity=" + capacity + ", mark "
+ + (mark >= 0 ? " at " + mark : " is not set") + "]";
}
@Override
@@ -169,7 +169,7 @@ public abstract class TDoubleBuffer extends TBuffer implements Comparable>> 32);
+ hashCode = 31 * hashCode + (int) elem + (int) (elem >>> 32);
}
return hashCode;
}
@@ -182,7 +182,7 @@ public abstract class TDoubleBuffer extends TBuffer implements Comparable> 56);
- byteByffer.array[start + index * 8 + 1] = (byte)(value >> 48);
- byteByffer.array[start + index * 8 + 2] = (byte)(value >> 40);
- byteByffer.array[start + index * 8 + 3] = (byte)(value >> 32);
- byteByffer.array[start + index * 8 + 4] = (byte)(value >> 24);
- byteByffer.array[start + index * 8 + 5] = (byte)(value >> 16);
- byteByffer.array[start + index * 8 + 6] = (byte)(value >> 8);
- byteByffer.array[start + index * 8 + 7] = (byte)value;
+ byteByffer.array[start + index * 8] = (byte) (value >> 56);
+ byteByffer.array[start + index * 8 + 1] = (byte) (value >> 48);
+ byteByffer.array[start + index * 8 + 2] = (byte) (value >> 40);
+ byteByffer.array[start + index * 8 + 3] = (byte) (value >> 32);
+ byteByffer.array[start + index * 8 + 4] = (byte) (value >> 24);
+ byteByffer.array[start + index * 8 + 5] = (byte) (value >> 16);
+ byteByffer.array[start + index * 8 + 6] = (byte) (value >> 8);
+ byteByffer.array[start + index * 8 + 7] = (byte) value;
} else {
- byteByffer.array[start + index * 8] = (byte)value;
- byteByffer.array[start + index * 8 + 1] = (byte)(value >> 8);
- byteByffer.array[start + index * 8 + 2] = (byte)(value >> 16);
- byteByffer.array[start + index * 8 + 3] = (byte)(value >> 24);
- byteByffer.array[start + index * 8 + 4] = (byte)(value >> 32);
- byteByffer.array[start + index * 8 + 5] = (byte)(value >> 40);
- byteByffer.array[start + index * 8 + 6] = (byte)(value >> 48);
- byteByffer.array[start + index * 8 + 7] = (byte)(value >> 56);
+ byteByffer.array[start + index * 8] = (byte) value;
+ byteByffer.array[start + index * 8 + 1] = (byte) (value >> 8);
+ byteByffer.array[start + index * 8 + 2] = (byte) (value >> 16);
+ byteByffer.array[start + index * 8 + 3] = (byte) (value >> 24);
+ byteByffer.array[start + index * 8 + 4] = (byte) (value >> 32);
+ byteByffer.array[start + index * 8 + 5] = (byte) (value >> 40);
+ byteByffer.array[start + index * 8 + 6] = (byte) (value >> 48);
+ byteByffer.array[start + index * 8 + 7] = (byte) (value >> 56);
}
}
diff --git a/teavm-classlib/src/main/java/org/teavm/classlib/java/nio/TFloatBuffer.java b/teavm-classlib/src/main/java/org/teavm/classlib/java/nio/TFloatBuffer.java
index 938f8cea6..8e9997419 100644
--- a/teavm-classlib/src/main/java/org/teavm/classlib/java/nio/TFloatBuffer.java
+++ b/teavm-classlib/src/main/java/org/teavm/classlib/java/nio/TFloatBuffer.java
@@ -64,8 +64,8 @@ public abstract class TFloatBuffer extends TBuffer implements Comparable