From bda49b95bd0b6924246af2ba5396c30fe40768ff Mon Sep 17 00:00:00 2001 From: Alexey Andreev Date: Thu, 23 Jul 2015 15:31:49 +0300 Subject: [PATCH] Fix build. Apply rules to some classes of teavm-classlib --- checkstyle.xml | 7 +- license-regexp.txt | 2 +- pom.xml | 14 +- teavm-classlib/pom.xml | 9 + .../java/org/teavm/classlib/impl/Base46.java | 13 +- .../impl/currency/CountriesGenerator.java | 8 +- .../impl/currency/CurrenciesGenerator.java | 6 +- .../impl/currency/CurrencyHelper.java | 3 + .../impl/report/JCLComparisonVisitor.java | 4 +- .../classlib/impl/tz/CachedDateTimeZone.java | 13 +- .../teavm/classlib/impl/tz/DateTimeZone.java | 2 +- .../classlib/impl/tz/DateTimeZoneBuilder.java | 83 ++-- .../impl/tz/DateTimeZoneProvider.java | 7 +- .../classlib/impl/tz/FixedDateTimeZone.java | 6 +- .../impl/tz/StorableDateTimeZone.java | 12 +- .../classlib/impl/tz/ZoneInfoCompiler.java | 81 ++-- .../impl/unicode/CLDRDecimalData.java | 4 +- .../classlib/impl/unicode/CLDRHelper.java | 18 +- .../classlib/impl/unicode/CLDRReader.java | 38 +- .../unicode/DateSymbolsMetadataGenerator.java | 26 +- .../classlib/impl/unicode/UnicodeHelper.java | 27 +- .../classlib/impl/unicode/UnicodeSupport.java | 7 +- .../java/io/TBufferedInputStream.java | 21 +- .../classlib/java/io/TBufferedReader.java | 2 +- .../java/io/TByteArrayInputStream.java | 2 +- .../java/io/TByteArrayOutputStream.java | 2 +- .../teavm/classlib/java/io/TCloseable.java | 2 +- .../classlib/java/io/TDataInputStream.java | 45 +- .../teavm/classlib/java/io/TDataOutput.java | 2 +- .../classlib/java/io/TDataOutputStream.java | 35 +- .../classlib/java/io/TFilterInputStream.java | 13 +- .../teavm/classlib/java/io/TInputStream.java | 4 +- .../classlib/java/io/TOutputStreamWriter.java | 2 +- .../java/io/TPushbackInputStream.java | 6 +- .../org/teavm/classlib/java/io/TReader.java | 2 +- .../teavm/classlib/java/io/TStringReader.java | 2 +- .../org/teavm/classlib/java/io/TWriter.java | 8 +- .../java/lang/TAbstractStringBuilder.java | 36 +- .../teavm/classlib/java/lang/TBoolean.java | 2 +- .../org/teavm/classlib/java/lang/TByte.java | 6 +- .../teavm/classlib/java/lang/TCharacter.java | 72 +-- .../org/teavm/classlib/java/lang/TClass.java | 42 +- ...r.java => TConsoleOutputStreamStderr.java} | 2 +- ...t.java => TConsoleOutputStreamStdout.java} | 2 +- .../org/teavm/classlib/java/lang/TDouble.java | 20 +- .../org/teavm/classlib/java/lang/TEnum.java | 11 +- .../org/teavm/classlib/java/lang/TFloat.java | 12 +- .../teavm/classlib/java/lang/TInteger.java | 6 +- .../org/teavm/classlib/java/lang/TLong.java | 12 +- .../org/teavm/classlib/java/lang/TMath.java | 12 +- .../org/teavm/classlib/java/lang/TNumber.java | 4 +- .../org/teavm/classlib/java/lang/TObject.java | 14 +- .../teavm/classlib/java/lang/TRuntime.java | 22 +- .../org/teavm/classlib/java/lang/TShort.java | 8 +- .../java/lang/TStackTraceElement.java | 10 +- .../teavm/classlib/java/lang/TStrictMath.java | 4 +- .../org/teavm/classlib/java/lang/TString.java | 24 +- .../org/teavm/classlib/java/lang/TSystem.java | 12 +- .../org/teavm/classlib/java/lang/TThread.java | 18 +- .../reflect/AnnotationDependencyListener.java | 10 +- .../teavm/classlib/java/math/TBigDecimal.java | 422 +++++++++--------- .../teavm/classlib/java/math/TBigInteger.java | 123 +++-- .../teavm/classlib/java/math/TBitLevel.java | 55 +-- .../teavm/classlib/java/math/TConversion.java | 57 +-- .../teavm/classlib/java/math/TDivision.java | 86 ++-- .../teavm/classlib/java/math/TElementary.java | 81 ++-- .../teavm/classlib/java/math/TLogical.java | 189 ++++---- .../classlib/java/math/TMathContext.java | 20 +- .../classlib/java/math/TMultiplication.java | 125 +++--- .../teavm/classlib/java/math/TPrimality.java | 62 +-- .../classlib/java/math/TRoundingMode.java | 14 +- .../org/teavm/classlib/java/net/TURI.java | 52 ++- .../classlib/java/net/TURIEncoderDecoder.java | 16 +- .../java/net/TURISyntaxException.java | 14 +- .../org/teavm/classlib/java/nio/TBuffer.java | 23 +- .../java/nio/TBufferOverflowException.java | 15 + .../java/nio/TBufferUnderflowException.java | 15 + .../teavm/classlib/java/nio/TByteBuffer.java | 29 +- .../classlib/java/nio/TByteBufferImpl.java | 159 ++++--- .../teavm/classlib/java/nio/TCharBuffer.java | 14 +- .../TCharBufferOverByteBufferBigEndian.java | 10 +- ...TCharBufferOverByteBufferLittleEndian.java | 10 +- .../classlib/java/nio/TDoubleBuffer.java | 16 +- .../java/nio/TDoubleBufferOverByteBuffer.java | 64 +-- .../teavm/classlib/java/nio/TFloatBuffer.java | 14 +- .../TFloatBufferOverByteBufferBigEndian.java | 16 +- ...FloatBufferOverByteBufferLittleEndian.java | 16 +- .../teavm/classlib/java/nio/TIntBuffer.java | 14 +- .../TIntBufferOverByteBufferBigEndian.java | 16 +- .../TIntBufferOverByteBufferLittleEndian.java | 16 +- .../java/nio/TInvalidMarkException.java | 15 + .../teavm/classlib/java/nio/TLongBuffer.java | 16 +- .../TLongBufferOverByteBufferBigEndian.java | 32 +- ...TLongBufferOverByteBufferLittleEndian.java | 32 +- .../java/nio/TReadOnlyBufferException.java | 15 + .../teavm/classlib/java/nio/TShortBuffer.java | 14 +- .../TShortBufferOverByteBufferBigEndian.java | 10 +- ...ShortBufferOverByteBufferLittleEndian.java | 10 +- .../java/nio/charset/TCharsetDecoder.java | 10 +- .../java/nio/charset/TCharsetEncoder.java | 6 +- .../java/nio/charset/TCoderResult.java | 8 +- .../java/nio/charset/impl/TUTF8Decoder.java | 6 +- .../java/nio/charset/impl/TUTF8Encoder.java | 20 +- .../teavm/classlib/java/text/TAnnotation.java | 24 +- .../text/TAttributedCharacterIterator.java | 42 +- .../classlib/java/text/TAttributedString.java | 38 +- .../java/text/TCharacterIterator.java | 46 +- .../teavm/classlib/java/text/TDateFormat.java | 34 +- .../java/text/TDateFormatElement.java | 19 +- .../java/text/TDateFormatSymbols.java | 30 +- .../classlib/java/text/TDecimalFormat.java | 48 +- .../java/text/TDecimalFormatParser.java | 47 +- .../java/text/TDecimalFormatSymbols.java | 22 +- .../classlib/java/text/TFieldPosition.java | 39 +- .../org/teavm/classlib/java/text/TFormat.java | 37 +- .../classlib/java/text/TNumberFormat.java | 13 +- .../classlib/java/text/TParseException.java | 24 +- .../classlib/java/text/TParsePosition.java | 28 +- .../classlib/java/text/TSimpleDateFormat.java | 12 +- .../java/util/TAbstractCollection.java | 4 +- .../classlib/java/util/TAbstractList.java | 2 +- .../classlib/java/util/TAbstractMap.java | 16 +- .../teavm/classlib/java/util/TArrayDeque.java | 12 +- .../teavm/classlib/java/util/TArrayList.java | 2 +- .../org/teavm/classlib/java/util/TArrays.java | 44 +- .../org/teavm/classlib/java/util/TBitSet.java | 44 +- .../teavm/classlib/java/util/TCalendar.java | 78 ++-- .../java/util/TCheckedCollection.java | 2 +- .../classlib/java/util/TCheckedList.java | 2 +- .../classlib/java/util/TCollections.java | 20 +- .../teavm/classlib/java/util/TCurrency.java | 4 +- .../org/teavm/classlib/java/util/TDate.java | 22 +- .../java/util/TGregorianCalendar.java | 94 ++-- .../teavm/classlib/java/util/THashMap.java | 75 ++-- .../teavm/classlib/java/util/THashSet.java | 2 +- .../teavm/classlib/java/util/THashtable.java | 17 +- .../classlib/java/util/TIANATimeZone.java | 4 +- .../classlib/java/util/TLinkedHashMap.java | 39 +- .../org/teavm/classlib/java/util/TLocale.java | 14 +- .../org/teavm/classlib/java/util/TMap.java | 4 +- .../teavm/classlib/java/util/TObjects.java | 16 +- .../teavm/classlib/java/util/TObservable.java | 25 +- .../teavm/classlib/java/util/TObserver.java | 24 +- .../classlib/java/util/TPriorityQueue.java | 20 +- .../org/teavm/classlib/java/util/TRandom.java | 10 +- .../classlib/java/util/TServiceLoader.java | 2 +- .../classlib/java/util/TStringTokenizer.java | 38 +- .../teavm/classlib/java/util/TTimeZone.java | 35 +- .../org/teavm/classlib/java/util/TTimer.java | 10 +- .../teavm/classlib/java/util/TTreeMap.java | 66 +-- .../teavm/classlib/java/util/TTreeSet.java | 15 + .../org/teavm/classlib/java/util/TVector.java | 47 +- .../java/util/regex/TAbstractCharClass.java | 45 +- teavm-core/pom.xml | 4 - teavm-html4j/pom.xml | 14 + teavm-jso/pom.xml | 14 + teavm-maven/teavm-maven-plugin/pom.xml | 17 +- teavm-samples/teavm-samples-async/pom.xml | 14 + teavm-samples/teavm-samples-hello/pom.xml | 14 + teavm-samples/teavm-samples-storage/pom.xml | 14 + teavm-samples/teavm-samples-video/pom.xml | 14 + 161 files changed, 2296 insertions(+), 2022 deletions(-) rename teavm-classlib/src/main/java/org/teavm/classlib/java/lang/{TConsoleOutputStream_stderr.java => TConsoleOutputStreamStderr.java} (94%) rename teavm-classlib/src/main/java/org/teavm/classlib/java/lang/{TConsoleOutputStream_stdout.java => TConsoleOutputStreamStdout.java} (94%) 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 getSuperclass() { - return (TClass)getClass(platformClass.getMetadata().getSuperclass()); + return (TClass) 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)this; + return (TClass) 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 dst.length) { - throw new IndexOutOfBoundsException("The last float in dst " + (offset + length) + " is outside " + - "of array of size " + dst.length); + throw new IndexOutOfBoundsException("The last float in dst " + (offset + length) + " is outside " + + "of array of size " + dst.length); } if (remaining() < length) { throw new TBufferUnderflowException(); @@ -113,8 +113,8 @@ public abstract class TFloatBuffer extends TBuffer implements Comparable src.length) { - throw new IndexOutOfBoundsException("The last float in src " + (offset + length) + " is outside " + - "of array of size " + src.length); + throw new IndexOutOfBoundsException("The last float in src " + (offset + length) + " is outside " + + "of array of size " + src.length); } if (length < 0) { throw new IndexOutOfBoundsException("Length " + length + " must be non-negative"); @@ -159,8 +159,8 @@ public abstract class TFloatBuffer extends TBuffer implements Comparable= 0 ? " at " + mark : " is not set") + "]"; + return "[FloatBuffer position=" + position + ", limit=" + limit + ", capacity=" + capacity + ", mark " + + (mark >= 0 ? " at " + mark : " is not set") + "]"; } @Override @@ -181,7 +181,7 @@ public abstract class TFloatBuffer extends TBuffer implements Comparable> 8); - byteByffer.array[start + index * 4 + 2] = (byte)(value >> 16); - byteByffer.array[start + index * 4 + 3] = (byte)(value >> 24); + byteByffer.array[start + index * 4] = (byte) value; + byteByffer.array[start + index * 4 + 1] = (byte) (value >> 8); + byteByffer.array[start + index * 4 + 2] = (byte) (value >> 16); + byteByffer.array[start + index * 4 + 3] = (byte) (value >> 24); } @Override diff --git a/teavm-classlib/src/main/java/org/teavm/classlib/java/nio/TFloatBufferOverByteBufferLittleEndian.java b/teavm-classlib/src/main/java/org/teavm/classlib/java/nio/TFloatBufferOverByteBufferLittleEndian.java index e098ef69b..e40972cc5 100644 --- a/teavm-classlib/src/main/java/org/teavm/classlib/java/nio/TFloatBufferOverByteBufferLittleEndian.java +++ b/teavm-classlib/src/main/java/org/teavm/classlib/java/nio/TFloatBufferOverByteBufferLittleEndian.java @@ -33,20 +33,20 @@ class TFloatBufferOverByteBufferLittleEndian extends TFloatBufferOverByteBuffer @Override float getElement(int index) { - int value = ((byteByffer.array[start + index * 4] & 0xFF) << 24) | - ((byteByffer.array[start + index * 4 + 1] & 0xFF) << 16) | - ((byteByffer.array[start + index * 4 + 2] & 0xFF) << 8) | - (byteByffer.array[start + index * 4 + 3] & 0xFF); + int value = ((byteByffer.array[start + index * 4] & 0xFF) << 24) + | ((byteByffer.array[start + index * 4 + 1] & 0xFF) << 16) + | ((byteByffer.array[start + index * 4 + 2] & 0xFF) << 8) + | (byteByffer.array[start + index * 4 + 3] & 0xFF); return Float.intBitsToFloat(value); } @Override void putElement(int index, float f) { int value = Float.floatToIntBits(f); - byteByffer.array[start + index * 4] = (byte)(value >> 24); - byteByffer.array[start + index * 4 + 1] = (byte)(value >> 16); - byteByffer.array[start + index * 4 + 2] = (byte)(value >> 8); - byteByffer.array[start + index * 4 + 3] = (byte)value; + byteByffer.array[start + index * 4] = (byte) (value >> 24); + byteByffer.array[start + index * 4 + 1] = (byte) (value >> 16); + byteByffer.array[start + index * 4 + 2] = (byte) (value >> 8); + byteByffer.array[start + index * 4 + 3] = (byte) value; } @Override diff --git a/teavm-classlib/src/main/java/org/teavm/classlib/java/nio/TIntBuffer.java b/teavm-classlib/src/main/java/org/teavm/classlib/java/nio/TIntBuffer.java index a43bca24b..7efbf640b 100644 --- a/teavm-classlib/src/main/java/org/teavm/classlib/java/nio/TIntBuffer.java +++ b/teavm-classlib/src/main/java/org/teavm/classlib/java/nio/TIntBuffer.java @@ -64,8 +64,8 @@ public abstract class TIntBuffer extends TBuffer implements Comparable dst.length) { - throw new IndexOutOfBoundsException("The last int in dst " + (offset + length) + " is outside " + - "of array of size " + dst.length); + throw new IndexOutOfBoundsException("The last int in dst " + (offset + length) + " is outside " + + "of array of size " + dst.length); } if (remaining() < length) { throw new TBufferUnderflowException(); @@ -113,8 +113,8 @@ public abstract class TIntBuffer extends TBuffer implements Comparable src.length) { - throw new IndexOutOfBoundsException("The last int in src " + (offset + length) + " is outside " + - "of array of size " + src.length); + throw new IndexOutOfBoundsException("The last int in src " + (offset + length) + " is outside " + + "of array of size " + src.length); } if (length < 0) { throw new IndexOutOfBoundsException("Length " + length + " must be non-negative"); @@ -159,8 +159,8 @@ public abstract class TIntBuffer extends TBuffer implements Comparable= 0 ? " at " + mark : " is not set") + "]"; + return "[IntBuffer position=" + position + ", limit=" + limit + ", capacity=" + capacity + ", mark " + + (mark >= 0 ? " at " + mark : " is not set") + "]"; } @Override @@ -181,7 +181,7 @@ public abstract class TIntBuffer extends TBuffer implements Comparable> 24); - byteByffer.array[start + index * 4 + 1] = (byte)(value >> 16); - byteByffer.array[start + index * 4 + 2] = (byte)(value >> 8); - byteByffer.array[start + index * 4 + 3] = (byte)value; + byteByffer.array[start + index * 4] = (byte) (value >> 24); + byteByffer.array[start + index * 4 + 1] = (byte) (value >> 16); + byteByffer.array[start + index * 4 + 2] = (byte) (value >> 8); + byteByffer.array[start + index * 4 + 3] = (byte) value; } @Override diff --git a/teavm-classlib/src/main/java/org/teavm/classlib/java/nio/TIntBufferOverByteBufferLittleEndian.java b/teavm-classlib/src/main/java/org/teavm/classlib/java/nio/TIntBufferOverByteBufferLittleEndian.java index 6515290f2..90372caa5 100644 --- a/teavm-classlib/src/main/java/org/teavm/classlib/java/nio/TIntBufferOverByteBufferLittleEndian.java +++ b/teavm-classlib/src/main/java/org/teavm/classlib/java/nio/TIntBufferOverByteBufferLittleEndian.java @@ -33,18 +33,18 @@ class TIntBufferOverByteBufferLittleEndian extends TIntBufferOverByteBuffer { @Override int getElement(int index) { - return (byteByffer.array[start + index * 4] & 0xFF) | - ((byteByffer.array[start + index * 4 + 1] & 0xFF) << 8) | - ((byteByffer.array[start + index * 4 + 2] & 0xFF) << 16) | - ((byteByffer.array[start + index * 4 + 3] & 0xFF) << 24); + return (byteByffer.array[start + index * 4] & 0xFF) + | ((byteByffer.array[start + index * 4 + 1] & 0xFF) << 8) + | ((byteByffer.array[start + index * 4 + 2] & 0xFF) << 16) + | ((byteByffer.array[start + index * 4 + 3] & 0xFF) << 24); } @Override void putElement(int index, int value) { - byteByffer.array[start + index * 4] = (byte)value; - byteByffer.array[start + index * 4 + 1] = (byte)(value >> 8); - byteByffer.array[start + index * 4 + 2] = (byte)(value >> 16); - byteByffer.array[start + index * 4 + 3] = (byte)(value >> 24); + byteByffer.array[start + index * 4] = (byte) value; + byteByffer.array[start + index * 4 + 1] = (byte) (value >> 8); + byteByffer.array[start + index * 4 + 2] = (byte) (value >> 16); + byteByffer.array[start + index * 4 + 3] = (byte) (value >> 24); } @Override diff --git a/teavm-classlib/src/main/java/org/teavm/classlib/java/nio/TInvalidMarkException.java b/teavm-classlib/src/main/java/org/teavm/classlib/java/nio/TInvalidMarkException.java index f22be7f53..04c1ce66d 100644 --- a/teavm-classlib/src/main/java/org/teavm/classlib/java/nio/TInvalidMarkException.java +++ b/teavm-classlib/src/main/java/org/teavm/classlib/java/nio/TInvalidMarkException.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.TIllegalStateException; diff --git a/teavm-classlib/src/main/java/org/teavm/classlib/java/nio/TLongBuffer.java b/teavm-classlib/src/main/java/org/teavm/classlib/java/nio/TLongBuffer.java index f22ce0609..e4c5386e2 100644 --- a/teavm-classlib/src/main/java/org/teavm/classlib/java/nio/TLongBuffer.java +++ b/teavm-classlib/src/main/java/org/teavm/classlib/java/nio/TLongBuffer.java @@ -64,8 +64,8 @@ public abstract class TLongBuffer extends TBuffer implements Comparable dst.length) { - throw new IndexOutOfBoundsException("The last long in dst " + (offset + length) + " is outside " + - "of array of size " + dst.length); + throw new IndexOutOfBoundsException("The last long in dst " + (offset + length) + " is outside " + + "of array of size " + dst.length); } if (remaining() < length) { throw new TBufferUnderflowException(); @@ -113,8 +113,8 @@ public abstract class TLongBuffer extends TBuffer implements Comparable src.length) { - throw new IndexOutOfBoundsException("The last long in src " + (offset + length) + " is outside " + - "of array of size " + src.length); + throw new IndexOutOfBoundsException("The last long in src " + (offset + length) + " is outside " + + "of array of size " + src.length); } if (length < 0) { throw new IndexOutOfBoundsException("Length " + length + " must be non-negative"); @@ -159,8 +159,8 @@ public abstract class TLongBuffer extends TBuffer implements Comparable= 0 ? " at " + mark : " is not set") + "]"; + return "[LongBuffer position=" + position + ", limit=" + limit + ", capacity=" + capacity + ", mark " + + (mark >= 0 ? " at " + mark : " is not set") + "]"; } @Override @@ -169,7 +169,7 @@ public abstract class TLongBuffer extends TBuffer implements Comparable>> 32); + hashCode = 31 * hashCode + (int) elem + (int) (elem >>> 32); } return hashCode; } @@ -182,7 +182,7 @@ public abstract class TLongBuffer 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; } @Override diff --git a/teavm-classlib/src/main/java/org/teavm/classlib/java/nio/TLongBufferOverByteBufferLittleEndian.java b/teavm-classlib/src/main/java/org/teavm/classlib/java/nio/TLongBufferOverByteBufferLittleEndian.java index a09324bf4..f88a779ef 100644 --- a/teavm-classlib/src/main/java/org/teavm/classlib/java/nio/TLongBufferOverByteBufferLittleEndian.java +++ b/teavm-classlib/src/main/java/org/teavm/classlib/java/nio/TLongBufferOverByteBufferLittleEndian.java @@ -33,26 +33,26 @@ class TLongBufferOverByteBufferLittleEndian extends TLongBufferOverByteBuffer { @Override long getElement(int index) { - return (byteByffer.array[start + index * 8] & 0xFF) | - (((long)byteByffer.array[start + index * 8 + 1] & 0xFF) << 8) | - (((long)byteByffer.array[start + index * 8 + 2] & 0xFF) << 16) | - (((long)byteByffer.array[start + index * 8 + 3] & 0xFF) << 24) | - (((long)byteByffer.array[start + index * 8 + 4] & 0xFF) << 32) | - (((long)byteByffer.array[start + index * 8 + 5] & 0xFF) << 40) | - (((long)byteByffer.array[start + index * 8 + 6] & 0xFF) << 48) | - (((long)byteByffer.array[start + index * 8 + 7] & 0xFF) << 56); + return (byteByffer.array[start + index * 8] & 0xFF) + | (((long) byteByffer.array[start + index * 8 + 1] & 0xFF) << 8) + | (((long) byteByffer.array[start + index * 8 + 2] & 0xFF) << 16) + | (((long) byteByffer.array[start + index * 8 + 3] & 0xFF) << 24) + | (((long) byteByffer.array[start + index * 8 + 4] & 0xFF) << 32) + | (((long) byteByffer.array[start + index * 8 + 5] & 0xFF) << 40) + | (((long) byteByffer.array[start + index * 8 + 6] & 0xFF) << 48) + | (((long) byteByffer.array[start + index * 8 + 7] & 0xFF) << 56); } @Override void putElement(int index, long value) { - 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); } @Override diff --git a/teavm-classlib/src/main/java/org/teavm/classlib/java/nio/TReadOnlyBufferException.java b/teavm-classlib/src/main/java/org/teavm/classlib/java/nio/TReadOnlyBufferException.java index d99fa7ffc..4d1c4e358 100644 --- a/teavm-classlib/src/main/java/org/teavm/classlib/java/nio/TReadOnlyBufferException.java +++ b/teavm-classlib/src/main/java/org/teavm/classlib/java/nio/TReadOnlyBufferException.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.TUnsupportedOperationException; diff --git a/teavm-classlib/src/main/java/org/teavm/classlib/java/nio/TShortBuffer.java b/teavm-classlib/src/main/java/org/teavm/classlib/java/nio/TShortBuffer.java index bfd22d4c8..ab7265962 100644 --- a/teavm-classlib/src/main/java/org/teavm/classlib/java/nio/TShortBuffer.java +++ b/teavm-classlib/src/main/java/org/teavm/classlib/java/nio/TShortBuffer.java @@ -64,8 +64,8 @@ public abstract class TShortBuffer extends TBuffer implements Comparable dst.length) { - throw new IndexOutOfBoundsException("The last short in dst " + (offset + length) + " is outside " + - "of array of size " + dst.length); + throw new IndexOutOfBoundsException("The last short in dst " + (offset + length) + " is outside " + + "of array of size " + dst.length); } if (remaining() < length) { throw new TBufferUnderflowException(); @@ -113,8 +113,8 @@ public abstract class TShortBuffer extends TBuffer implements Comparable src.length) { - throw new IndexOutOfBoundsException("The last short in src " + (offset + length) + " is outside " + - "of array of size " + src.length); + throw new IndexOutOfBoundsException("The last short in src " + (offset + length) + " is outside " + + "of array of size " + src.length); } if (length < 0) { throw new IndexOutOfBoundsException("Length " + length + " must be non-negative"); @@ -159,8 +159,8 @@ public abstract class TShortBuffer extends TBuffer implements Comparable= 0 ? " at " + mark : " is not set") + "]"; + return "[ShortBuffer position=" + position + ", limit=" + limit + ", capacity=" + capacity + ", mark " + + (mark >= 0 ? " at " + mark : " is not set") + "]"; } @Override @@ -181,7 +181,7 @@ public abstract class TShortBuffer 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/TShortBufferOverByteBufferLittleEndian.java b/teavm-classlib/src/main/java/org/teavm/classlib/java/nio/TShortBufferOverByteBufferLittleEndian.java index 63521e4e4..1ab57315d 100644 --- a/teavm-classlib/src/main/java/org/teavm/classlib/java/nio/TShortBufferOverByteBufferLittleEndian.java +++ b/teavm-classlib/src/main/java/org/teavm/classlib/java/nio/TShortBufferOverByteBufferLittleEndian.java @@ -33,15 +33,15 @@ class TShortBufferOverByteBufferLittleEndian extends TShortBufferOverByteBuffer @Override short getElement(int index) { - int value = (byteByffer.array[start + index * 2] & 0xFF) | - ((byteByffer.array[start + index * 2 + 1] & 0xFF) << 8); - return (short)value; + int value = (byteByffer.array[start + index * 2] & 0xFF) + | ((byteByffer.array[start + index * 2 + 1] & 0xFF) << 8); + return (short) value; } @Override void putElement(int index, short 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/charset/TCharsetDecoder.java b/teavm-classlib/src/main/java/org/teavm/classlib/java/nio/charset/TCharsetDecoder.java index 05e86add0..a512f60a2 100644 --- a/teavm-classlib/src/main/java/org/teavm/classlib/java/nio/charset/TCharsetDecoder.java +++ b/teavm-classlib/src/main/java/org/teavm/classlib/java/nio/charset/TCharsetDecoder.java @@ -38,12 +38,12 @@ public abstract class TCharsetDecoder { protected TCharsetDecoder(TCharset cs, float averageCharsPerByte, float maxCharsPerByte) { if (averageCharsPerByte <= 0) { - throw new IllegalArgumentException("averageCharsPerByte must be positive. Actual value is " + - averageCharsPerByte); + throw new IllegalArgumentException("averageCharsPerByte must be positive. Actual value is " + + averageCharsPerByte); } if (maxCharsPerByte <= 0) { - throw new IllegalArgumentException("maxCharsPerByte must be positive. Actual value is " + - maxCharsPerByte); + throw new IllegalArgumentException("maxCharsPerByte must be positive. Actual value is " + + maxCharsPerByte); } this.charset = cs; this.averageCharsPerByte = averageCharsPerByte; @@ -191,7 +191,7 @@ public abstract class TCharsetDecoder { reset(); } - TCharBuffer out = TCharBuffer.allocate(Math.max(8, (int)(in.remaining() * averageCharsPerByte))); + TCharBuffer out = TCharBuffer.allocate(Math.max(8, (int) (in.remaining() * averageCharsPerByte))); TCoderResult result; while (true) { result = decode(in, out, false); diff --git a/teavm-classlib/src/main/java/org/teavm/classlib/java/nio/charset/TCharsetEncoder.java b/teavm-classlib/src/main/java/org/teavm/classlib/java/nio/charset/TCharsetEncoder.java index 65282e5eb..796e5309b 100644 --- a/teavm-classlib/src/main/java/org/teavm/classlib/java/nio/charset/TCharsetEncoder.java +++ b/teavm-classlib/src/main/java/org/teavm/classlib/java/nio/charset/TCharsetEncoder.java @@ -46,7 +46,7 @@ public abstract class TCharsetEncoder { } protected TCharsetEncoder(TCharset cs, float averageBytesPerChar, float maxBytesPerChar) { - this(cs, averageBytesPerChar, maxBytesPerChar, new byte[] { (byte)'?' }); + this(cs, averageBytesPerChar, maxBytesPerChar, new byte[] { (byte) '?' }); } public final TCharset charset() { @@ -160,7 +160,7 @@ public abstract class TCharsetEncoder { return TByteBuffer.allocate(0); } reset(); - TByteBuffer output = TByteBuffer.allocate((int)(in.remaining() * averageBytesPerChar)); + TByteBuffer output = TByteBuffer.allocate((int) (in.remaining() * averageBytesPerChar)); TCoderResult result; while (true) { @@ -225,7 +225,7 @@ public abstract class TCharsetEncoder { public boolean canEncode(CharSequence sequence) { TCharBuffer cb; if (sequence instanceof TCharBuffer) { - cb = ((TCharBuffer)sequence).duplicate(); + cb = ((TCharBuffer) sequence).duplicate(); } else { cb = TCharBuffer.wrap(sequence); } diff --git a/teavm-classlib/src/main/java/org/teavm/classlib/java/nio/charset/TCoderResult.java b/teavm-classlib/src/main/java/org/teavm/classlib/java/nio/charset/TCoderResult.java index 240674f1a..b6b57b80a 100644 --- a/teavm-classlib/src/main/java/org/teavm/classlib/java/nio/charset/TCoderResult.java +++ b/teavm-classlib/src/main/java/org/teavm/classlib/java/nio/charset/TCoderResult.java @@ -20,8 +20,8 @@ package org.teavm.classlib.java.nio.charset; * @author Alexey Andreev */ public class TCoderResult { - public static final TCoderResult UNDERFLOW = new TCoderResult((byte)0, 0); - public static final TCoderResult OVERFLOW = new TCoderResult((byte)1, 0); + public static final TCoderResult UNDERFLOW = new TCoderResult((byte) 0, 0); + public static final TCoderResult OVERFLOW = new TCoderResult((byte) 1, 0); private byte kind; private int length; @@ -59,11 +59,11 @@ public class TCoderResult { } public static TCoderResult malformedForLength(int length) { - return new TCoderResult((byte)2, length); + return new TCoderResult((byte) 2, length); } public static TCoderResult unmappableForLength(int length) { - return new TCoderResult((byte)3, length); + return new TCoderResult((byte) 3, length); } public void throwException() throws TCharacterCodingException { diff --git a/teavm-classlib/src/main/java/org/teavm/classlib/java/nio/charset/impl/TUTF8Decoder.java b/teavm-classlib/src/main/java/org/teavm/classlib/java/nio/charset/impl/TUTF8Decoder.java index 758f1682b..c2fd39963 100644 --- a/teavm-classlib/src/main/java/org/teavm/classlib/java/nio/charset/impl/TUTF8Decoder.java +++ b/teavm-classlib/src/main/java/org/teavm/classlib/java/nio/charset/impl/TUTF8Decoder.java @@ -34,7 +34,7 @@ public class TUTF8Decoder extends TBufferedDecoder { while (inPos < inSize && outPos < outSize) { int b = inArray[inPos++] & 0xFF; if ((b & 0x80) == 0) { - outArray[outPos++] = (char)b; + outArray[outPos++] = (char) b; } else if ((b & 0xE0) == 0xC0) { if (inPos >= inSize) { --inPos; @@ -49,7 +49,7 @@ public class TUTF8Decoder extends TBufferedDecoder { result = TCoderResult.malformedForLength(1); break; } - outArray[outPos++] = (char)(((b & 0x1F) << 6) | (b2 & 0x3F)); + outArray[outPos++] = (char) (((b & 0x1F) << 6) | (b2 & 0x3F)); } else if ((b & 0xF0) == 0xE0) { if (inPos + 2 > inSize) { --inPos; @@ -65,7 +65,7 @@ public class TUTF8Decoder extends TBufferedDecoder { result = TCoderResult.malformedForLength(1); break; } - char c = (char)(((b & 0x0F) << 12) | ((b2 & 0x3f) << 6) | (b3 & 0x3F)); + char c = (char) (((b & 0x0F) << 12) | ((b2 & 0x3f) << 6) | (b3 & 0x3F)); if (Character.isSurrogate(c)) { inPos -= 3; result = TCoderResult.malformedForLength(3); diff --git a/teavm-classlib/src/main/java/org/teavm/classlib/java/nio/charset/impl/TUTF8Encoder.java b/teavm-classlib/src/main/java/org/teavm/classlib/java/nio/charset/impl/TUTF8Encoder.java index e5dc774c7..c6c051d88 100644 --- a/teavm-classlib/src/main/java/org/teavm/classlib/java/nio/charset/impl/TUTF8Encoder.java +++ b/teavm-classlib/src/main/java/org/teavm/classlib/java/nio/charset/impl/TUTF8Encoder.java @@ -34,7 +34,7 @@ public class TUTF8Encoder extends TBufferedEncoder { while (inPos < inSize && outPos < outSize) { char ch = inArray[inPos++]; if (ch < 0x80) { - outArray[outPos++] = (byte)ch; + outArray[outPos++] = (byte) ch; } else if (ch < 0x800) { if (outPos + 2 > outSize) { --inPos; @@ -43,8 +43,8 @@ public class TUTF8Encoder extends TBufferedEncoder { } break; } - outArray[outPos++] = (byte)(0xC0 | (ch >> 6)); - outArray[outPos++] = (byte)(0x80 | (ch & 0x3F)); + outArray[outPos++] = (byte) (0xC0 | (ch >> 6)); + outArray[outPos++] = (byte) (0x80 | (ch & 0x3F)); } else if (!Character.isSurrogate(ch)) { if (outPos + 3 > outSize) { --inPos; @@ -53,9 +53,9 @@ public class TUTF8Encoder extends TBufferedEncoder { } break; } - outArray[outPos++] = (byte)(0xE0 | (ch >> 12)); - outArray[outPos++] = (byte)(0x80 | ((ch >> 6) & 0x3F)); - outArray[outPos++] = (byte)(0x80 | (ch & 0x3F)); + outArray[outPos++] = (byte) (0xE0 | (ch >> 12)); + outArray[outPos++] = (byte) (0x80 | ((ch >> 6) & 0x3F)); + outArray[outPos++] = (byte) (0x80 | (ch & 0x3F)); } else if (Character.isHighSurrogate(ch)) { if (inPos >= inSize) { if (!controller.hasMoreInput()) { @@ -77,10 +77,10 @@ public class TUTF8Encoder extends TBufferedEncoder { break; } int codePoint = Character.toCodePoint(ch, low); - outArray[outPos++] = (byte)(0xF0 | (codePoint >> 18)); - outArray[outPos++] = (byte)(0x80 | ((codePoint >> 12) & 0x3F)); - outArray[outPos++] = (byte)(0x80 | ((codePoint >> 6) & 0x3F)); - outArray[outPos++] = (byte)(0x80 | (codePoint & 0x3F)); + outArray[outPos++] = (byte) (0xF0 | (codePoint >> 18)); + outArray[outPos++] = (byte) (0x80 | ((codePoint >> 12) & 0x3F)); + outArray[outPos++] = (byte) (0x80 | ((codePoint >> 6) & 0x3F)); + outArray[outPos++] = (byte) (0x80 | (codePoint & 0x3F)); } else { result = TCoderResult.malformedForLength(1); break; diff --git a/teavm-classlib/src/main/java/org/teavm/classlib/java/text/TAnnotation.java b/teavm-classlib/src/main/java/org/teavm/classlib/java/text/TAnnotation.java index a7b28b68a..98589337f 100644 --- a/teavm-classlib/src/main/java/org/teavm/classlib/java/text/TAnnotation.java +++ b/teavm-classlib/src/main/java/org/teavm/classlib/java/text/TAnnotation.java @@ -1,20 +1,18 @@ /* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at + * Copyright 2015 Alexey Andreev. * - * 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 * - * 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. + * 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.text; public class TAnnotation { diff --git a/teavm-classlib/src/main/java/org/teavm/classlib/java/text/TAttributedCharacterIterator.java b/teavm-classlib/src/main/java/org/teavm/classlib/java/text/TAttributedCharacterIterator.java index f3baf6960..aeb1e14f9 100644 --- a/teavm-classlib/src/main/java/org/teavm/classlib/java/text/TAttributedCharacterIterator.java +++ b/teavm-classlib/src/main/java/org/teavm/classlib/java/text/TAttributedCharacterIterator.java @@ -1,20 +1,18 @@ /* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at + * Copyright 2015 Alexey Andreev. * - * 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 * - * 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. + * 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.text; import org.teavm.classlib.java.io.TSerializable; @@ -64,7 +62,7 @@ public interface TAttributedCharacterIterator extends TCharacterIterator { * * @return a set of attribute keys; may be empty. */ - public TSet getAllAttributeKeys(); + TSet getAllAttributeKeys(); /** * Returns the value stored in the attribute for the current character. If @@ -74,7 +72,7 @@ public interface TAttributedCharacterIterator extends TCharacterIterator { * @return the value of the requested attribute for the current character or * {@code null} if it was not defined. */ - public Object getAttribute(Attribute attribute); + Object getAttribute(Attribute attribute); /** * Returns a map of all attributes of the current character. If no @@ -84,7 +82,7 @@ public interface TAttributedCharacterIterator extends TCharacterIterator { * @return a map of all attributes for the current character or an empty * map. */ - public TMap getAttributes(); + TMap getAttributes(); /** * Returns the index of the last character in the run having the same @@ -92,7 +90,7 @@ public interface TAttributedCharacterIterator extends TCharacterIterator { * * @return the index of the last character of the current run. */ - public int getRunLimit(); + int getRunLimit(); /** * Returns the index of the last character in the run that has the same @@ -102,7 +100,7 @@ public interface TAttributedCharacterIterator extends TCharacterIterator { * the attribute which the run is based on. * @return the index of the last character of the current run. */ - public int getRunLimit(Attribute attribute); + int getRunLimit(Attribute attribute); /** * Returns the index of the last character in the run that has the same @@ -112,7 +110,7 @@ public interface TAttributedCharacterIterator extends TCharacterIterator { * the set of attributes which the run is based on. * @return the index of the last character of the current run. */ - public int getRunLimit(TSet attributes); + int getRunLimit(TSet attributes); /** * Returns the index of the first character in the run that has the same @@ -120,7 +118,7 @@ public interface TAttributedCharacterIterator extends TCharacterIterator { * * @return the index of the last character of the current run. */ - public int getRunStart(); + int getRunStart(); /** * Returns the index of the first character in the run that has the same @@ -130,7 +128,7 @@ public interface TAttributedCharacterIterator extends TCharacterIterator { * the attribute which the run is based on. * @return the index of the last character of the current run. */ - public int getRunStart(Attribute attribute); + int getRunStart(Attribute attribute); /** * Returns the index of the first character in the run that has the same @@ -140,5 +138,5 @@ public interface TAttributedCharacterIterator extends TCharacterIterator { * the set of attributes which the run is based on. * @return the index of the last character of the current run. */ - public int getRunStart(TSet attributes); + int getRunStart(TSet attributes); } diff --git a/teavm-classlib/src/main/java/org/teavm/classlib/java/text/TAttributedString.java b/teavm-classlib/src/main/java/org/teavm/classlib/java/text/TAttributedString.java index d59073f56..1ce5f411c 100644 --- a/teavm-classlib/src/main/java/org/teavm/classlib/java/text/TAttributedString.java +++ b/teavm-classlib/src/main/java/org/teavm/classlib/java/text/TAttributedString.java @@ -1,20 +1,18 @@ /* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at + * Copyright 2015 Alexey Andreev. * - * 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 * - * 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. + * 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.text; import org.teavm.classlib.java.text.TAttributedCharacterIterator.Attribute; @@ -42,7 +40,9 @@ public class TAttributedString { static class AttributedIterator implements TAttributedCharacterIterator { - private int begin, end, offset; + private int begin; + private int end; + private int offset; private TAttributedString attrString; @@ -393,8 +393,8 @@ public class TAttributedString { Object value = iterator.getAttribute(attribute); int runStart = iterator.getRunStart(attribute); int limit = iterator.getRunLimit(attribute); - if ((value instanceof TAnnotation && runStart >= start && limit <= end) || - (value != null && !(value instanceof TAnnotation))) { + if ((value instanceof TAnnotation && runStart >= start && limit <= end) + || (value != null && !(value instanceof TAnnotation))) { addAttribute(attribute, value, (runStart < start ? start : runStart) - start, (limit > end ? end : limit) - start); } @@ -513,7 +513,8 @@ public class TAttributedString { it.previous(); break; } else if (start < range.end || (start == range.end && value.equals(range.value))) { - Range r1 = null, r3; + Range r1 = null; + Range r3; it.remove(); r1 = new Range(range.start, start, range.value); r3 = new Range(end, range.end, range.value); @@ -575,7 +576,8 @@ public class TAttributedString { * if {@code start < 0}, {@code end} is greater than the length * of this string, or if {@code start >= end}. */ - public void addAttributes(TMap attributes, int start, int end) { + public void addAttributes(TMap attributes, + int start, int end) { TIterator it = attributes.entrySet().iterator(); while (it.hasNext()) { TMap.Entry entry = (TMap.Entry) it.next(); diff --git a/teavm-classlib/src/main/java/org/teavm/classlib/java/text/TCharacterIterator.java b/teavm-classlib/src/main/java/org/teavm/classlib/java/text/TCharacterIterator.java index 82491583e..8a0245559 100644 --- a/teavm-classlib/src/main/java/org/teavm/classlib/java/text/TCharacterIterator.java +++ b/teavm-classlib/src/main/java/org/teavm/classlib/java/text/TCharacterIterator.java @@ -1,42 +1,40 @@ /* - * 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 * - * 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. + * 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.text; public interface TCharacterIterator extends Cloneable { - public static final char DONE = '\uffff'; + char DONE = '\uffff'; - public Object clone(); + Object clone(); - public char current(); + char current(); - public char first(); + char first(); - public int getBeginIndex(); + int getBeginIndex(); - public int getEndIndex(); + int getEndIndex(); - public int getIndex(); + int getIndex(); - public char last(); + char last(); - public char next(); + char next(); - public char previous(); + char previous(); - public char setIndex(int location); + char setIndex(int location); } diff --git a/teavm-classlib/src/main/java/org/teavm/classlib/java/text/TDateFormat.java b/teavm-classlib/src/main/java/org/teavm/classlib/java/text/TDateFormat.java index dd1e607ae..5c018809a 100644 --- a/teavm-classlib/src/main/java/org/teavm/classlib/java/text/TDateFormat.java +++ b/teavm-classlib/src/main/java/org/teavm/classlib/java/text/TDateFormat.java @@ -1,20 +1,18 @@ /* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at + * Copyright 2015 Alexey Andreev. * - * 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 * - * 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. + * 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.text; import org.teavm.classlib.impl.unicode.CLDRHelper; @@ -67,9 +65,9 @@ public abstract class TDateFormat extends TFormat { return false; } TDateFormat dateFormat = (TDateFormat) object; - return calendar.getFirstDayOfWeek() == dateFormat.calendar.getFirstDayOfWeek() && - calendar.getMinimalDaysInFirstWeek() == dateFormat.calendar.getMinimalDaysInFirstWeek() && - calendar.isLenient() == dateFormat.calendar.isLenient(); + return calendar.getFirstDayOfWeek() == dateFormat.calendar.getFirstDayOfWeek() + && calendar.getMinimalDaysInFirstWeek() == dateFormat.calendar.getMinimalDaysInFirstWeek() + && calendar.isLenient() == dateFormat.calendar.isLenient(); } @Override @@ -219,8 +217,8 @@ public abstract class TDateFormat extends TFormat { @Override public int hashCode() { - return calendar.getFirstDayOfWeek() + calendar.getMinimalDaysInFirstWeek() + - (calendar.isLenient() ? 1231 : 1237); + return calendar.getFirstDayOfWeek() + calendar.getMinimalDaysInFirstWeek() + + (calendar.isLenient() ? 1231 : 1237); } public boolean isLenient() { diff --git a/teavm-classlib/src/main/java/org/teavm/classlib/java/text/TDateFormatElement.java b/teavm-classlib/src/main/java/org/teavm/classlib/java/text/TDateFormatElement.java index 403423e78..fc4fbf4c1 100644 --- a/teavm-classlib/src/main/java/org/teavm/classlib/java/text/TDateFormatElement.java +++ b/teavm-classlib/src/main/java/org/teavm/classlib/java/text/TDateFormatElement.java @@ -283,8 +283,8 @@ abstract class TDateFormatElement { if (number < 10) { buffer.append(number); } else { - buffer.append((char)((number % 100 / 10) + '0')); - buffer.append((char)((number % 10) + '0')); + buffer.append((char) ((number % 100 / 10) + '0')); + buffer.append((char) ((number % 10) + '0')); } } @@ -588,10 +588,9 @@ abstract class TDateFormatElement { } } int sign = signChar == '-' ? -1 : 1; - int hours = 10 * Character.digit(text.charAt(index), 10) + - Character.digit(text.charAt(index + 1), 10); - int minutes = 10 * Character.digit(text.charAt(index + 2), 10) + - Character.digit(text.charAt(index + 3), 10); + int hours = 10 * Character.digit(text.charAt(index), 10) + Character.digit(text.charAt(index + 1), 10); + int minutes = 10 * Character.digit(text.charAt(index + 2), 10) + + Character.digit(text.charAt(index + 3), 10); date.setTimeZone(getStaticTimeZone(sign * hours, minutes)); return true; } @@ -623,8 +622,8 @@ abstract class TDateFormatElement { } ++index; - if (index + 2 > text.length() || !Character.isDigit(text.charAt(index)) || - !Character.isDigit(text.charAt(index + 1))) { + if (index + 2 > text.length() || !Character.isDigit(text.charAt(index)) + || !Character.isDigit(text.charAt(index + 1))) { position.setErrorIndex(index); return; } @@ -635,8 +634,8 @@ abstract class TDateFormatElement { } static TTimeZone getStaticTimeZone(int hours, int minutes) { - return TTimeZone.getTimeZone("GMT" + (hours > 0 ? '+' : '-') + Math.abs(hours) + - ":" + (minutes / 10) + (minutes % 10)); + return TTimeZone.getTimeZone("GMT" + (hours > 0 ? '+' : '-') + Math.abs(hours) + + ":" + (minutes / 10) + (minutes % 10)); } static class TrieNode { diff --git a/teavm-classlib/src/main/java/org/teavm/classlib/java/text/TDateFormatSymbols.java b/teavm-classlib/src/main/java/org/teavm/classlib/java/text/TDateFormatSymbols.java index 4d384c103..69c7e83a6 100644 --- a/teavm-classlib/src/main/java/org/teavm/classlib/java/text/TDateFormatSymbols.java +++ b/teavm-classlib/src/main/java/org/teavm/classlib/java/text/TDateFormatSymbols.java @@ -1,18 +1,17 @@ /* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at + * Copyright 2014 Alexey Andreev. * - * 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 * - * 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. + * 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.text; @@ -25,7 +24,12 @@ import org.teavm.classlib.java.util.TLocale; public class TDateFormatSymbols implements TSerializable, TCloneable { private TLocale locale; private String localPatternChars; - String[] ampms, eras, months, shortMonths, shortWeekdays, weekdays; + String[] ampms; + String[] eras; + String[] months; + String[] shortMonths; + String[] shortWeekdays; + String[] weekdays; String[][] zoneStrings; diff --git a/teavm-classlib/src/main/java/org/teavm/classlib/java/text/TDecimalFormat.java b/teavm-classlib/src/main/java/org/teavm/classlib/java/text/TDecimalFormat.java index 1f9e09f87..33696f21e 100644 --- a/teavm-classlib/src/main/java/org/teavm/classlib/java/text/TDecimalFormat.java +++ b/teavm-classlib/src/main/java/org/teavm/classlib/java/text/TDecimalFormat.java @@ -38,7 +38,7 @@ public class TDecimalFormat extends TNumberFormat { private static final double[] POW10_FRAC_ARRAY = { 1E1, 1E2, 1E4, 1E8, 1E16, 1E32, 1E64, 1E128, 1E256 }; private static final double[] POWM10_FRAC_ARRAY = { 1E-1, 1E-2, 1E-4, 1E-8, 1E-16, 1E-32, 1E-64, 1E-128, 1E-256 }; private static final int DOUBLE_MAX_EXPONENT = 308; - private static long MAX_LONG_DIV_10 = Long.MAX_VALUE / 10; + private static final long MAX_LONG_DIV_10 = Long.MAX_VALUE / 10; TDecimalFormatSymbols symbols; FormatField[] positivePrefix = {}; FormatField[] negativePrefix = { new TextField("-") }; @@ -59,7 +59,7 @@ public class TDecimalFormat extends TNumberFormat { } public TDecimalFormat(String pattern, TDecimalFormatSymbols value) { - symbols = (TDecimalFormatSymbols)value.clone(); + symbols = (TDecimalFormatSymbols) value.clone(); applyPattern(pattern); } @@ -70,7 +70,7 @@ public class TDecimalFormat extends TNumberFormat { } public DecimalFormatSymbols getDecimalFormatSymbols() { - return (DecimalFormatSymbols)symbols.clone(); + return (DecimalFormatSymbols) symbols.clone(); } private StringBuffer fieldsToText(FormatField[] fields, StringBuffer buffer) { @@ -168,19 +168,19 @@ public class TDecimalFormat extends TNumberFormat { if (!(obj instanceof TDecimalFormat)) { return false; } - TDecimalFormat other = (TDecimalFormat)obj; + TDecimalFormat other = (TDecimalFormat) obj; if (!super.equals(obj)) { return false; } - return positivePrefix.equals(other.positivePrefix) && - positiveSuffix.equals(other.positiveSuffix) && - negativePrefix.equals(other.negativePrefix) && - negativeSuffix.equals(other.negativeSuffix) && - multiplier == other.multiplier && - groupingSize == other.groupingSize && - decimalSeparatorAlwaysShown == other.decimalSeparatorAlwaysShown && - parseBigDecimal == other.parseBigDecimal && - exponentDigits == other.exponentDigits; + return positivePrefix.equals(other.positivePrefix) + && positiveSuffix.equals(other.positiveSuffix) + && negativePrefix.equals(other.negativePrefix) + && negativeSuffix.equals(other.negativeSuffix) + && multiplier == other.multiplier + && groupingSize == other.groupingSize + && decimalSeparatorAlwaysShown == other.decimalSeparatorAlwaysShown + && parseBigDecimal == other.parseBigDecimal + && exponentDigits == other.exponentDigits; } @Override @@ -503,9 +503,9 @@ public class TDecimalFormat extends TNumberFormat { @Override public StringBuffer format(Object object, StringBuffer buffer, TFieldPosition field) { if (object instanceof BigDecimal) { - return format((BigDecimal)object, buffer, field); + return format((BigDecimal) object, buffer, field); } else if (object instanceof BigInteger) { - return format((BigInteger)object, buffer, field); + return format((BigInteger) object, buffer, field); } else { return super.format(object, buffer, field); } @@ -608,7 +608,7 @@ public class TDecimalFormat extends TNumberFormat { int exponentPos = Math.max(visibleExponent, 0); for (int i = mantissaLength - 1; i >= exponentPos; --i) { long mantissaDigitMask = POW10_ARRAY[i]; - buffer.append(forDigit(Math.abs((int)(mantissa / mantissaDigitMask)))); + buffer.append(forDigit(Math.abs((int) (mantissa / mantissaDigitMask)))); mantissa %= mantissaDigitMask; } for (int i = exponentPos - 1; i >= visibleExponent; --i) { @@ -624,7 +624,7 @@ public class TDecimalFormat extends TNumberFormat { int count = 0; for (int i = visibleExponent - 1; i >= limit; --i) { long mantissaDigitMask = POW10_ARRAY[i]; - buffer.append(forDigit(Math.abs((int)(mantissa / mantissaDigitMask)))); + buffer.append(forDigit(Math.abs((int) (mantissa / mantissaDigitMask)))); mantissa %= mantissaDigitMask; ++count; if (mantissa == 0) { @@ -698,7 +698,7 @@ public class TDecimalFormat extends TNumberFormat { int mantissaDigit = mantissaLength - 1; for (int i = 0; i < significantIntDigits; ++i) { long mantissaDigitMask = POW10_ARRAY[mantissaDigit--]; - buffer.append(forDigit(Math.abs((int)(mantissa / mantissaDigitMask)))); + buffer.append(forDigit(Math.abs((int) (mantissa / mantissaDigitMask)))); mantissa %= mantissaDigitMask; if (groupingSize > 0 && digitPos % groupingSize == 0 && digitPos > 0) { buffer.append(symbols.getGroupingSeparator()); @@ -746,7 +746,7 @@ public class TDecimalFormat extends TNumberFormat { } ++digitPos; long mantissaDigitMask = POW10_ARRAY[mantissaDigit]; - buffer.append(forDigit(Math.abs((int)(mantissa / mantissaDigitMask)))); + buffer.append(forDigit(Math.abs((int) (mantissa / mantissaDigitMask)))); mantissa %= mantissaDigitMask; mantissaDigit--; } @@ -848,8 +848,8 @@ public class TDecimalFormat extends TNumberFormat { fieldsToText(positiveSuffix, buffer); } } else { - fieldsToText(negativeSuffix != null ? negativeSuffix : - positiveSuffix != null ? positiveSuffix : new FormatField[0], buffer); + fieldsToText(negativeSuffix != null ? negativeSuffix + : positiveSuffix != null ? positiveSuffix : new FormatField[0], buffer); } } @@ -1174,7 +1174,7 @@ public class TDecimalFormat extends TNumberFormat { } bit >>= 1; } - mantissa = (long)(((value / digit) * mantissaPattern) + 0.5); + mantissa = (long) (((value / digit) * mantissaPattern) + 0.5); } else { int bit = 256; exp = 0; @@ -1187,14 +1187,14 @@ public class TDecimalFormat extends TNumberFormat { bit >>= 1; } exp = -exp; - mantissa = (long)(((value * mantissaPattern) / digit) + 0.5); + mantissa = (long) (((value * mantissaPattern) / digit) + 0.5); } mantissa = ((mantissa + 500) / 1000) * 1000; return new MantissaAndExponent(positive ? mantissa : -mantissa, exp); } private char forDigit(int n) { - return (char)(symbols.getZeroDigit() + n); + return (char) (symbols.getZeroDigit() + n); } static class MantissaAndExponent { diff --git a/teavm-classlib/src/main/java/org/teavm/classlib/java/text/TDecimalFormatParser.java b/teavm-classlib/src/main/java/org/teavm/classlib/java/text/TDecimalFormatParser.java index 49858f860..b963ffa7c 100644 --- a/teavm-classlib/src/main/java/org/teavm/classlib/java/text/TDecimalFormatParser.java +++ b/teavm-classlib/src/main/java/org/teavm/classlib/java/text/TDecimalFormatParser.java @@ -81,8 +81,8 @@ class TDecimalFormatParser { format.negativeSuffix = negativeSuffix != null ? negativeSuffix : positiveSuffix; format.setGroupingSize(groupSize); format.setGroupingUsed(groupSize > 0); - format.setMinimumIntegerDigits(!decimalSeparatorRequired ? minimumIntLength : - Math.max(1, minimumIntLength)); + format.setMinimumIntegerDigits(!decimalSeparatorRequired ? minimumIntLength + : Math.max(1, minimumIntLength)); format.setMaximumIntegerDigits(intLength); format.setMinimumFractionDigits(minimumFracLength); format.setMaximumFractionDigits(fracLength); @@ -100,26 +100,26 @@ class TDecimalFormatParser { case '#': case '0': if (suffix) { - throw new IllegalArgumentException("Prefix contains special character at " + index + " in " + - string); + throw new IllegalArgumentException("Prefix contains special character at " + index + " in " + + string); } break loop; case ';': if (end) { - throw new IllegalArgumentException("Prefix contains special character at " + index + " in " + - string); + throw new IllegalArgumentException("Prefix contains special character at " + index + " in " + + string); } break loop; case '.': case 'E': - throw new IllegalArgumentException("Prefix contains special character at " + index + " in " + - string); + throw new IllegalArgumentException("Prefix contains special character at " + index + " in " + + string); case '\'': { ++index; int next = string.indexOf('\'', index); if (next < 0) { - throw new IllegalArgumentException("Quote opened at " + index + " was not closed in " + - string); + throw new IllegalArgumentException("Quote opened at " + index + " was not closed in " + + string); } if (next == index) { sb.append('\''); @@ -199,8 +199,8 @@ class TDecimalFormatParser { switch (string.charAt(index)) { case '#': if (!optionalDigits) { - throw new IllegalArgumentException("Unexpected '#' at non-optional digit part at " + index + - " in " + string); + throw new IllegalArgumentException("Unexpected '#' at non-optional digit part at " + index + + " in " + string); } ++length; break; @@ -224,8 +224,8 @@ class TDecimalFormatParser { ++index; } if (length == 0) { - throw new IllegalArgumentException("Pattern does not specify integer digits at " + index + - " in " + string); + throw new IllegalArgumentException("Pattern does not specify integer digits at " + index + + " in " + string); } if (lastGroup == index) { throw new IllegalArgumentException("Group separator at the end of number at " + index + " in " + string); @@ -250,19 +250,19 @@ class TDecimalFormatParser { optionalDigits = true; break; case ',': - throw new IllegalArgumentException("Group separator found at fractional part at " + index + - " in " + string); + throw new IllegalArgumentException("Group separator found at fractional part at " + index + + " in " + string); case '0': if (optionalDigits) { - throw new IllegalArgumentException("Unexpected '0' at optional digit part at " + index + - " in " + string); + throw new IllegalArgumentException("Unexpected '0' at optional digit part at " + index + + " in " + string); } ++length; ++minimumLength; break; case '.': - throw new IllegalArgumentException("Unexpected second decimal separator at " + index + - " in " + string); + throw new IllegalArgumentException("Unexpected second decimal separator at " + index + + " in " + string); default: break loop; } @@ -283,8 +283,7 @@ class TDecimalFormatParser { case ',': case '.': case 'E': - throw new IllegalArgumentException("Unexpected char at exponent at " + index + - " in " + string); + throw new IllegalArgumentException("Unexpected char at exponent at " + index + " in " + string); case '0': ++length; break; @@ -294,8 +293,8 @@ class TDecimalFormatParser { ++index; } if (length == 0) { - throw new IllegalArgumentException("Pattern does not specify exponent digits at " + index + - " in " + string); + throw new IllegalArgumentException("Pattern does not specify exponent digits at " + index + + " in " + string); } if (apply) { exponentLength = length; diff --git a/teavm-classlib/src/main/java/org/teavm/classlib/java/text/TDecimalFormatSymbols.java b/teavm-classlib/src/main/java/org/teavm/classlib/java/text/TDecimalFormatSymbols.java index 6c8d1bdc1..237cc7582 100644 --- a/teavm-classlib/src/main/java/org/teavm/classlib/java/text/TDecimalFormatSymbols.java +++ b/teavm-classlib/src/main/java/org/teavm/classlib/java/text/TDecimalFormatSymbols.java @@ -15,8 +15,8 @@ */ package org.teavm.classlib.java.text; -import org.teavm.classlib.impl.unicode.DecimalData; import org.teavm.classlib.impl.unicode.CLDRHelper; +import org.teavm.classlib.impl.unicode.DecimalData; import org.teavm.classlib.java.util.TLocale; /** @@ -32,7 +32,7 @@ public class TDecimalFormatSymbols implements Cloneable { private char percent; private char digit; private char patternSeparator; - private String NaN; + private String nan; private String infinity; private char minusSign; private char monetaryDecimalSeparator; @@ -50,16 +50,16 @@ public class TDecimalFormatSymbols implements Cloneable { private void initData() { DecimalData data = CLDRHelper.resolveDecimalData(locale.getLanguage(), locale.getCountry()); zeroDigit = '0'; - groupingSeparator = (char)data.getGroupingSeparator(); - decimalSeparator = (char)data.getDecimalSeparator(); - perMill = (char)data.getPerMille(); - percent = (char)data.getPercent(); + groupingSeparator = (char) data.getGroupingSeparator(); + decimalSeparator = (char) data.getDecimalSeparator(); + perMill = (char) data.getPerMille(); + percent = (char) data.getPercent(); digit = '#'; patternSeparator = ';'; - NaN = data.getNaN(); + nan = data.getNaN(); infinity = data.getInfinity(); - minusSign = (char)data.getMinusSign(); - monetaryDecimalSeparator = (char)data.getDecimalSeparator(); + minusSign = (char) data.getMinusSign(); + monetaryDecimalSeparator = (char) data.getDecimalSeparator(); exponentSeparator = data.getExponentSeparator(); } @@ -136,11 +136,11 @@ public class TDecimalFormatSymbols implements Cloneable { } public String getNaN() { - return NaN; + return nan; } public void setNaN(String naN) { - NaN = naN; + nan = naN; } public String getInfinity() { diff --git a/teavm-classlib/src/main/java/org/teavm/classlib/java/text/TFieldPosition.java b/teavm-classlib/src/main/java/org/teavm/classlib/java/text/TFieldPosition.java index 72e06628e..35898fa5f 100644 --- a/teavm-classlib/src/main/java/org/teavm/classlib/java/text/TFieldPosition.java +++ b/teavm-classlib/src/main/java/org/teavm/classlib/java/text/TFieldPosition.java @@ -1,24 +1,24 @@ /* - * 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 * - * 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. + * 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.text; public class TFieldPosition { - private int myField, beginIndex, endIndex; + private int myField; + private int beginIndex; + private int endIndex; private TFormat.Field myAttribute; public TFieldPosition(int field) { @@ -36,7 +36,8 @@ public class TFieldPosition { } void clear() { - beginIndex = endIndex = 0; + beginIndex = 0; + endIndex = 0; } @Override @@ -45,8 +46,8 @@ public class TFieldPosition { return false; } TFieldPosition pos = (TFieldPosition) object; - return myField == pos.myField && myAttribute == pos.myAttribute && beginIndex == pos.beginIndex && - endIndex == pos.endIndex; + return myField == pos.myField && myAttribute == pos.myAttribute && beginIndex == pos.beginIndex + && endIndex == pos.endIndex; } public int getBeginIndex() { @@ -81,7 +82,7 @@ public class TFieldPosition { @Override public String toString() { - return getClass().getName() + "[attribute=" + myAttribute + ", field=" + myField + ", beginIndex=" + - beginIndex + ", endIndex=" + endIndex + "]"; + return getClass().getName() + "[attribute=" + myAttribute + ", field=" + myField + ", beginIndex=" + + beginIndex + ", endIndex=" + endIndex + "]"; } } diff --git a/teavm-classlib/src/main/java/org/teavm/classlib/java/text/TFormat.java b/teavm-classlib/src/main/java/org/teavm/classlib/java/text/TFormat.java index 6ece84c18..1c2ba3ccb 100644 --- a/teavm-classlib/src/main/java/org/teavm/classlib/java/text/TFormat.java +++ b/teavm-classlib/src/main/java/org/teavm/classlib/java/text/TFormat.java @@ -1,20 +1,18 @@ /* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at + * Copyright 2015 Alexey Andreev. * - * 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 * - * 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. + * 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.text; import org.teavm.classlib.java.io.TSerializable; @@ -46,7 +44,8 @@ public abstract class TFormat implements TSerializable, TCloneable { if (next == '\'') { quote = !quote; } - if (!quote && (index = fromChars.indexOf(next)) != -1) { + index = fromChars.indexOf(next); + if (!quote && index != -1) { output.append(toChars.charAt(index)); } else if (check && !quote && ((next >= 'a' && next <= 'z') || (next >= 'A' && next <= 'Z'))) { throw new IllegalArgumentException("Invalid pattern char" + next + " in " + template); @@ -82,8 +81,10 @@ public abstract class TFormat implements TSerializable, TCloneable { public abstract Object parseObject(String string, TParsePosition position); static boolean upTo(String string, TParsePosition position, StringBuffer buffer, char stop) { - int index = position.getIndex(), length = string.length(); - boolean lastQuote = false, quote = false; + int index = position.getIndex(); + int length = string.length(); + boolean lastQuote = false; + boolean quote = false; while (index < length) { char ch = string.charAt(index++); if (ch == '\'') { @@ -105,7 +106,9 @@ public abstract class TFormat implements TSerializable, TCloneable { } static boolean upToWithQuotes(String string, TParsePosition position, StringBuffer buffer, char stop, char start) { - int index = position.getIndex(), length = string.length(), count = 1; + int index = position.getIndex(); + int length = string.length(); + int count = 1; boolean quote = false; while (index < length) { char ch = string.charAt(index++); diff --git a/teavm-classlib/src/main/java/org/teavm/classlib/java/text/TNumberFormat.java b/teavm-classlib/src/main/java/org/teavm/classlib/java/text/TNumberFormat.java index effadfc73..85cc74b39 100644 --- a/teavm-classlib/src/main/java/org/teavm/classlib/java/text/TNumberFormat.java +++ b/teavm-classlib/src/main/java/org/teavm/classlib/java/text/TNumberFormat.java @@ -28,9 +28,12 @@ import org.teavm.classlib.java.util.TLocale; public abstract class TNumberFormat extends TFormat { public static final int INTEGER_FIELD = 0; public static final int FRACTION_FIELD = 1; - private boolean groupingUsed = true, parseIntegerOnly; - private int maximumIntegerDigits = 40, minimumIntegerDigits = 1, - maximumFractionDigits = 3, minimumFractionDigits = 0; + private boolean groupingUsed = true; + private boolean parseIntegerOnly; + private int maximumIntegerDigits = 40; + private int minimumIntegerDigits = 1; + private int maximumFractionDigits = 3; + private int minimumFractionDigits; private TRoundingMode roundingMode = TRoundingMode.HALF_EVEN; TCurrency currency = TCurrency.getInstance(TLocale.getDefault()); @@ -167,8 +170,8 @@ public abstract class TNumberFormat extends TFormat { public int hashCode() { return (groupingUsed ? 1231 : 1237) + (parseIntegerOnly ? 1231 : 1237) + maximumFractionDigits + maximumIntegerDigits - + minimumFractionDigits + minimumIntegerDigits + - roundingMode.hashCode() + Objects.hashCode(currency); + + minimumFractionDigits + minimumIntegerDigits + + roundingMode.hashCode() + Objects.hashCode(currency); } public boolean isGroupingUsed() { diff --git a/teavm-classlib/src/main/java/org/teavm/classlib/java/text/TParseException.java b/teavm-classlib/src/main/java/org/teavm/classlib/java/text/TParseException.java index 3d7478d34..9eac8bfda 100644 --- a/teavm-classlib/src/main/java/org/teavm/classlib/java/text/TParseException.java +++ b/teavm-classlib/src/main/java/org/teavm/classlib/java/text/TParseException.java @@ -1,20 +1,18 @@ /* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at + * Copyright 2015 Alexey Andreev. * - * 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 * - * 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. + * 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.text; /** diff --git a/teavm-classlib/src/main/java/org/teavm/classlib/java/text/TParsePosition.java b/teavm-classlib/src/main/java/org/teavm/classlib/java/text/TParsePosition.java index e20c31e94..6397c042b 100644 --- a/teavm-classlib/src/main/java/org/teavm/classlib/java/text/TParsePosition.java +++ b/teavm-classlib/src/main/java/org/teavm/classlib/java/text/TParsePosition.java @@ -1,25 +1,23 @@ /* - * 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 * - * 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. + * 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.text; public class TParsePosition { - - private int currentPosition, errorIndex = -1; + private int currentPosition; + private int errorIndex = -1; public TParsePosition(int index) { currentPosition = index; diff --git a/teavm-classlib/src/main/java/org/teavm/classlib/java/text/TSimpleDateFormat.java b/teavm-classlib/src/main/java/org/teavm/classlib/java/text/TSimpleDateFormat.java index 4c4509c1f..03e212f8f 100644 --- a/teavm-classlib/src/main/java/org/teavm/classlib/java/text/TSimpleDateFormat.java +++ b/teavm-classlib/src/main/java/org/teavm/classlib/java/text/TSimpleDateFormat.java @@ -50,7 +50,7 @@ public class TSimpleDateFormat extends TDateFormat { } public TSimpleDateFormat(String pattern, TDateFormatSymbols dateFormatSymbols) { - this.dateFormatSymbols = (TDateFormatSymbols)dateFormatSymbols.clone(); + this.dateFormatSymbols = (TDateFormatSymbols) dateFormatSymbols.clone(); locale = TLocale.getDefault(); applyPattern(pattern); } @@ -79,7 +79,7 @@ public class TSimpleDateFormat extends TDateFormat { @Override public TDate parse(String string, TParsePosition position) { - TCalendar calendar = (TCalendar)this.calendar.clone(); + TCalendar calendar = (TCalendar) this.calendar.clone(); calendar.clear(); for (TDateFormatElement element : elements) { if (position.getIndex() > string.length()) { @@ -96,18 +96,18 @@ public class TSimpleDateFormat extends TDateFormat { @Override public Object clone() { - TSimpleDateFormat copy = (TSimpleDateFormat)super.clone(); - copy.dateFormatSymbols = (TDateFormatSymbols)dateFormatSymbols.clone(); + TSimpleDateFormat copy = (TSimpleDateFormat) super.clone(); + copy.dateFormatSymbols = (TDateFormatSymbols) dateFormatSymbols.clone(); copy.elements = elements.clone(); return copy; } public TDateFormatSymbols getDateFormatSymbols() { - return (TDateFormatSymbols)dateFormatSymbols.clone(); + return (TDateFormatSymbols) dateFormatSymbols.clone(); } public void setDateFormatSymbols(TDateFormatSymbols newFormatSymbols) { - dateFormatSymbols = (TDateFormatSymbols)newFormatSymbols.clone(); + dateFormatSymbols = (TDateFormatSymbols) newFormatSymbols.clone(); reparsePattern(); } diff --git a/teavm-classlib/src/main/java/org/teavm/classlib/java/util/TAbstractCollection.java b/teavm-classlib/src/main/java/org/teavm/classlib/java/util/TAbstractCollection.java index 91acd1708..f82bc39fd 100644 --- a/teavm-classlib/src/main/java/org/teavm/classlib/java/util/TAbstractCollection.java +++ b/teavm-classlib/src/main/java/org/teavm/classlib/java/util/TAbstractCollection.java @@ -59,7 +59,7 @@ public abstract class TAbstractCollection extends TObject implements TCollect public T[] toArray(T[] a) { int size = size(); if (a.length < size) { - a = (T[])Array.newInstance(a.getClass().getComponentType(), size); + a = (T[]) Array.newInstance(a.getClass().getComponentType(), size); } else { for (int i = size; i < a.length; ++i) { a[i] = null; @@ -67,7 +67,7 @@ public abstract class TAbstractCollection extends TObject implements TCollect } int i = 0; for (TIterator iter = iterator(); iter.hasNext();) { - a[i++] = (T)iter.next(); + a[i++] = (T) iter.next(); } return a; } diff --git a/teavm-classlib/src/main/java/org/teavm/classlib/java/util/TAbstractList.java b/teavm-classlib/src/main/java/org/teavm/classlib/java/util/TAbstractList.java index 1b2efe4d1..9ab3c8a97 100644 --- a/teavm-classlib/src/main/java/org/teavm/classlib/java/util/TAbstractList.java +++ b/teavm-classlib/src/main/java/org/teavm/classlib/java/util/TAbstractList.java @@ -178,7 +178,7 @@ public abstract class TAbstractList extends TAbstractCollection implements return false; } @SuppressWarnings("unchecked") - TList list = (TList)other; + TList list = (TList) other; if (size() != list.size()) { return false; } diff --git a/teavm-classlib/src/main/java/org/teavm/classlib/java/util/TAbstractMap.java b/teavm-classlib/src/main/java/org/teavm/classlib/java/util/TAbstractMap.java index 1d8f7e9bd..fff0b21ab 100644 --- a/teavm-classlib/src/main/java/org/teavm/classlib/java/util/TAbstractMap.java +++ b/teavm-classlib/src/main/java/org/teavm/classlib/java/util/TAbstractMap.java @@ -36,7 +36,7 @@ public abstract class TAbstractMap extends TObject implements TMap { this.value = value; } - public SimpleEntry(TMap.Entry entry) { + public SimpleEntry(TMap.Entry entry) { this(entry.getKey(), entry.getValue()); } @@ -62,7 +62,7 @@ public abstract class TAbstractMap extends TObject implements TMap { if (!(obj instanceof TMap.Entry)) { return false; } - TMap.Entry other = (TMap.Entry)obj; + TMap.Entry other = (TMap.Entry) obj; if (getKey() == null ? other.getKey() != null : !getKey().equals(other.getKey())) { return false; } @@ -89,7 +89,7 @@ public abstract class TAbstractMap extends TObject implements TMap { this.value = value; } - public SimpleImmutableEntry(TMap.Entry entry) { + public SimpleImmutableEntry(TMap.Entry entry) { this(entry.getKey(), entry.getValue()); } @@ -113,7 +113,7 @@ public abstract class TAbstractMap extends TObject implements TMap { if (!(obj instanceof TMap.Entry)) { return false; } - TMap.Entry other = (TMap.Entry)obj; + TMap.Entry other = (TMap.Entry) obj; if (getKey() == null ? other.getKey() != null : !getKey().equals(other.getKey())) { return false; } @@ -186,7 +186,7 @@ public abstract class TAbstractMap extends TObject implements TMap { } @Override - public void putAll(TMap m) { + public void putAll(TMap m) { for (TIterator> iter = m.entrySet().iterator(); iter.hasNext();) { TMap.Entry entry = iter.next(); @@ -207,7 +207,7 @@ public abstract class TAbstractMap extends TObject implements TMap { } @Override - public abstract TSet> entrySet(); + public abstract TSet> entrySet(); @Override public void clear() { @@ -239,7 +239,7 @@ public abstract class TAbstractMap extends TObject implements TMap { return false; } @SuppressWarnings("unchecked") - TMap other = (TMap)obj; + TMap other = (TMap) obj; if (size() != other.size()) { return false; } @@ -267,7 +267,7 @@ public abstract class TAbstractMap extends TObject implements TMap { @Override protected Object clone() throws TCloneNotSupportedException { - TAbstractMap copy = (TAbstractMap)super.clone(); + TAbstractMap copy = (TAbstractMap) super.clone(); copy.cachedKeySet = null; copy.cachedValues = null; return copy; diff --git a/teavm-classlib/src/main/java/org/teavm/classlib/java/util/TArrayDeque.java b/teavm-classlib/src/main/java/org/teavm/classlib/java/util/TArrayDeque.java index e5886b777..7a9abb92f 100644 --- a/teavm-classlib/src/main/java/org/teavm/classlib/java/util/TArrayDeque.java +++ b/teavm-classlib/src/main/java/org/teavm/classlib/java/util/TArrayDeque.java @@ -113,7 +113,7 @@ public class TArrayDeque extends TAbstractCollection implements TDeque return null; } @SuppressWarnings("unchecked") - E result = (E)array[head]; + E result = (E) array[head]; array[head] = null; head++; if (head >= array.length) { @@ -133,7 +133,7 @@ public class TArrayDeque extends TAbstractCollection implements TDeque tail = array.length - 1; } @SuppressWarnings("unchecked") - E result = (E)array[tail]; + E result = (E) array[tail]; array[tail] = null; ++version; return result; @@ -160,13 +160,13 @@ public class TArrayDeque extends TAbstractCollection implements TDeque @Override @SuppressWarnings("unchecked") public E peekFirst() { - return !isEmpty() ? (E)array[head] : null; + return !isEmpty() ? (E) array[head] : null; } @Override @SuppressWarnings("unchecked") public E peekLast() { - return !isEmpty() ? (E)array[tail > 0 ? tail - 1 : array.length - 1] : null; + return !isEmpty() ? (E) array[tail > 0 ? tail - 1 : array.length - 1] : null; } @Override @@ -292,7 +292,7 @@ public class TArrayDeque extends TAbstractCollection implements TDeque } lastIndex = index; @SuppressWarnings("unchecked") - E result = (E)array[index++]; + E result = (E) array[index++]; if (index >= array.length) { index = 0; wrapped = true; @@ -327,7 +327,7 @@ public class TArrayDeque extends TAbstractCollection implements TDeque } lastIndex = index; @SuppressWarnings("unchecked") - E result = (E)array[index]; + E result = (E) array[index]; return result; } @Override public void remove() { diff --git a/teavm-classlib/src/main/java/org/teavm/classlib/java/util/TArrayList.java b/teavm-classlib/src/main/java/org/teavm/classlib/java/util/TArrayList.java index 64702736c..e72dbe8e7 100644 --- a/teavm-classlib/src/main/java/org/teavm/classlib/java/util/TArrayList.java +++ b/teavm-classlib/src/main/java/org/teavm/classlib/java/util/TArrayList.java @@ -35,7 +35,7 @@ public class TArrayList extends TAbstractList implements TCloneable, TSeri @SuppressWarnings("unchecked") public TArrayList(int initialCapacity) { - array = (E[])new Object[initialCapacity]; + array = (E[]) new Object[initialCapacity]; } public TArrayList(TCollection c) { diff --git a/teavm-classlib/src/main/java/org/teavm/classlib/java/util/TArrays.java b/teavm-classlib/src/main/java/org/teavm/classlib/java/util/TArrays.java index 0817a1dc4..a4582893c 100644 --- a/teavm-classlib/src/main/java/org/teavm/classlib/java/util/TArrays.java +++ b/teavm-classlib/src/main/java/org/teavm/classlib/java/util/TArrays.java @@ -99,7 +99,7 @@ public class TArrays extends TObject { public static T[] copyOf(T[] original, int newLength) { @SuppressWarnings("unchecked") - T[] result = (T[])Array.newInstance(original.getClass().getComponentType(), newLength); + T[] result = (T[]) Array.newInstance(original.getClass().getComponentType(), newLength); int sz = TMath.min(newLength, original.length); for (int i = 0; i < sz; ++i) { result[i] = original[i]; @@ -110,10 +110,10 @@ public class TArrays extends TObject { @SuppressWarnings("unchecked") public static T[] copyOf(U[] original, int newLength, TClass cls) { TClass componentType = cls.getComponentType(); - T[] result = (T[])(Object)TArray.newInstance(componentType, newLength); + T[] result = (T[]) (Object) TArray.newInstance(componentType, newLength); int sz = TMath.min(newLength, original.length); for (int i = 0; i < sz; ++i) { - result[i] = (T)componentType.cast(TObject.wrap(original[i])); + result[i] = (T) componentType.cast(TObject.wrap(original[i])); } return result; } @@ -184,7 +184,7 @@ public class TArrays extends TObject { public static T[] copyOfRange(T[] original, int from, int to) { @SuppressWarnings("unchecked") - T[] result = (T[])Array.newInstance(original.getClass().getComponentType(), to - from); + T[] result = (T[]) Array.newInstance(original.getClass().getComponentType(), to - from); for (int i = from; i < to; ++i) { result[i - from] = original[i]; } @@ -194,9 +194,9 @@ public class TArrays extends TObject { @SuppressWarnings("unchecked") public static T[] copyOfRange(U[] original, int from, int to, TClass newType) { TClass componentType = newType.getComponentType(); - T[] result = (T[])(Object)TArray.newInstance(componentType, to - from); + T[] result = (T[]) (Object) TArray.newInstance(componentType, to - from); for (int i = from; i < to; ++i) { - result[i - from] = (T)newType.getComponentType().cast(TObject.wrap(original[i])); + result[i - from] = (T) newType.getComponentType().cast(TObject.wrap(original[i])); } return result; } @@ -881,9 +881,9 @@ public class TArrays extends TObject { @SuppressWarnings({ "rawtypes", "unchecked" }) @Override public int compare(Object o1, Object o2) { if (o1 != null) { - return ((TComparable)o1).compareTo(o2); + return ((TComparable) o1).compareTo(o2); } else if (o2 != null) { - return ((TComparable)o2).compareTo(o1); + return ((TComparable) o2).compareTo(o1); } else { return 0; } @@ -892,7 +892,7 @@ public class TArrays extends TObject { public static void sort(T[] a, int fromIndex, int toIndex, TComparator c) { @SuppressWarnings("unchecked") - T[] subarray = (T[])new Object[toIndex - fromIndex]; + T[] subarray = (T[]) new Object[toIndex - fromIndex]; for (int i = fromIndex; i < toIndex; ++i) { subarray[i - fromIndex] = a[i]; } @@ -913,7 +913,7 @@ public class TArrays extends TObject { while (chunkSize < a.length) { for (int i = 0; i < first.length; i += chunkSize * 2) { merge(first, second, i, Math.min(first.length, i + chunkSize), - Math.min(first.length, i + 2 * chunkSize), (TComparator)c); + Math.min(first.length, i + 2 * chunkSize), (TComparator) c); } Object[] tmp = first; first = second; @@ -1348,7 +1348,7 @@ public class TArrays extends TObject { } int hash = 0xA5A537FC; for (int i = 0; i < a.length; ++i) { - int h = (int)(a[i] >>> 32) ^ (int)a[i]; + int h = (int) (a[i] >>> 32) ^ (int) a[i]; hash = TInteger.rotateLeft(h, 4) ^ TInteger.rotateRight(h, 7) ^ TInteger.rotateLeft(hash, 13); } return hash; @@ -1417,7 +1417,7 @@ public class TArrays extends TObject { int hash = 0xA5A537FC; for (int i = 0; i < a.length; ++i) { long lh = TDouble.doubleToLongBits(a[i]); - int h = (int)lh ^ (int)(lh >> 32); + int h = (int) lh ^ (int) (lh >> 32); hash = TInteger.rotateLeft(h, 4) ^ TInteger.rotateRight(h, 7) ^ TInteger.rotateLeft(hash, 13); } return hash; @@ -1444,23 +1444,23 @@ public class TArrays extends TObject { Object el = a[i]; int h; if (a[i] instanceof boolean[]) { - h = hashCode((boolean[])el); + h = hashCode((boolean[]) el); } else if (a[i] instanceof byte[]) { - h = hashCode((byte[])el); + h = hashCode((byte[]) el); } else if (a[i] instanceof short[]) { - h = hashCode((short[])el); + h = hashCode((short[]) el); } else if (a[i] instanceof char[]) { - h = hashCode((char[])el); + h = hashCode((char[]) el); } else if (a[i] instanceof int[]) { - h = hashCode((int[])el); + h = hashCode((int[]) el); } else if (a[i] instanceof long[]) { - h = hashCode((long[])el); + h = hashCode((long[]) el); } else if (a[i] instanceof float[]) { - h = hashCode((float[])el); + h = hashCode((float[]) el); } else if (a[i] instanceof double[]) { - h = hashCode((double[])el); + h = hashCode((double[]) el); } else if (a[i] instanceof Object[]) { - h = deepHashCode((Object[])el); + h = deepHashCode((Object[]) el); } else { h = TObjects.hashCode(el) ^ 0x1F7A58E0; } @@ -1529,7 +1529,7 @@ public class TArrays extends TObject { private static void deepToString(Object a, TStringBuilder out, TList visited) { if (a instanceof Object[]) { - deepToString((Object[])a, out, visited); + deepToString((Object[]) a, out, visited); } else { out.append(TObject.wrap(a)); } diff --git a/teavm-classlib/src/main/java/org/teavm/classlib/java/util/TBitSet.java b/teavm-classlib/src/main/java/org/teavm/classlib/java/util/TBitSet.java index 358ccffd9..4a799e068 100644 --- a/teavm-classlib/src/main/java/org/teavm/classlib/java/util/TBitSet.java +++ b/teavm-classlib/src/main/java/org/teavm/classlib/java/util/TBitSet.java @@ -44,8 +44,8 @@ public class TBitSet extends TObject implements TCloneable, TSerializable { public static TBitSet valueOf(long[] longs) { int[] ints = new int[longs.length * 2]; for (int i = 0; i < longs.length; ++i) { - ints[i * 2 + 1] = (int)longs[i]; - ints[i * 2 + 1] = (int)(longs[i] >>> TInteger.SIZE); + ints[i * 2 + 1] = (int) longs[i]; + ints[i * 2 + 1] = (int) (longs[i] >>> TInteger.SIZE); } return new TBitSet(ints); } @@ -54,15 +54,15 @@ public class TBitSet extends TObject implements TCloneable, TSerializable { int[] ints = new int[(bytes.length + 3) / 4]; int fullInts = bytes.length / 4; for (int i = 0; i < fullInts; ++i) { - ints[i] = (bytes[i * 4] & 0xFF) | ((bytes[i * 4 + 1] & 0xFF) << 8) | ((bytes[i * 4 + 2] & 0xFF) << 16) | - ((bytes[i * 4 + 3] & 0xFF) << 24); + ints[i] = (bytes[i * 4] & 0xFF) | ((bytes[i * 4 + 1] & 0xFF) << 8) | ((bytes[i * 4 + 2] & 0xFF) << 16) + | ((bytes[i * 4 + 3] & 0xFF) << 24); } int lastInt = ints.length - 1; int lastByte = lastInt * 4; switch (bytes.length % 4) { case 3: - ints[lastInt] = (bytes[lastByte] & 0xFF) | ((bytes[lastByte + 1] & 0xFF) << 8) | - ((bytes[lastByte + 2] & 0xFF) << 16); + ints[lastInt] = (bytes[lastByte] & 0xFF) | ((bytes[lastByte + 1] & 0xFF) << 8) + | ((bytes[lastByte + 2] & 0xFF) << 16); break; case 2: ints[lastInt] = (bytes[lastByte] & 0xFF) | ((bytes[lastByte + 1] & 0xFF) << 8); @@ -80,23 +80,23 @@ public class TBitSet extends TObject implements TCloneable, TSerializable { int j = 0; int i = 0; for (; i < fullInts; i += 4) { - bytes[j++] = (byte)data[i]; - bytes[j++] = (byte)(data[i] >>> 8); - bytes[j++] = (byte)(data[i] >>> 16); - bytes[j++] = (byte)(data[i] >>> 24); + bytes[j++] = (byte) data[i]; + bytes[j++] = (byte) (data[i] >>> 8); + bytes[j++] = (byte) (data[i] >>> 16); + bytes[j++] = (byte) (data[i] >>> 24); } switch (bytes.length % 4) { case 3: - bytes[j++] = (byte)data[i]; - bytes[j++] = (byte)(data[i] >>> 8); - bytes[j++] = (byte)(data[i] >>> 16); + bytes[j++] = (byte) data[i]; + bytes[j++] = (byte) (data[i] >>> 8); + bytes[j++] = (byte) (data[i] >>> 16); break; case 2: - bytes[j++] = (byte)data[i]; - bytes[j++] = (byte)(data[i] >>> 8); + bytes[j++] = (byte) data[i]; + bytes[j++] = (byte) (data[i] >>> 8); break; case 1: - bytes[j++] = (byte)data[i]; + bytes[j++] = (byte) data[i]; break; } return bytes; @@ -107,7 +107,7 @@ public class TBitSet extends TObject implements TCloneable, TSerializable { int fullLongs = length / 64; int i = 0; for (; i < fullLongs; ++i) { - longs[i] = data[i * 2] | ((long)data[i * 2 + 1] << 32); + longs[i] = data[i * 2] | ((long) data[i * 2 + 1] << 32); } if ((((31 + length) / 32) & 1) == 1) { longs[i] = data[i * 2]; @@ -286,7 +286,7 @@ public class TBitSet extends TObject implements TCloneable, TSerializable { } int index = fromIndex / 32; int val = data[index]; - val >>>= (fromIndex % 32); + val >>>= fromIndex % 32; if (val != 0) { return TInteger.numberOfTrailingZeros(val) + fromIndex; } @@ -305,7 +305,7 @@ public class TBitSet extends TObject implements TCloneable, TSerializable { } int index = fromIndex / 32; int val = ~data[index]; - val >>>= (fromIndex % 32); + val >>>= fromIndex % 32; if (val != 0) { return TInteger.numberOfTrailingZeros(val) + fromIndex; } @@ -458,7 +458,7 @@ public class TBitSet extends TObject implements TCloneable, TSerializable { if (!(other instanceof TBitSet)) { return false; } - TBitSet set = (TBitSet)other; + TBitSet set = (TBitSet) other; if (set.length != length) { return false; } @@ -475,10 +475,10 @@ public class TBitSet extends TObject implements TCloneable, TSerializable { public int hashCode() { long h = 1234; long[] words = toLongArray(); - for (int i = words.length; --i >= 0; ) { + for (int i = words.length; --i >= 0;) { h ^= words[i] * (i + 1); } - return (int)((h >> 32) ^ h); + return (int) ((h >> 32) ^ h); } @Override diff --git a/teavm-classlib/src/main/java/org/teavm/classlib/java/util/TCalendar.java b/teavm-classlib/src/main/java/org/teavm/classlib/java/util/TCalendar.java index f54c9901b..982f2b82e 100644 --- a/teavm-classlib/src/main/java/org/teavm/classlib/java/util/TCalendar.java +++ b/teavm-classlib/src/main/java/org/teavm/classlib/java/util/TCalendar.java @@ -1,18 +1,18 @@ /* -* Copyright 2014 Alexey Andreev. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ + * Copyright 2014 Alexey Andreev. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with @@ -39,6 +39,7 @@ import org.teavm.classlib.java.lang.TComparable; import org.teavm.platform.metadata.IntResource; import org.teavm.platform.metadata.ResourceMap; + public abstract class TCalendar implements TSerializable, TCloneable, TComparable { protected boolean areFieldsSet; @@ -159,7 +160,8 @@ public abstract class TCalendar implements TSerializable, TCloneable, TComparabl TCalendar(TTimeZone timezone) { fields = new int[FIELD_COUNT]; isSet = new boolean[FIELD_COUNT]; - areFieldsSet = isTimeSet = false; + areFieldsSet = false; + isTimeSet = false; setLenient(true); setTimeZone(timezone); } @@ -168,7 +170,8 @@ public abstract class TCalendar implements TSerializable, TCloneable, TComparabl this(timezone); fields = new int[FIELD_COUNT]; isSet = new boolean[FIELD_COUNT]; - areFieldsSet = isTimeSet = false; + areFieldsSet = false; + isTimeSet = false; setLenient(true); setFirstDayOfWeek(resolveFirstDayOfWeek(locale)); setMinimalDaysInFirstWeek(resolveMinimalDaysInFirstWeek(locale)); @@ -191,8 +194,8 @@ public abstract class TCalendar implements TSerializable, TCloneable, TComparabl } String country = CLDRHelper.resolveCountry(locale.getLanguage(), locale.getCountry()); ResourceMap dayMap = CLDRHelper.getMinimalDaysInFirstWeek(); - minimalDaysInFirstWeekCache = dayMap.has(country) ? dayMap.get(country).getValue() : - dayMap.get("001").getValue(); + minimalDaysInFirstWeekCache = dayMap.has(country) ? dayMap.get(country).getValue() + : dayMap.get("001").getValue(); return minimalDaysInFirstWeekCache; } @@ -217,13 +220,15 @@ public abstract class TCalendar implements TSerializable, TCloneable, TComparabl fields[i] = 0; isSet[i] = false; } - areFieldsSet = isTimeSet = false; + areFieldsSet = false; + isTimeSet = false; } public final void clear(int field) { fields[field] = 0; isSet[field] = false; - areFieldsSet = isTimeSet = false; + areFieldsSet = false; + isTimeSet = false; } @Override @@ -232,7 +237,7 @@ public abstract class TCalendar implements TSerializable, TCloneable, TComparabl TCalendar clone = (TCalendar) super.clone(); clone.fields = fields.clone(); clone.isSet = isSet.clone(); - clone.zone = (TTimeZone)zone.clone(); + clone.zone = (TTimeZone) zone.clone(); return clone; } catch (CloneNotSupportedException e) { return null; @@ -263,10 +268,10 @@ public abstract class TCalendar implements TSerializable, TCloneable, TComparabl return false; } TCalendar cal = (TCalendar) object; - return getTimeInMillis() == cal.getTimeInMillis() && isLenient() == cal.isLenient() && - getFirstDayOfWeek() == cal.getFirstDayOfWeek() && - getMinimalDaysInFirstWeek() == cal.getMinimalDaysInFirstWeek() && - zone.equals(cal.zone); + return getTimeInMillis() == cal.getTimeInMillis() && isLenient() == cal.isLenient() + && getFirstDayOfWeek() == cal.getFirstDayOfWeek() + && getMinimalDaysInFirstWeek() == cal.getMinimalDaysInFirstWeek() + && zone.equals(cal.zone); } public int get(int field) { @@ -275,8 +280,10 @@ public abstract class TCalendar implements TSerializable, TCloneable, TComparabl } public int getActualMaximum(int field) { - int value, next; - if (getMaximum(field) == (next = getLeastMaximum(field))) { + int value; + int max = getMaximum(field); + int next = getLeastMaximum(field); + if (max == next) { return next; } complete(); @@ -293,8 +300,10 @@ public abstract class TCalendar implements TSerializable, TCloneable, TComparabl } public int getActualMinimum(int field) { - int value, next; - if (getMinimum(field) == (next = getGreatestMinimum(field))) { + int value; + int min = getMinimum(field); + int next = getGreatestMinimum(field); + if (min == next) { return next; } complete(); @@ -397,7 +406,8 @@ public abstract class TCalendar implements TSerializable, TCloneable, TComparabl public void set(int field, int value) { fields[field] = value; isSet[field] = true; - areFieldsSet = isTimeSet = false; + areFieldsSet = false; + isTimeSet = false; if (field > MONTH && field < AM_PM) { lastDateFieldSet = field; } @@ -453,10 +463,10 @@ public abstract class TCalendar implements TSerializable, TCloneable, TComparabl @Override public String toString() { - StringBuilder result = new StringBuilder(getClass().getName() + "[time=" + - (isTimeSet ? String.valueOf(time) : "?") + ",areFieldsSet=" + areFieldsSet + ",lenient=" + lenient + - ",firstDayOfWeek=" + firstDayOfWeek + ",minimalDaysInFirstWeek=" + - minimalDaysInFirstWeek); + StringBuilder result = new StringBuilder(getClass().getName() + "[time=" + + (isTimeSet ? String.valueOf(time) : "?") + ",areFieldsSet=" + areFieldsSet + ",lenient=" + lenient + + ",firstDayOfWeek=" + firstDayOfWeek + ",minimalDaysInFirstWeek=" + + minimalDaysInFirstWeek); for (int i = 0; i < FIELD_COUNT; i++) { result.append(','); result.append(fieldNames[i]); diff --git a/teavm-classlib/src/main/java/org/teavm/classlib/java/util/TCheckedCollection.java b/teavm-classlib/src/main/java/org/teavm/classlib/java/util/TCheckedCollection.java index af1c758e8..290c6cdfa 100644 --- a/teavm-classlib/src/main/java/org/teavm/classlib/java/util/TCheckedCollection.java +++ b/teavm-classlib/src/main/java/org/teavm/classlib/java/util/TCheckedCollection.java @@ -83,7 +83,7 @@ class TCheckedCollection implements TCollection { for (int i = 0; i < items.length; ++i) { items[i] = type.cast(TObject.wrap(items[i])); } - return innerCollection.addAll(TArrays.asList((E[])items)); + return innerCollection.addAll(TArrays.asList((E[]) items)); } @Override diff --git a/teavm-classlib/src/main/java/org/teavm/classlib/java/util/TCheckedList.java b/teavm-classlib/src/main/java/org/teavm/classlib/java/util/TCheckedList.java index 8b0fcd945..c2324f8fe 100644 --- a/teavm-classlib/src/main/java/org/teavm/classlib/java/util/TCheckedList.java +++ b/teavm-classlib/src/main/java/org/teavm/classlib/java/util/TCheckedList.java @@ -37,7 +37,7 @@ class TCheckedList extends TCheckedCollection implements TList { for (int i = 0; i < items.length; ++i) { items[i] = type.cast(TObject.wrap(items[i])); } - return innerList.addAll(index, TArrays.asList((E[])items)); + return innerList.addAll(index, TArrays.asList((E[]) items)); } @Override diff --git a/teavm-classlib/src/main/java/org/teavm/classlib/java/util/TCollections.java b/teavm-classlib/src/main/java/org/teavm/classlib/java/util/TCollections.java index 2e670fd6c..29f27475b 100644 --- a/teavm-classlib/src/main/java/org/teavm/classlib/java/util/TCollections.java +++ b/teavm-classlib/src/main/java/org/teavm/classlib/java/util/TCollections.java @@ -164,7 +164,7 @@ public class TCollections extends TObject { } public static TMap singletonMap(final K key, final V value) { - final TSet> entries = singleton((Entry)new TAbstractMap.SimpleImmutableEntry<>(key, value)); + final TSet> entries = singleton((Entry) new TAbstractMap.SimpleImmutableEntry<>(key, value)); return new TAbstractMap() { @Override public TSet> entrySet() { return entries; @@ -199,7 +199,7 @@ public class TCollections extends TObject { public static void swap(TList list, int i, int j) { @SuppressWarnings("unchecked") - TList objList = (TList)list; + TList objList = (TList) list; Object tmp = objList.get(i); objList.set(i, objList.get(j)); objList.set(j, tmp); @@ -210,7 +210,7 @@ public class TCollections extends TObject { c = naturalOrder; } @SuppressWarnings("unchecked") - T[] array = (T[])new Object[list.size()]; + T[] array = (T[]) new Object[list.size()]; list.toArray(array); TArrays.sort(array, c); for (int i = 0; i < array.length; ++i) { @@ -230,7 +230,7 @@ public class TCollections extends TObject { TList randomAccess = new TArrayList<>(list); reverse(list, 0, list.size()); list.clear(); - ((TList)list).addAll(randomAccess); + ((TList) list).addAll(randomAccess); } } @@ -240,7 +240,7 @@ public class TCollections extends TObject { private static TComparator naturalOrder = new TComparator() { @SuppressWarnings("unchecked") @Override public int compare(Object o1, Object o2) { - return o1 != null ? ((TComparable)o1).compareTo(o2) : -((TComparable)o2).compareTo(o1); + return o1 != null ? ((TComparable) o1).compareTo(o2) : -((TComparable) o2).compareTo(o1); } }; @@ -288,7 +288,7 @@ public class TCollections extends TObject { TList randomAccess = new TArrayList<>(list); shuffleRandomAccess(randomAccess, rnd); list.clear(); - ((TList)list).addAll(randomAccess); + ((TList) list).addAll(randomAccess); } } @@ -376,7 +376,7 @@ public class TCollections extends TObject { TList randomAccess = new TArrayList<>(list); rotateRandomAccess(randomAccess, distance); list.clear(); - ((TList)list).addAll(randomAccess); + ((TList) list).addAll(randomAccess); } } @@ -395,7 +395,7 @@ public class TCollections extends TObject { private static void reverse(TList list, int from, int to) { @SuppressWarnings("unchecked") - TList safeList = (TList)list; + TList safeList = (TList) list; int half = (from + to) / 2; int j = to - 1; for (int i = from; i < half; ++i, --j) { @@ -546,12 +546,12 @@ public class TCollections extends TObject { @SuppressWarnings("unchecked") public static TComparator reverseOrder() { - return (TComparator)reverseOrder; + return (TComparator) reverseOrder; } private static TComparator reverseOrder = new TComparator() { @SuppressWarnings("unchecked") @Override public int compare(Object o1, Object o2) { - return o1 != null ? -((TComparable)o1).compareTo(o2) : ((TComparable)o2).compareTo(o1); + return o1 != null ? -((TComparable) o1).compareTo(o2) : ((TComparable) o2).compareTo(o1); } }; diff --git a/teavm-classlib/src/main/java/org/teavm/classlib/java/util/TCurrency.java b/teavm-classlib/src/main/java/org/teavm/classlib/java/util/TCurrency.java index 184ed2aeb..37cf792d9 100644 --- a/teavm-classlib/src/main/java/org/teavm/classlib/java/util/TCurrency.java +++ b/teavm-classlib/src/main/java/org/teavm/classlib/java/util/TCurrency.java @@ -92,8 +92,8 @@ public final class TCurrency implements TSerializable { public String getSymbol(TLocale locale) { CurrencyLocalization localization = CLDRHelper.resolveCurrency(locale.getLanguage(), locale.getCountry(), getCurrencyCode()); - return localization != null && !localization.getSymbol().isEmpty() ? - localization.getSymbol() : getCurrencyCode(); + return localization != null && !localization.getSymbol().isEmpty() + ? localization.getSymbol() : getCurrencyCode(); } public int getDefaultFractionDigits() { diff --git a/teavm-classlib/src/main/java/org/teavm/classlib/java/util/TDate.java b/teavm-classlib/src/main/java/org/teavm/classlib/java/util/TDate.java index 7e5f30d7b..50d32244b 100644 --- a/teavm-classlib/src/main/java/org/teavm/classlib/java/util/TDate.java +++ b/teavm-classlib/src/main/java/org/teavm/classlib/java/util/TDate.java @@ -51,7 +51,7 @@ public class TDate implements TComparable { @Deprecated public TDate(int year, int month, int date, int hrs, int min, int sec) { - this((long)buildNumericTime(year, month, date, hrs, min, sec)); + this((long) buildNumericTime(year, month, date, hrs, min, sec)); setFullYear(value, year + 1900); } @@ -66,7 +66,7 @@ public class TDate implements TComparable { @Deprecated public static long UTC(int year, int month, int date, int hrs, int min, int sec) { - return (long)buildNumericUTC(year, month, date, hrs, min, sec); + return (long) buildNumericUTC(year, month, date, hrs, min, sec); } @Deprecated @@ -75,7 +75,7 @@ public class TDate implements TComparable { if (Double.isNaN(value)) { throw new IllegalArgumentException("Can't parse date: " + s); } - return (long)value; + return (long) value; } @Deprecated @@ -85,7 +85,7 @@ public class TDate implements TComparable { @Deprecated public void setYear(int year) { - this.value = (long)setFullYear(value, year + 1900); + this.value = (long) setFullYear(value, year + 1900); } @Deprecated @@ -95,7 +95,7 @@ public class TDate implements TComparable { @Deprecated public void setMonth(int month) { - this.value = (long)setMonth(value, month); + this.value = (long) setMonth(value, month); } @Deprecated @@ -105,7 +105,7 @@ public class TDate implements TComparable { @Deprecated public void setDate(int date) { - this.value = (long)setDate(value, date); + this.value = (long) setDate(value, date); } @Deprecated @@ -120,7 +120,7 @@ public class TDate implements TComparable { @Deprecated public void setHours(int hours) { - this.value = (long)setHours(value, hours); + this.value = (long) setHours(value, hours); } @Deprecated @@ -130,7 +130,7 @@ public class TDate implements TComparable { @Deprecated public void setMinutes(int minutes) { - this.value = (long)setMinutes(value, minutes); + this.value = (long) setMinutes(value, minutes); } @Deprecated @@ -140,7 +140,7 @@ public class TDate implements TComparable { @Deprecated public void setSeconds(int seconds) { - this.value = (long)setSeconds(value, seconds); + this.value = (long) setSeconds(value, seconds); } public long getTime() { @@ -164,7 +164,7 @@ public class TDate implements TComparable { if (!(obj instanceof TDate)) { return false; } - TDate other = (TDate)obj; + TDate other = (TDate) obj; return value == other.value; } @@ -175,7 +175,7 @@ public class TDate implements TComparable { @Override public int hashCode() { - return (int)value ^ (int)(value >>> 32); + return (int) value ^ (int) (value >>> 32); } @Override diff --git a/teavm-classlib/src/main/java/org/teavm/classlib/java/util/TGregorianCalendar.java b/teavm-classlib/src/main/java/org/teavm/classlib/java/util/TGregorianCalendar.java index d1b15b149..0766641d1 100644 --- a/teavm-classlib/src/main/java/org/teavm/classlib/java/util/TGregorianCalendar.java +++ b/teavm-classlib/src/main/java/org/teavm/classlib/java/util/TGregorianCalendar.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.util; public class TGregorianCalendar extends TCalendar { @@ -23,7 +21,7 @@ public class TGregorianCalendar extends TCalendar { public static final int AD = 1; - private static final long defaultGregorianCutover = -12219292800000l; + private static final long defaultGregorianCutover = -12219292800000L; private long gregorianCutover = defaultGregorianCutover; @@ -31,9 +29,9 @@ public class TGregorianCalendar extends TCalendar { private transient int julianSkew = ((changeYear - 2000) / 400) + julianError() - ((changeYear - 2000) / 100); - static byte[] DaysInMonth = new byte[] { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }; + static byte[] daysInMonth = new byte[] { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }; - private static int[] DaysInYear = new int[] { 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334 }; + private static int[] daysInYear = new int[] { 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334 }; private static int[] maximums = new int[] { 1, 292278994, 11, 53, 6, 31, 366, 7, 6, 1, 11, 23, 59, 59, 999, 14 * 3600 * 1000, 7200000 }; @@ -45,15 +43,15 @@ public class TGregorianCalendar extends TCalendar { private boolean isCached; - private int cachedFields[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + private int[] cachedFields = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; - private long nextMidnightMillis = 0L; + private long nextMidnightMillis; - private long lastMidnightMillis = 0L; + private long lastMidnightMillis; private int currentYearSkew = 10; - private int lastYearSkew = 0; + private int lastYearSkew; public TGregorianCalendar() { this(TLocale.getDefault()); @@ -194,7 +192,7 @@ public class TGregorianCalendar extends TCalendar { return thisClone; } - private final void fullFieldsCalc(long timeVal, int millis, int zoneOffset) { + private void fullFieldsCalc(long timeVal, int millis, int zoneOffset) { long days = timeVal / 86400000; if (millis < 0) { @@ -257,13 +255,13 @@ public class TGregorianCalendar extends TCalendar { } } - fields[MILLISECOND] = (millis % 1000); + fields[MILLISECOND] = millis % 1000; millis /= 1000; - fields[SECOND] = (millis % 60); + fields[SECOND] = millis % 60; millis /= 60; - fields[MINUTE] = (millis % 60); + fields[MINUTE] = millis % 60; millis /= 60; - fields[HOUR_OF_DAY] = (millis % 24); + fields[HOUR_OF_DAY] = millis % 24; fields[AM_PM] = fields[HOUR_OF_DAY] > 11 ? 1 : 0; fields[HOUR] = fields[HOUR_OF_DAY] % 12; @@ -278,11 +276,11 @@ public class TGregorianCalendar extends TCalendar { fields[DAY_OF_WEEK_IN_MONTH] = (date - 1) / 7 + 1; fields[WEEK_OF_MONTH] = (date - 1 + mod7(days - date - 2 - (getFirstDayOfWeek() - 1))) / 7 + 1; int daysFromStart = mod7(days - 3 - (fields[DAY_OF_YEAR] - 1) - (getFirstDayOfWeek() - 1)); - int week = (fields[DAY_OF_YEAR] - 1 + daysFromStart) / 7 + - (7 - daysFromStart >= getMinimalDaysInFirstWeek() ? 1 : 0); + int week = (fields[DAY_OF_YEAR] - 1 + daysFromStart) / 7 + + (7 - daysFromStart >= getMinimalDaysInFirstWeek() ? 1 : 0); if (week == 0) { - fields[WEEK_OF_YEAR] = 7 - mod7(daysFromStart - (isLeapYear(fields[YEAR] - 1) ? 2 : 1)) >= getMinimalDaysInFirstWeek() ? 53 - : 52; + fields[WEEK_OF_YEAR] = 7 - mod7(daysFromStart - (isLeapYear(fields[YEAR] - 1) ? 2 : 1)) + >= getMinimalDaysInFirstWeek() ? 53 : 52; } else if (fields[DAY_OF_YEAR] >= (leapYear ? 367 : 366) - mod7(daysFromStart + (leapYear ? 2 : 1))) { fields[WEEK_OF_YEAR] = 7 - mod7(daysFromStart + (leapYear ? 2 : 1)) >= getMinimalDaysInFirstWeek() ? 1 : week; @@ -291,12 +289,12 @@ public class TGregorianCalendar extends TCalendar { } } - private final void cachedFieldsCheckAndGet(long timeVal, long newTimeMillis, long newTimeMillisAdjusted, + private void cachedFieldsCheckAndGet(long timeVal, long newTimeMillis, long newTimeMillisAdjusted, int millis, int zoneOffset) { int dstOffset = fields[DST_OFFSET]; - if (!isCached || newTimeMillis >= nextMidnightMillis || newTimeMillis <= lastMidnightMillis || - cachedFields[4] != zoneOffset || (dstOffset == 0 && (newTimeMillisAdjusted >= nextMidnightMillis)) || - (dstOffset != 0 && (newTimeMillisAdjusted <= lastMidnightMillis))) { + if (!isCached || newTimeMillis >= nextMidnightMillis || newTimeMillis <= lastMidnightMillis + || cachedFields[4] != zoneOffset || (dstOffset == 0 && (newTimeMillisAdjusted >= nextMidnightMillis)) + || (dstOffset != 0 && (newTimeMillisAdjusted <= lastMidnightMillis))) { fullFieldsCalc(timeVal, millis, zoneOffset); isCached = false; } else { @@ -352,13 +350,13 @@ public class TGregorianCalendar extends TCalendar { millis -= 86400000; } - fields[MILLISECOND] = (millis % 1000); + fields[MILLISECOND] = millis % 1000; millis /= 1000; - fields[SECOND] = (millis % 60); + fields[SECOND] = millis % 60; millis /= 60; - fields[MINUTE] = (millis % 60); + fields[MINUTE] = millis % 60; millis /= 60; - fields[HOUR_OF_DAY] = (millis % 24); + fields[HOUR_OF_DAY] = millis % 24; millis /= 24; fields[AM_PM] = fields[HOUR_OF_DAY] > 11 ? 1 : 0; fields[HOUR] = fields[HOUR_OF_DAY] % 12; @@ -509,8 +507,8 @@ public class TGregorianCalendar extends TCalendar { boolean leapYear = isLeapYear(year); days = daysFromBaseYear(year) + daysInYear(leapYear, month); boolean useDate = isSet[DATE]; - if (useDate && - (lastDateFieldSet == DAY_OF_WEEK || lastDateFieldSet == WEEK_OF_MONTH || lastDateFieldSet == DAY_OF_WEEK_IN_MONTH)) { + if (useDate && (lastDateFieldSet == DAY_OF_WEEK || lastDateFieldSet == WEEK_OF_MONTH + || lastDateFieldSet == DAY_OF_WEEK_IN_MONTH)) { useDate = !(isSet[DAY_OF_WEEK] && weekMonthSet); } if (useDate) { @@ -532,9 +530,9 @@ public class TGregorianCalendar extends TCalendar { if (fields[DAY_OF_WEEK_IN_MONTH] >= 0) { days += mod7(dayOfWeek - (days - 3)) + (fields[DAY_OF_WEEK_IN_MONTH] - 1) * 7; } else { - days += daysInMonth(leapYear, month) + - mod7(dayOfWeek - (days + daysInMonth(leapYear, month) - 3)) + - fields[DAY_OF_WEEK_IN_MONTH] * 7; + days += daysInMonth(leapYear, month) + + mod7(dayOfWeek - (days + daysInMonth(leapYear, month) - 3)) + + fields[DAY_OF_WEEK_IN_MONTH] * 7; } } else if (isSet[DAY_OF_WEEK]) { int skew = mod7(days - 3 - (getFirstDayOfWeek() - 1)); @@ -560,8 +558,8 @@ public class TGregorianCalendar extends TCalendar { days += 7; } } else if (isSet[DAY_OF_YEAR]) { - if (!isLenient() && - (fields[DAY_OF_YEAR] < 1 || fields[DAY_OF_YEAR] > (365 + (isLeapYear(year) ? 1 : 0)))) { + if (!isLenient() && (fields[DAY_OF_YEAR] < 1 + || fields[DAY_OF_YEAR] > (365 + (isLeapYear(year) ? 1 : 0)))) { throw new IllegalArgumentException(); } days += fields[DAY_OF_YEAR] - 1; @@ -629,10 +627,10 @@ public class TGregorianCalendar extends TCalendar { private int daysInMonth(boolean leapYear, int month) { if (leapYear && month == FEBRUARY) { - return DaysInMonth[month] + 1; + return daysInMonth[month] + 1; } - return DaysInMonth[month]; + return daysInMonth[month]; } private int daysInYear(int year) { @@ -648,10 +646,10 @@ public class TGregorianCalendar extends TCalendar { private int daysInYear(boolean leapYear, int month) { if (leapYear && month > FEBRUARY) { - return DaysInYear[month] + 1; + return daysInYear[month] + 1; } - return DaysInYear[month]; + return daysInYear[month]; } @Override @@ -661,8 +659,8 @@ public class TGregorianCalendar extends TCalendar { @Override public int getActualMaximum(int field) { - int value; - if ((value = maximums[field]) == leastMaximums[field]) { + int value = maximums[field]; + if (value == leastMaximums[field]) { return value; } @@ -803,7 +801,11 @@ public class TGregorianCalendar extends TCalendar { isCached = false; complete(); - int days, day, mod, maxWeeks, newWeek; + int days; + int day; + int mod; + int maxWeeks; + int newWeek; int max = -1; switch (field) { case YEAR: diff --git a/teavm-classlib/src/main/java/org/teavm/classlib/java/util/THashMap.java b/teavm-classlib/src/main/java/org/teavm/classlib/java/util/THashMap.java index 7237ada87..8ee052962 100644 --- a/teavm-classlib/src/main/java/org/teavm/classlib/java/util/THashMap.java +++ b/teavm-classlib/src/main/java/org/teavm/classlib/java/util/THashMap.java @@ -41,7 +41,7 @@ import org.teavm.javascript.spi.Rename; public class THashMap extends TAbstractMap implements TCloneable, TSerializable { transient int elementCount; transient HashEntry[] elementData; - transient int modCount = 0; + transient int modCount; private static final int DEFAULT_SIZE = 16; final float loadFactor; int threshold; @@ -58,7 +58,7 @@ public class THashMap extends TAbstractMap implements TCloneable, TS HashEntry(K theKey, V theValue) { super(theKey, theValue); - origKeyHash = (theKey == null ? 0 : computeHashCode(theKey)); + origKeyHash = theKey == null ? 0 : computeHashCode(theKey); } @Override @@ -73,7 +73,7 @@ public class THashMap extends TAbstractMap implements TCloneable, TS } private static class AbstractMapIterator { - private int position = 0; + private int position; int expectedModCount; HashEntry futureEntry; HashEntry currentEntry; @@ -117,7 +117,7 @@ public class THashMap extends TAbstractMap implements TCloneable, TS futureEntry = currentEntry.next; prevEntry = null; } else { - if(currentEntry!=null){ + if (currentEntry != null) { prevEntry = currentEntry; } currentEntry = futureEntry; @@ -130,7 +130,7 @@ public class THashMap extends TAbstractMap implements TCloneable, TS if (currentEntry == null) { throw new TIllegalStateException(); } - if(prevEntry == null){ + if (prevEntry == null) { int index = currentEntry.origKeyHash & (associatedMap.elementData.length - 1); associatedMap.elementData[index] = associatedMap.elementData[index].next; } else { @@ -145,9 +145,9 @@ public class THashMap extends TAbstractMap implements TCloneable, TS } - private static class EntryIterator extends AbstractMapIterator + private static class EntryIterator extends AbstractMapIterator implements TIterator> { - EntryIterator (THashMap map) { + EntryIterator(THashMap map) { super(map); } @@ -158,8 +158,8 @@ public class THashMap extends TAbstractMap implements TCloneable, TS } } - private static class KeyIterator extends AbstractMapIterator implements TIterator { - KeyIterator (THashMap map) { + private static class KeyIterator extends AbstractMapIterator implements TIterator { + KeyIterator(THashMap map) { super(map); } @@ -170,8 +170,8 @@ public class THashMap extends TAbstractMap implements TCloneable, TS } } - private static class ValueIterator extends AbstractMapIterator implements TIterator { - ValueIterator (THashMap map) { + private static class ValueIterator extends AbstractMapIterator implements TIterator { + ValueIterator(THashMap map) { super(map); } @@ -182,14 +182,14 @@ public class THashMap extends TAbstractMap implements TCloneable, TS } } - static class HashMapEntrySet extends TAbstractSet> { - private final THashMap associatedMap; + static class HashMapEntrySet extends TAbstractSet> { + private final THashMap associatedMap; - public HashMapEntrySet(THashMap hm) { + public HashMapEntrySet(THashMap hm) { associatedMap = hm; } - THashMap hashMap() { + THashMap hashMap() { return associatedMap; } @@ -207,8 +207,8 @@ public class THashMap extends TAbstractMap implements TCloneable, TS public boolean remove(Object object) { if (object instanceof TMap.Entry) { TMap.Entry oEntry = (TMap.Entry) object; - TMap.Entry entry = associatedMap.getEntry(oEntry.getKey()); - if(valuesEq(entry, oEntry)) { + TMap.Entry entry = associatedMap.getEntry(oEntry.getKey()); + if (valuesEq(entry, oEntry)) { associatedMap.removeEntry(entry); return true; } @@ -220,21 +220,21 @@ public class THashMap extends TAbstractMap implements TCloneable, TS public boolean contains(Object object) { if (object instanceof TMap.Entry) { TMap.Entry oEntry = (TMap.Entry) object; - TMap.Entry entry = associatedMap.getEntry(oEntry.getKey()); + TMap.Entry entry = associatedMap.getEntry(oEntry.getKey()); return valuesEq(entry, oEntry); } return false; } private static boolean valuesEq(TMap.Entry entry, TMap.Entry oEntry) { - return (entry != null) && - ((entry.getValue() == null) ? - (oEntry.getValue() == null) : - (areEqualValues(entry.getValue(), oEntry.getValue()))); + return entry != null + && (entry.getValue() == null + ? oEntry.getValue() == null + : areEqualValues(entry.getValue(), oEntry.getValue())); } @Override - public TIterator> iterator() { + public TIterator> iterator() { return new EntryIterator<>(associatedMap); } } @@ -252,14 +252,14 @@ public class THashMap extends TAbstractMap implements TCloneable, TS this(capacity, 0.75f); // default load factor of 0.75 } - private static final int calculateCapacity(int x) { - if(x >= 1 << 30){ + private static int calculateCapacity(int x) { + if (x >= 1 << 30) { return 1 << 30; } - if(x == 0){ + if (x == 0) { return 16; } - x = x -1; + x = x - 1; x |= x >> 1; x |= x >> 2; x |= x >> 4; @@ -383,8 +383,8 @@ public class THashMap extends TAbstractMap implements TCloneable, TS return m; } - final HashEntry findNonNullKeyEntry(Object key, int index, int keyHash) { - HashEntry m = elementData[index]; + final HashEntry findNonNullKeyEntry(Object key, int index, int keyHash) { + HashEntry m = elementData[index]; while (m != null && (m.origKeyHash != keyHash || !areEqualKeys(key, m.key))) { m = m.next; @@ -392,10 +392,11 @@ public class THashMap extends TAbstractMap implements TCloneable, TS return m; } - final HashEntry findNullKeyEntry() { - HashEntry m = elementData[0]; - while (m != null && m.key != null) + final HashEntry findNullKeyEntry() { + HashEntry m = elementData[0]; + while (m != null && m.key != null) { m = m.next; + } return m; } @@ -435,8 +436,8 @@ public class THashMap extends TAbstractMap implements TCloneable, TS } V putImpl(K key, V value) { - HashEntry entry; - if(key == null) { + HashEntry entry; + if (key == null) { entry = findNullKeyEntry(); if (entry == null) { modCount++; @@ -470,8 +471,8 @@ public class THashMap extends TAbstractMap implements TCloneable, TS return entry; } - HashEntry createHashedEntry(K key, int index, int hash) { - HashEntry entry = new HashEntry<>(key,hash); + HashEntry createHashedEntry(K key, int index, int hash) { + HashEntry entry = new HashEntry<>(key, hash); entry.next = elementData[index]; elementData[index] = entry; return entry; @@ -497,7 +498,7 @@ public class THashMap extends TAbstractMap implements TCloneable, TS } void rehash(int capacity) { - int length = calculateCapacity((capacity == 0 ? 1 : capacity << 1)); + int length = calculateCapacity(capacity == 0 ? 1 : capacity << 1); HashEntry[] newData = newElementArray(length); for (int i = 0; i < elementData.length; i++) { diff --git a/teavm-classlib/src/main/java/org/teavm/classlib/java/util/THashSet.java b/teavm-classlib/src/main/java/org/teavm/classlib/java/util/THashSet.java index 4c6b68f5b..54e7413d9 100644 --- a/teavm-classlib/src/main/java/org/teavm/classlib/java/util/THashSet.java +++ b/teavm-classlib/src/main/java/org/teavm/classlib/java/util/THashSet.java @@ -114,7 +114,7 @@ public class THashSet extends TAbstractSet implements TCloneable, TSeriali public TObject clone0() { try { THashSet clone = (THashSet) super.clone(); - clone.backingMap = (THashMap>)backingMap.clone(); + clone.backingMap = (THashMap>) backingMap.clone(); return clone; } catch (TCloneNotSupportedException e) { return null; diff --git a/teavm-classlib/src/main/java/org/teavm/classlib/java/util/THashtable.java b/teavm-classlib/src/main/java/org/teavm/classlib/java/util/THashtable.java index aec216a5d..308d159cc 100644 --- a/teavm-classlib/src/main/java/org/teavm/classlib/java/util/THashtable.java +++ b/teavm-classlib/src/main/java/org/teavm/classlib/java/util/THashtable.java @@ -135,7 +135,8 @@ public class THashtable extends TDictionary implements TMap, } private class HashIterator implements TIterator { - int position, expectedModCount; + int position; + int expectedModCount; final TMapEntry.Type type; @@ -143,7 +144,7 @@ public class THashtable extends TDictionary implements TMap, int lastPosition; - boolean canRemove = false; + boolean canRemove; HashIterator(TMapEntry.Type value) { type = value; @@ -173,8 +174,11 @@ public class THashtable extends TDictionary implements TMap, lastEntry = lastEntry.next; } if (lastEntry == null) { - while (position >= firstSlot - && (lastEntry = elementData[position]) == null) { + while (position >= firstSlot) { + lastEntry = elementData[position]; + if (lastEntry != null) { + break; + } position--; } if (lastEntry != null) { @@ -287,7 +291,8 @@ public class THashtable extends TDictionary implements TMap, hashtable.elementData = new Entry[elementData.length]; Entry entry; for (int i = elementData.length; --i >= 0;) { - if ((entry = elementData[i]) != null) { + entry = elementData[i]; + if (entry != null) { hashtable.elementData[i] = (Entry) entry.clone(); } } @@ -523,7 +528,7 @@ public class THashtable extends TDictionary implements TMap, class HashEnumIterator extends HashIterator implements TEnumeration { - private boolean isEnumeration = false; + private boolean isEnumeration; int start; diff --git a/teavm-classlib/src/main/java/org/teavm/classlib/java/util/TIANATimeZone.java b/teavm-classlib/src/main/java/org/teavm/classlib/java/util/TIANATimeZone.java index d9e757378..c8a4a4c53 100644 --- a/teavm-classlib/src/main/java/org/teavm/classlib/java/util/TIANATimeZone.java +++ b/teavm-classlib/src/main/java/org/teavm/classlib/java/util/TIANATimeZone.java @@ -71,7 +71,7 @@ class TIANATimeZone extends TTimeZone { @Override public TIANATimeZone clone() { - TIANATimeZone copy = (TIANATimeZone)super.clone(); + TIANATimeZone copy = (TIANATimeZone) super.clone(); copy.rawOffset = rawOffset; copy.underlyingZone = underlyingZone; return copy; @@ -85,7 +85,7 @@ class TIANATimeZone extends TTimeZone { if (!(obj instanceof TIANATimeZone)) { return false; } - TIANATimeZone other = (TIANATimeZone)obj; + TIANATimeZone other = (TIANATimeZone) obj; return rawOffset == other.rawOffset && underlyingZone.getID().equals(other.getID()); } diff --git a/teavm-classlib/src/main/java/org/teavm/classlib/java/util/TLinkedHashMap.java b/teavm-classlib/src/main/java/org/teavm/classlib/java/util/TLinkedHashMap.java index ca57f3cae..a02839aea 100644 --- a/teavm-classlib/src/main/java/org/teavm/classlib/java/util/TLinkedHashMap.java +++ b/teavm-classlib/src/main/java/org/teavm/classlib/java/util/TLinkedHashMap.java @@ -36,7 +36,8 @@ import org.teavm.classlib.java.lang.TIllegalStateException; public class TLinkedHashMap extends THashMap implements TMap { private final boolean accessOrder; - transient private LinkedHashMapEntry head, tail; + transient private LinkedHashMapEntry head; + transient private LinkedHashMapEntry tail; public TLinkedHashMap() { accessOrder = false; @@ -83,7 +84,7 @@ public class TLinkedHashMap extends THashMap implements TMap { } public boolean hasNext() { - return (futureEntry != null); + return futureEntry != null; } final void checkConcurrentMod() throws TConcurrentModificationException { @@ -103,7 +104,7 @@ public class TLinkedHashMap extends THashMap implements TMap { public void remove() { checkConcurrentMod(); - if (currentEntry==null) { + if (currentEntry == null) { throw new TIllegalStateException(); } associatedMap.removeEntry(currentEntry); @@ -131,8 +132,8 @@ public class TLinkedHashMap extends THashMap implements TMap { } } - private static class EntryIterator extends AbstractMapIterator implements TIterator> { - EntryIterator (TLinkedHashMap map) { + private static class EntryIterator extends AbstractMapIterator implements TIterator> { + EntryIterator(TLinkedHashMap map) { super(map); } @@ -143,8 +144,8 @@ public class TLinkedHashMap extends THashMap implements TMap { } } - private static class KeyIterator extends AbstractMapIterator implements TIterator { - KeyIterator (TLinkedHashMap map) { + private static class KeyIterator extends AbstractMapIterator implements TIterator { + KeyIterator(TLinkedHashMap map) { super(map); } @@ -155,8 +156,8 @@ public class TLinkedHashMap extends THashMap implements TMap { } } - private static class ValueIterator extends AbstractMapIterator implements TIterator { - ValueIterator (TLinkedHashMap map) { + private static class ValueIterator extends AbstractMapIterator implements TIterator { + ValueIterator(TLinkedHashMap map) { super(map); } @@ -167,19 +168,20 @@ public class TLinkedHashMap extends THashMap implements TMap { } } - static final class LinkedHashMapEntrySet extends HashMapEntrySet { - public LinkedHashMapEntrySet(TLinkedHashMap lhm) { + static final class LinkedHashMapEntrySet extends HashMapEntrySet { + public LinkedHashMapEntrySet(TLinkedHashMap lhm) { super(lhm); } @Override - public TIterator> iterator() { - return new EntryIterator<>((TLinkedHashMap) hashMap()); + public TIterator> iterator() { + return new EntryIterator<>((TLinkedHashMap) hashMap()); } } static final class LinkedHashMapEntry extends HashEntry { - LinkedHashMapEntry chainForward, chainBackward; + LinkedHashMapEntry chainForward; + LinkedHashMapEntry chainBackward; LinkedHashMapEntry(K theKey, V theValue) { super(theKey, theValue); @@ -297,7 +299,8 @@ public class TLinkedHashMap extends THashMap implements TMap { V putImpl(K key, V value) { LinkedHashMapEntry m; if (elementCount == 0) { - head = tail = null; + head = null; + tail = null; } if (key == null) { m = (LinkedHashMapEntry) findNullKeyEntry(); @@ -341,7 +344,8 @@ public class TLinkedHashMap extends THashMap implements TMap { if (head == null) { // Check if the map is empty - head = tail = m; + head = m; + tail = m; return; } @@ -484,6 +488,7 @@ public class TLinkedHashMap extends THashMap implements TMap { @Override public void clear() { super.clear(); - head = tail = null; + head = null; + tail = null; } } diff --git a/teavm-classlib/src/main/java/org/teavm/classlib/java/util/TLocale.java b/teavm-classlib/src/main/java/org/teavm/classlib/java/util/TLocale.java index 392693641..1fe57408d 100644 --- a/teavm-classlib/src/main/java/org/teavm/classlib/java/util/TLocale.java +++ b/teavm-classlib/src/main/java/org/teavm/classlib/java/util/TLocale.java @@ -115,8 +115,8 @@ public final class TLocale implements TCloneable, TSerializable { } if (object instanceof TLocale) { TLocale o = (TLocale) object; - return languageCode.equals(o.languageCode) && countryCode.equals(o.countryCode) && - variantCode.equals(o.variantCode); + return languageCode.equals(o.languageCode) && countryCode.equals(o.countryCode) + && variantCode.equals(o.variantCode); } return false; } @@ -147,7 +147,7 @@ public final class TLocale implements TCloneable, TSerializable { return defaultLocale; } - public final String getDisplayCountry() { + public String getDisplayCountry() { return getDisplayCountry(getDefault()); } @@ -170,7 +170,7 @@ public final class TLocale implements TCloneable, TSerializable { return countries.get(country).getValue(); } - public final String getDisplayLanguage() { + public String getDisplayLanguage() { return getDisplayLanguage(getDefault()); } @@ -193,7 +193,7 @@ public final class TLocale implements TCloneable, TSerializable { return languages.get(language).getValue(); } - public final String getDisplayName() { + public String getDisplayName() { return getDisplayName(getDefault()); } @@ -226,7 +226,7 @@ public final class TLocale implements TCloneable, TSerializable { return buffer.toString(); } - public final String getDisplayVariant() { + public String getDisplayVariant() { return getDisplayVariant(getDefault()); } @@ -257,7 +257,7 @@ public final class TLocale implements TCloneable, TSerializable { } @Override - public final String toString() { + public String toString() { StringBuilder result = new StringBuilder(); result.append(languageCode); if (countryCode.length() > 0) { diff --git a/teavm-classlib/src/main/java/org/teavm/classlib/java/util/TMap.java b/teavm-classlib/src/main/java/org/teavm/classlib/java/util/TMap.java index a11e31be9..ed65f8ba9 100644 --- a/teavm-classlib/src/main/java/org/teavm/classlib/java/util/TMap.java +++ b/teavm-classlib/src/main/java/org/teavm/classlib/java/util/TMap.java @@ -22,7 +22,7 @@ package org.teavm.classlib.java.util; * @param */ public interface TMap { - public static interface Entry { + public interface Entry { K1 getKey(); V1 getValue(); @@ -44,7 +44,7 @@ public interface TMap { V remove(Object key); - void putAll(TMap m); + void putAll(TMap m); void clear(); diff --git a/teavm-classlib/src/main/java/org/teavm/classlib/java/util/TObjects.java b/teavm-classlib/src/main/java/org/teavm/classlib/java/util/TObjects.java index 5f3114ecf..f3ac8d02b 100644 --- a/teavm-classlib/src/main/java/org/teavm/classlib/java/util/TObjects.java +++ b/teavm-classlib/src/main/java/org/teavm/classlib/java/util/TObjects.java @@ -64,35 +64,35 @@ public final class TObjects extends TObject { return b == null; } if (a instanceof boolean[]) { - return b instanceof boolean[] && TArrays.equals((boolean[])a, (boolean[])b); + return b instanceof boolean[] && TArrays.equals((boolean[]) a, (boolean[]) b); } else if (b instanceof boolean[]) { return false; } else if (a instanceof byte[]) { - return b instanceof byte[] && TArrays.equals((byte[])a, (byte[])b); + return b instanceof byte[] && TArrays.equals((byte[]) a, (byte[]) b); } else if (b instanceof byte[]) { return false; } else if (a instanceof short[]) { - return b instanceof short[] && TArrays.equals((short[])a, (short[])b); + return b instanceof short[] && TArrays.equals((short[]) a, (short[]) b); } else if (b instanceof short[]) { return false; } else if (a instanceof int[]) { - return b instanceof int[] && TArrays.equals((int[])a, (int[])b); + return b instanceof int[] && TArrays.equals((int[]) a, (int[]) b); } else if (b instanceof int[]) { return false; } else if (a instanceof char[]) { - return b instanceof char[] && TArrays.equals((char[])a, (char[])b); + return b instanceof char[] && TArrays.equals((char[]) a, (char[]) b); } else if (b instanceof char[]) { return false; } else if (a instanceof float[]) { - return b instanceof float[] && TArrays.equals((float[])a, (float[])b); + return b instanceof float[] && TArrays.equals((float[]) a, (float[]) b); } else if (b instanceof float[]) { return false; } else if (a instanceof double[]) { - return b instanceof double[] && TArrays.equals((double[])a, (double[])b); + return b instanceof double[] && TArrays.equals((double[]) a, (double[]) b); } else if (b instanceof double[]) { return false; } else if (a instanceof Object[]) { - return b instanceof Object[] && TArrays.deepEquals((Object[])a, (Object[])b); + return b instanceof Object[] && TArrays.deepEquals((Object[]) a, (Object[]) b); } else if (b instanceof Object[]) { return false; } else { diff --git a/teavm-classlib/src/main/java/org/teavm/classlib/java/util/TObservable.java b/teavm-classlib/src/main/java/org/teavm/classlib/java/util/TObservable.java index f8af26322..59c764f34 100644 --- a/teavm-classlib/src/main/java/org/teavm/classlib/java/util/TObservable.java +++ b/teavm-classlib/src/main/java/org/teavm/classlib/java/util/TObservable.java @@ -1,17 +1,17 @@ /* - * Copyright 2015 Steve Hannah. + * Copyright 2015 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.util; @@ -22,7 +22,7 @@ package org.teavm.classlib.java.util; public class TObservable { TList observers = new TArrayList<>(); - boolean changed = false; + boolean changed; /** * Constructs a new {@code Observable} object. @@ -43,8 +43,9 @@ public class TObservable { throw new NullPointerException(); } synchronized (this) { - if (!observers.contains(observer)) + if (!observers.contains(observer)) { observers.add(observer); + } } } diff --git a/teavm-classlib/src/main/java/org/teavm/classlib/java/util/TObserver.java b/teavm-classlib/src/main/java/org/teavm/classlib/java/util/TObserver.java index 7de864f4f..c802a3c32 100644 --- a/teavm-classlib/src/main/java/org/teavm/classlib/java/util/TObserver.java +++ b/teavm-classlib/src/main/java/org/teavm/classlib/java/util/TObserver.java @@ -1,17 +1,17 @@ /* - * Copyright 2015 Steve Hannah. + * Copyright 2015 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.util; @@ -23,9 +23,9 @@ package org.teavm.classlib.java.util; public interface TObserver { /** * This method is called if the specified {@code Observable} object's - * {@code notifyObservers} method is called (because the {@code Observable} + * {@code notifyObservers} method is called (because the {@code Observable} * object has been updated. - * + * * @param observable * the {@link Observable} object. * @param data diff --git a/teavm-classlib/src/main/java/org/teavm/classlib/java/util/TPriorityQueue.java b/teavm-classlib/src/main/java/org/teavm/classlib/java/util/TPriorityQueue.java index 4462196af..b3af901cc 100644 --- a/teavm-classlib/src/main/java/org/teavm/classlib/java/util/TPriorityQueue.java +++ b/teavm-classlib/src/main/java/org/teavm/classlib/java/util/TPriorityQueue.java @@ -44,9 +44,9 @@ public class TPriorityQueue extends TAbstractQueue implements TSerializabl public TPriorityQueue(TCollection c) { if (c instanceof TPriorityQueue) { - initFromPriorityQueue((TPriorityQueue)c); + initFromPriorityQueue((TPriorityQueue) c); } else if (c instanceof TSortedSet) { - initFromSortedSet((TSortedSet)c); + initFromSortedSet((TSortedSet) c); } else { data = new Object[c.size()]; fillFromCollection(c); @@ -65,7 +65,7 @@ public class TPriorityQueue extends TAbstractQueue implements TSerializabl @SuppressWarnings("unchecked") private void initFromSortedSet(TSortedSet sortedSet) { data = new Object[sortedSet.size()]; - setComparator((TComparator)sortedSet.comparator()); + setComparator((TComparator) sortedSet.comparator()); fillFromCollection(sortedSet); } @@ -73,7 +73,7 @@ public class TPriorityQueue extends TAbstractQueue implements TSerializabl private void initFromPriorityQueue(TPriorityQueue prirityQueue) { data = Arrays.copyOf(prirityQueue.data, prirityQueue.size); size = prirityQueue.size; - setComparator((TComparator)prirityQueue.comparator()); + setComparator((TComparator) prirityQueue.comparator()); } private void fillFromCollection(TCollection c) { @@ -98,14 +98,14 @@ public class TPriorityQueue extends TAbstractQueue implements TSerializabl comparator = new TComparator() { @Override public int compare(Object o1, Object o2) { if (o1 instanceof TComparable) { - return ((TComparable)o1).compareTo(o2); + return ((TComparable) o1).compareTo(o2); } else { - return -((TComparable)o2).compareTo(o1); + return -((TComparable) o2).compareTo(o1); } } }; } - this.comparator = (TComparator)comparator; + this.comparator = (TComparator) comparator; } public TComparator comparator() { @@ -140,7 +140,7 @@ public class TPriorityQueue extends TAbstractQueue implements TSerializabl return null; } @SuppressWarnings("unchecked") - E elem = (E)data[0]; + E elem = (E) data[0]; removeAt(0); return elem; } @@ -151,7 +151,7 @@ public class TPriorityQueue extends TAbstractQueue implements TSerializabl if (size == 0) { return null; } - return (E)data[0]; + return (E) data[0]; } @Override @@ -176,7 +176,7 @@ public class TPriorityQueue extends TAbstractQueue implements TSerializabl throw new TConcurrentModificationException(); } removeIndex = index; - return (E)data[index++]; + return (E) data[index++]; } @Override public void remove() { if (version != knownVersion) { diff --git a/teavm-classlib/src/main/java/org/teavm/classlib/java/util/TRandom.java b/teavm-classlib/src/main/java/org/teavm/classlib/java/util/TRandom.java index f48ff258b..e0a59de83 100644 --- a/teavm-classlib/src/main/java/org/teavm/classlib/java/util/TRandom.java +++ b/teavm-classlib/src/main/java/org/teavm/classlib/java/util/TRandom.java @@ -35,12 +35,12 @@ public class TRandom extends TObject implements TSerializable { } protected int next(int bits) { - return (int)(random() * (1L << TMath.min(32, bits))); + return (int) (random() * (1L << TMath.min(32, bits))); } public void nextBytes(byte[] bytes) { for (int i = 0; i < bytes.length; ++i) { - bytes[i] = (byte)next(8); + bytes[i] = (byte) next(8); } } @@ -49,11 +49,11 @@ public class TRandom extends TObject implements TSerializable { } public int nextInt(int n) { - return (int)(random() * n); + return (int) (random() * n); } public long nextLong() { - return ((long)nextInt() << 32) | nextInt(); + return ((long) nextInt() << 32) | nextInt(); } public boolean nextBoolean() { @@ -61,7 +61,7 @@ public class TRandom extends TObject implements TSerializable { } public float nextFloat() { - return (float)random(); + return (float) random(); } public double nextDouble() { diff --git a/teavm-classlib/src/main/java/org/teavm/classlib/java/util/TServiceLoader.java b/teavm-classlib/src/main/java/org/teavm/classlib/java/util/TServiceLoader.java index 0e628b5b9..6d917f816 100644 --- a/teavm-classlib/src/main/java/org/teavm/classlib/java/util/TServiceLoader.java +++ b/teavm-classlib/src/main/java/org/teavm/classlib/java/util/TServiceLoader.java @@ -41,7 +41,7 @@ public final class TServiceLoader extends TObject implements TIterable { if (index == services.length) { throw new TNoSuchElementException(); } - return (S)services[index++]; + return (S) services[index++]; } @Override public void remove() { throw new TUnsupportedOperationException(); diff --git a/teavm-classlib/src/main/java/org/teavm/classlib/java/util/TStringTokenizer.java b/teavm-classlib/src/main/java/org/teavm/classlib/java/util/TStringTokenizer.java index dc1e35f50..d41e99de3 100644 --- a/teavm-classlib/src/main/java/org/teavm/classlib/java/util/TStringTokenizer.java +++ b/teavm-classlib/src/main/java/org/teavm/classlib/java/util/TStringTokenizer.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.util; public class TStringTokenizer implements TEnumeration { @@ -37,8 +35,9 @@ public class TStringTokenizer implements TEnumeration { this.delimiters = delimiters; this.returnDelimiters = returnDelimiters; this.position = 0; - } else + } else { throw new NullPointerException(); + } } public int countTokens() { @@ -46,8 +45,9 @@ public class TStringTokenizer implements TEnumeration { boolean inToken = false; for (int i = position, length = string.length(); i < length; i++) { if (delimiters.indexOf(string.charAt(i), 0) >= 0) { - if (returnDelimiters) + if (returnDelimiters) { count++; + } if (inToken) { count++; inToken = false; @@ -56,8 +56,9 @@ public class TStringTokenizer implements TEnumeration { inToken = true; } } - if (inToken) + if (inToken) { count++; + } return count; } @@ -72,14 +73,17 @@ public class TStringTokenizer implements TEnumeration { } int length = string.length(); if (position < length) { - if (returnDelimiters) - return true; // there is at least one character and even if - // it is a delimiter it is a token - + if (returnDelimiters) { + return true; + // there is at least one character and even if + //it is a delimiter it is a token + } // otherwise find a character which is not a delimiter - for (int i = position; i < length; i++) - if (delimiters.indexOf(string.charAt(i), 0) == -1) + for (int i = position; i < length; i++) { + if (delimiters.indexOf(string.charAt(i), 0) == -1) { return true; + } + } } return false; } diff --git a/teavm-classlib/src/main/java/org/teavm/classlib/java/util/TTimeZone.java b/teavm-classlib/src/main/java/org/teavm/classlib/java/util/TTimeZone.java index 1b31e2868..dcf3b28af 100644 --- a/teavm-classlib/src/main/java/org/teavm/classlib/java/util/TTimeZone.java +++ b/teavm-classlib/src/main/java/org/teavm/classlib/java/util/TTimeZone.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.util; import java.io.Serializable; @@ -87,7 +85,7 @@ public abstract class TTimeZone implements Serializable, Cloneable { private static TTimeZone defaultTz; - static TTimeZone GMT = new TIANATimeZone(new FixedDateTimeZone("GMT", 0, 0)); + static final TTimeZone GMT = new TIANATimeZone(new FixedDateTimeZone("GMT", 0, 0)); private String id; @@ -345,7 +343,8 @@ public abstract class TTimeZone implements Serializable, Cloneable { private static String formatTimeZoneName(String name, int offset) { StringBuilder buf = new StringBuilder(); - int index = offset, length = name.length(); + int index = offset; + int length = name.length(); buf.append(name.substring(0, offset)); while (index < length) { @@ -400,9 +399,15 @@ public abstract class TTimeZone implements Serializable, Cloneable { abstract public boolean inDaylightTime(TDate time); private static int parseNumber(String string, int offset, int[] position) { - int index = offset, length = string.length(), digit, result = 0; - while (index < length - && (digit = Character.digit(string.charAt(index), 10)) != -1) { + int index = offset; + int length = string.length(); + int digit; + int result = 0; + while (index < length) { + digit = Character.digit(string.charAt(index), 10); + if (digit == -1) { + break; + } index++; result = result * 10 + digit; } @@ -420,7 +425,7 @@ public abstract class TTimeZone implements Serializable, Cloneable { * a {@code TimeZone} object. */ public static void setDefault(TTimeZone timezone) { - defaultTz = timezone != null ? (TTimeZone)timezone.clone() : null; + defaultTz = timezone != null ? (TTimeZone) timezone.clone() : null; } /** @@ -483,7 +488,7 @@ public abstract class TTimeZone implements Serializable, Cloneable { if (obj == null || obj.getClass() != TTimeZone.class) { return false; } - TTimeZone other = (TTimeZone)obj; + TTimeZone other = (TTimeZone) obj; return this.id.equals(other.id); } diff --git a/teavm-classlib/src/main/java/org/teavm/classlib/java/util/TTimer.java b/teavm-classlib/src/main/java/org/teavm/classlib/java/util/TTimer.java index c252d642f..06da728ae 100644 --- a/teavm-classlib/src/main/java/org/teavm/classlib/java/util/TTimer.java +++ b/teavm-classlib/src/main/java/org/teavm/classlib/java/util/TTimer.java @@ -51,7 +51,7 @@ public class TTimer extends TObject { throw new TIllegalStateException(); } task.timer = this; - task.nativeTimerId = ((Window)JS.getGlobal()).setTimeout(new TimerHandler() { + task.nativeTimerId = ((Window) JS.getGlobal()).setTimeout(new TimerHandler() { @Override public void onTimer() { new Thread() { @@ -64,7 +64,7 @@ public class TTimer extends TObject { } }.start(); } - }, (int)delay); + }, (int) delay); } public void schedule(final TTimerTask task, long delay, final long period) { @@ -72,7 +72,7 @@ public class TTimer extends TObject { throw new TIllegalStateException(); } task.timer = this; - task.nativeTimerId = ((Window)JS.getGlobal()).setTimeout(new TimerHandler() { + task.nativeTimerId = ((Window) JS.getGlobal()).setTimeout(new TimerHandler() { @Override public void onTimer() { final TimerHandler self = this; @@ -82,7 +82,7 @@ public class TTimer extends TObject { if (cancelled || task.timer == null) { return; } - task.nativeTimerId = ((Window)JS.getGlobal()).setTimeout(self, (int)period); + task.nativeTimerId = ((Window) JS.getGlobal()).setTimeout(self, (int) period); TTimerTask.performOnce(task); if (!cancelled) { task.timer = TTimer.this; @@ -90,6 +90,6 @@ public class TTimer extends TObject { } }.start(); } - }, (int)delay); + }, (int) delay); } } diff --git a/teavm-classlib/src/main/java/org/teavm/classlib/java/util/TTreeMap.java b/teavm-classlib/src/main/java/org/teavm/classlib/java/util/TTreeMap.java index e3c888c36..8a834e28e 100644 --- a/teavm-classlib/src/main/java/org/teavm/classlib/java/util/TTreeMap.java +++ b/teavm-classlib/src/main/java/org/teavm/classlib/java/util/TTreeMap.java @@ -94,12 +94,12 @@ public class TTreeMap extends TAbstractMap implements TCloneable, TS private TComparator comparator; private TComparator originalComparator; private TComparator revertedComparator; - private int modCount = 0; + private int modCount; private EntrySet cachedEntrySet; private NavigableKeySet cachedNavigableKeySet; public TTreeMap() { - this((TComparator)null); + this((TComparator) null); } public TTreeMap(TComparator comparator) { @@ -107,8 +107,8 @@ public class TTreeMap extends TAbstractMap implements TCloneable, TS if (comparator == null) { comparator = new TComparator() { @SuppressWarnings("unchecked") @Override public int compare(Object o1, Object o2) { - return o1 != null ? ((TComparable)o1).compareTo(o2) : - ((TComparable)o2).compareTo(o1); + return o1 != null ? ((TComparable) o1).compareTo(o2) + : ((TComparable) o2).compareTo(o1); } }; } @@ -116,9 +116,9 @@ public class TTreeMap extends TAbstractMap implements TCloneable, TS } public TTreeMap(TMap m) { - this((TComparator)null); + this((TComparator) null); @SuppressWarnings("unchecked") - Entry[] entries = (Entry[])new Entry[m.size()]; + Entry[] entries = (Entry[]) new Entry[m.size()]; entries = m.entrySet().toArray(entries); TArrays.sort(entries, new TComparator>() { @Override public int compare(Entry o1, Entry o2) { @@ -131,7 +131,7 @@ public class TTreeMap extends TAbstractMap implements TCloneable, TS public TTreeMap(TSortedMap m) { this(m.comparator()); @SuppressWarnings("unchecked") - Entry[] entries = (Entry[])new Entry[m.size()]; + Entry[] entries = (Entry[]) new Entry[m.size()]; entries = m.entrySet().toArray(entries); fillMap(entries); } @@ -211,7 +211,7 @@ public class TTreeMap extends TAbstractMap implements TCloneable, TS TreeNode node = root; while (node != null) { @SuppressWarnings("unchecked") - int cmp = comparator.compare((K)key, node.getKey()); + int cmp = comparator.compare((K) key, node.getKey()); if (cmp == 0) { return node; } else if (cmp < 0) { @@ -228,7 +228,7 @@ public class TTreeMap extends TAbstractMap implements TCloneable, TS TreeNode lastForward = null; while (node != null) { @SuppressWarnings("unchecked") - int cmp = comparator.compare((K)key, node.getKey()); + int cmp = comparator.compare((K) key, node.getKey()); if (reverse) { cmp = -cmp; } @@ -246,12 +246,12 @@ public class TTreeMap extends TAbstractMap implements TCloneable, TS TreeNode[] pathToExactOrNext(Object key, boolean reverse) { @SuppressWarnings("unchecked") - TreeNode[] path = (TreeNode[])new TreeNode[height()]; + TreeNode[] path = (TreeNode[]) new TreeNode[height()]; int depth = 0; TreeNode node = root; while (node != null) { @SuppressWarnings("unchecked") - int cmp = comparator.compare((K)key, node.getKey()); + int cmp = comparator.compare((K) key, node.getKey()); if (reverse) { cmp = -cmp; } @@ -273,7 +273,7 @@ public class TTreeMap extends TAbstractMap implements TCloneable, TS TreeNode lastForward = null; while (node != null) { @SuppressWarnings("unchecked") - int cmp = comparator.compare((K)key, node.getKey()); + int cmp = comparator.compare((K) key, node.getKey()); if (reverse) { cmp = -cmp; } @@ -289,12 +289,12 @@ public class TTreeMap extends TAbstractMap implements TCloneable, TS TreeNode[] pathToNext(Object key, boolean reverse) { @SuppressWarnings("unchecked") - TreeNode[] path = (TreeNode[])new TreeNode[height()]; + TreeNode[] path = (TreeNode[]) new TreeNode[height()]; int depth = 0; TreeNode node = root; while (node != null) { @SuppressWarnings("unchecked") - int cmp = comparator.compare((K)key, node.getKey()); + int cmp = comparator.compare((K) key, node.getKey()); if (reverse) { cmp = -cmp; } @@ -310,7 +310,7 @@ public class TTreeMap extends TAbstractMap implements TCloneable, TS TreeNode[] pathToFirst(boolean reverse) { @SuppressWarnings("unchecked") - TreeNode[] path = (TreeNode[])new TreeNode[height()]; + TreeNode[] path = (TreeNode[]) new TreeNode[height()]; int depth = 0; TreeNode node = root; while (node != null) { @@ -341,7 +341,7 @@ public class TTreeMap extends TAbstractMap implements TCloneable, TS return null; } @SuppressWarnings("unchecked") - int cmp = comparator.compare((K)key, root.getKey()); + int cmp = comparator.compare((K) key, root.getKey()); if (cmp < 0) { root.left = deleteNode(root.left, key); } else if (cmp > 0) { @@ -353,7 +353,7 @@ public class TTreeMap extends TAbstractMap implements TCloneable, TS TreeNode right = root.right; TreeNode min = right; @SuppressWarnings("unchecked") - TreeNode[] pathToMin = (TreeNode[])new TreeNode[right.height]; + TreeNode[] pathToMin = (TreeNode[]) new TreeNode[right.height]; int minDepth = 0; while (min.left != null) { pathToMin[minDepth++] = min; @@ -551,7 +551,7 @@ public class TTreeMap extends TAbstractMap implements TCloneable, TS @Override public Object clone() { - TTreeMap copy = (TTreeMap)super.clone(); + TTreeMap copy = (TTreeMap) super.clone(); copy.cachedEntrySet = null; return copy; } @@ -587,8 +587,8 @@ public class TTreeMap extends TAbstractMap implements TCloneable, TS modCount = owner.modCount; size = owner.size(); if (fromChecked) { - TreeNode[] path = fromIncluded ? owner.pathToNext(from, true) : - owner.pathToExactOrNext(from, true); + TreeNode[] path = fromIncluded ? owner.pathToNext(from, true) + : owner.pathToExactOrNext(from, true); for (TreeNode node : path) { if (node.left != null) { size -= node.left.size; @@ -597,8 +597,8 @@ public class TTreeMap extends TAbstractMap implements TCloneable, TS size -= path.length; } if (toChecked) { - TreeNode path[] = toIncluded ? owner.pathToNext(to, false) : - owner.pathToExactOrNext(to, false); + TreeNode[] path = toIncluded ? owner.pathToNext(to, false) + : owner.pathToExactOrNext(to, false); for (TreeNode node : path) { if (node.right != null) { size -= node.right.size; @@ -653,18 +653,18 @@ public class TTreeMap extends TAbstractMap implements TCloneable, TS if (!(o instanceof Entry)) { return false; } - Entry entry = (Entry)o; + Entry entry = (Entry) o; Object key = entry.getKey(); if (from != null) { @SuppressWarnings("unchecked") - int cmp = owner.comparator.compare((K)key, from); + int cmp = owner.comparator.compare((K) key, from); if (fromIncluded ? cmp < 0 : cmp <= 0) { return false; } } if (to != null) { @SuppressWarnings("unchecked") - int cmp = owner.comparator.compare((K)key, to); + int cmp = owner.comparator.compare((K) key, to); if (toIncluded ? cmp > 0 : cmp >= 0) { return false; } @@ -810,7 +810,7 @@ public class TTreeMap extends TAbstractMap implements TCloneable, TS @SuppressWarnings("unchecked") @Override public V get(Object key) { - if (!keyInRange((K)key)) { + if (!keyInRange((K) key)) { return null; } return owner.get(key); @@ -819,7 +819,7 @@ public class TTreeMap extends TAbstractMap implements TCloneable, TS @SuppressWarnings("unchecked") @Override public V remove(Object key) { - if (!keyInRange((K)key)) { + if (!keyInRange((K) key)) { return null; } return owner.remove(key); @@ -847,8 +847,8 @@ public class TTreeMap extends TAbstractMap implements TCloneable, TS modCount = owner.modCount; size = owner.size(); if (fromChecked) { - TreeNode[] path = fromIncluded ? owner.pathToNext(from, true) : - owner.pathToExactOrNext(from, true); + TreeNode[] path = fromIncluded ? owner.pathToNext(from, true) + : owner.pathToExactOrNext(from, true); for (TreeNode node : path) { if (node.left != null) { size -= node.left.size; @@ -857,8 +857,8 @@ public class TTreeMap extends TAbstractMap implements TCloneable, TS size -= path.length; } if (toChecked) { - TreeNode path[] = toIncluded ? owner.pathToNext(to, false) : - owner.pathToExactOrNext(to, false); + TreeNode[] path = toIncluded ? owner.pathToNext(to, false) + : owner.pathToExactOrNext(to, false); for (TreeNode node : path) { if (node.right != null) { size -= node.right.size; @@ -875,14 +875,14 @@ public class TTreeMap extends TAbstractMap implements TCloneable, TS public boolean containsKey(Object key) { if (fromChecked) { @SuppressWarnings("unchecked") - int cmp = owner.comparator.compare((K)key, from); + int cmp = owner.comparator.compare((K) key, from); if (fromIncluded ? cmp < 0 : cmp <= 0) { return false; } } if (toChecked) { @SuppressWarnings("unchecked") - int cmp = owner.comparator.compare((K)key, to); + int cmp = owner.comparator.compare((K) key, to); if (fromIncluded ? cmp > 0 : cmp >= 0) { return false; } diff --git a/teavm-classlib/src/main/java/org/teavm/classlib/java/util/TTreeSet.java b/teavm-classlib/src/main/java/org/teavm/classlib/java/util/TTreeSet.java index 034551234..408a718f3 100644 --- a/teavm-classlib/src/main/java/org/teavm/classlib/java/util/TTreeSet.java +++ b/teavm-classlib/src/main/java/org/teavm/classlib/java/util/TTreeSet.java @@ -1,3 +1,18 @@ +/* + * Copyright 2014 Alexey Andreev. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package org.teavm.classlib.java.util; /** diff --git a/teavm-classlib/src/main/java/org/teavm/classlib/java/util/TVector.java b/teavm-classlib/src/main/java/org/teavm/classlib/java/util/TVector.java index ebe4e2ff3..6c1ac8e91 100644 --- a/teavm-classlib/src/main/java/org/teavm/classlib/java/util/TVector.java +++ b/teavm-classlib/src/main/java/org/teavm/classlib/java/util/TVector.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,23 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -/* - * 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 - * - * 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.util; import java.lang.reflect.Array; @@ -174,7 +156,7 @@ public class TVector extends TAbstractList implements TList, TRandomAcc public TEnumeration elements() { return new TEnumeration() { - int pos = 0; + int pos; @Override public boolean hasMoreElements() { @@ -215,7 +197,8 @@ public class TVector extends TAbstractList implements TList, TRandomAcc int index = 0; TIterator it = list.iterator(); while (it.hasNext()) { - Object e1 = elementData[index++], e2 = it.next(); + Object e1 = elementData[index++]; + Object e2 = it.next(); if (!(e1 == null ? e2 == null : e1.equals(e2))) { return false; } @@ -252,7 +235,8 @@ public class TVector extends TAbstractList implements TList, TRandomAcc private void growByOne() { int adding = 0; if (capacityIncrement <= 0) { - if ((adding = elementData.length) == 0) { + adding = elementData.length; + if (adding == 0) { adding = 1; } } else { @@ -267,7 +251,8 @@ public class TVector extends TAbstractList implements TList, TRandomAcc private void growBy(int required) { int adding = 0; if (capacityIncrement <= 0) { - if ((adding = elementData.length) == 0) { + adding = elementData.length; + if (adding == 0) { adding = required; } while (adding < required) { @@ -411,8 +396,8 @@ public class TVector extends TAbstractList implements TList, TRandomAcc } public synchronized boolean removeElement(Object object) { - int index; - if ((index = indexOf(object, 0)) == -1) { + int index = indexOf(object, 0); + if (index == -1) { return false; } removeElementAt(index); @@ -522,7 +507,7 @@ public class TVector extends TAbstractList implements TList, TRandomAcc @Override public synchronized String toString() { if (elementCount == 0) { - return "[]"; //$NON-NLS-1$ + return "[]"; } int length = elementCount - 1; StringBuilder buffer = new StringBuilder(elementCount * 16); diff --git a/teavm-classlib/src/main/java/org/teavm/classlib/java/util/regex/TAbstractCharClass.java b/teavm-classlib/src/main/java/org/teavm/classlib/java/util/regex/TAbstractCharClass.java index 783f01b47..114e9bf29 100644 --- a/teavm-classlib/src/main/java/org/teavm/classlib/java/util/regex/TAbstractCharClass.java +++ b/teavm-classlib/src/main/java/org/teavm/classlib/java/util/regex/TAbstractCharClass.java @@ -52,13 +52,13 @@ abstract class TAbstractCharClass extends TSpecialToken { protected boolean altSurrogates; // Character.MAX_SURROGATE - Character.MIN_SURROGATE + 1 - static int SURROGATE_CARDINALITY = 2048; + static final int SURROGATE_CARDINALITY = 2048; BitSet lowHighSurrogates = new BitSet(SURROGATE_CARDINALITY); - TAbstractCharClass charClassWithoutSurrogates = null; + TAbstractCharClass charClassWithoutSurrogates; - TAbstractCharClass charClassWithSurrogates = null; + TAbstractCharClass charClassWithSurrogates; static PredefinedCharacterClasses charClasses = new PredefinedCharacterClasses(); @@ -67,7 +67,7 @@ abstract class TAbstractCharClass extends TSpecialToken { * this flag is specified it doesn't mean that this class contains * supplementary characters but may contain. */ - protected boolean mayContainSupplCodepoints = false; + protected boolean mayContainSupplCodepoints; abstract public boolean contains(int ch); @@ -113,8 +113,8 @@ abstract class TAbstractCharClass extends TSpecialToken { public boolean contains(int ch) { int index = ch - Character.MIN_SURROGATE; - return ((index >= 0) && (index < TAbstractCharClass.SURROGATE_CARDINALITY)) ? this.altSurrogates ^ - lHS.get(index) : false; + return ((index >= 0) && (index < TAbstractCharClass.SURROGATE_CARDINALITY)) ? this.altSurrogates + ^ lHS.get(index) : false; } }; charClassWithSurrogates.setNegative(this.altSurrogates); @@ -133,8 +133,8 @@ abstract class TAbstractCharClass extends TSpecialToken { public boolean contains(int ch) { int index = ch - Character.MIN_SURROGATE; - boolean containslHS = ((index >= 0) && (index < TAbstractCharClass.SURROGATE_CARDINALITY)) ? this.altSurrogates ^ - lHS.get(index) + boolean containslHS = (index >= 0 && index < TAbstractCharClass.SURROGATE_CARDINALITY) + ? this.altSurrogates ^ lHS.get(index) : false; return thisClass.contains(ch) && !containslHS; @@ -179,19 +179,20 @@ abstract class TAbstractCharClass extends TSpecialToken { } public static boolean intersects(TAbstractCharClass cc1, TAbstractCharClass cc2) { - if (cc1.getBits() == null || cc2.getBits() == null) + if (cc1.getBits() == null || cc2.getBits() == null) { return true; + } return cc1.getBits().intersects(cc2.getBits()); } public static TAbstractCharClass getPredefinedClass(String name, boolean negative) { - return ((LazyCharClass)charClasses.getObject(name)).getValue(negative); + return ((LazyCharClass) charClasses.getObject(name)).getValue(negative); } abstract static class LazyCharClass { - TAbstractCharClass posValue = null; + TAbstractCharClass posValue; - TAbstractCharClass negValue = null; + TAbstractCharClass negValue; public TAbstractCharClass getValue(boolean negative) { if (!negative && posValue == null) { @@ -199,8 +200,9 @@ abstract class TAbstractCharClass extends TSpecialToken { } else if (negative && negValue == null) { negValue = computeValue().setNegative(true); } - if (!negative) + if (!negative) { return posValue; + } return negValue; } @@ -290,7 +292,7 @@ abstract class TAbstractCharClass extends TSpecialToken { static class LazyAlnum extends LazyAlpha { @Override protected TAbstractCharClass computeValue() { - return ((TCharClass)super.computeValue()).add('0', '9'); + return ((TCharClass) super.computeValue()).add('0', '9'); } } @@ -306,14 +308,14 @@ abstract class TAbstractCharClass extends TSpecialToken { @Override protected TAbstractCharClass computeValue() { /* plus punctuation */ - return ((TCharClass)super.computeValue()).add(0x21, 0x40).add(0x5B, 0x60).add(0x7B, 0x7E); + return ((TCharClass) super.computeValue()).add(0x21, 0x40).add(0x5B, 0x60).add(0x7B, 0x7E); } } static class LazyPrint extends LazyGraph { @Override protected TAbstractCharClass computeValue() { - return ((TCharClass)super.computeValue()).add(0x20); + return ((TCharClass) super.computeValue()).add(0x20); } } @@ -339,7 +341,8 @@ abstract class TAbstractCharClass extends TSpecialToken { } static class LazyRange extends LazyCharClass { - int start, end; + int start; + int end; public LazyRange(int start, int end) { this.start = start; @@ -848,10 +851,10 @@ abstract class TAbstractCharClass extends TSpecialToken { { "Cs", new LazyCategory(Character.SURROGATE, false, true) }, { "IsP", - new LazyCategoryScope((1 << Character.DASH_PUNCTUATION) | (1 << Character.START_PUNCTUATION) | - (1 << Character.END_PUNCTUATION) | (1 << Character.CONNECTOR_PUNCTUATION) | - (1 << Character.OTHER_PUNCTUATION) | (1 << Character.INITIAL_QUOTE_PUNCTUATION) | - (1 << Character.FINAL_QUOTE_PUNCTUATION), true) }, + new LazyCategoryScope((1 << Character.DASH_PUNCTUATION) | (1 << Character.START_PUNCTUATION) + | (1 << Character.END_PUNCTUATION) | (1 << Character.CONNECTOR_PUNCTUATION) + | (1 << Character.OTHER_PUNCTUATION) | (1 << Character.INITIAL_QUOTE_PUNCTUATION) + | (1 << Character.FINAL_QUOTE_PUNCTUATION), true) }, { "Pd", new LazyCategory(Character.DASH_PUNCTUATION, false) }, { "Ps", new LazyCategory(Character.START_PUNCTUATION, false) }, { "Pe", new LazyCategory(Character.END_PUNCTUATION, false) }, diff --git a/teavm-core/pom.xml b/teavm-core/pom.xml index 38849b528..798a6b5a8 100644 --- a/teavm-core/pom.xml +++ b/teavm-core/pom.xml @@ -45,10 +45,6 @@ hppc 0.6.1 - - org.checkerframework - checker - TeaVM core diff --git a/teavm-html4j/pom.xml b/teavm-html4j/pom.xml index bffacb498..0941950de 100644 --- a/teavm-html4j/pom.xml +++ b/teavm-html4j/pom.xml @@ -66,6 +66,20 @@ + + net.orfjackal.retrolambda + retrolambda-maven-plugin + 1.8.1 + + + retrolambda + process-classes + + process-main + + + + org.teavm teavm-maven-plugin diff --git a/teavm-jso/pom.xml b/teavm-jso/pom.xml index aaffeb282..26b0cdb7f 100644 --- a/teavm-jso/pom.xml +++ b/teavm-jso/pom.xml @@ -43,6 +43,20 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xs + + net.orfjackal.retrolambda + retrolambda-maven-plugin + 1.8.1 + + + retrolambda + process-classes + + process-main + + + + org.apache.maven.plugins maven-checkstyle-plugin diff --git a/teavm-maven/teavm-maven-plugin/pom.xml b/teavm-maven/teavm-maven-plugin/pom.xml index 5d837d732..019d13541 100644 --- a/teavm-maven/teavm-maven-plugin/pom.xml +++ b/teavm-maven/teavm-maven-plugin/pom.xml @@ -68,11 +68,26 @@ org.apache.maven.plugins maven-plugin-plugin - 3.0 + 3.3 true + mysql-jdbc-compliance + + default-descriptor + + descriptor + + process-classes + + + help-descriptor + + helpmojo + + process-classes + mojo-descriptor diff --git a/teavm-samples/teavm-samples-async/pom.xml b/teavm-samples/teavm-samples-async/pom.xml index 001e04006..36f0db545 100644 --- a/teavm-samples/teavm-samples-async/pom.xml +++ b/teavm-samples/teavm-samples-async/pom.xml @@ -39,6 +39,20 @@ + + net.orfjackal.retrolambda + retrolambda-maven-plugin + 1.8.1 + + + retrolambda + process-classes + + process-main + + + + maven-war-plugin 2.4 diff --git a/teavm-samples/teavm-samples-hello/pom.xml b/teavm-samples/teavm-samples-hello/pom.xml index ed8128e63..a5a198335 100644 --- a/teavm-samples/teavm-samples-hello/pom.xml +++ b/teavm-samples/teavm-samples-hello/pom.xml @@ -58,6 +58,20 @@ + + net.orfjackal.retrolambda + retrolambda-maven-plugin + 1.8.1 + + + retrolambda + process-classes + + process-main + + + + maven-war-plugin 2.4 diff --git a/teavm-samples/teavm-samples-storage/pom.xml b/teavm-samples/teavm-samples-storage/pom.xml index 70d0cc0bc..5115be250 100644 --- a/teavm-samples/teavm-samples-storage/pom.xml +++ b/teavm-samples/teavm-samples-storage/pom.xml @@ -58,6 +58,20 @@ + + net.orfjackal.retrolambda + retrolambda-maven-plugin + 1.8.1 + + + retrolambda + process-classes + + process-main + + + + maven-war-plugin 2.4 diff --git a/teavm-samples/teavm-samples-video/pom.xml b/teavm-samples/teavm-samples-video/pom.xml index 1f64bc021..b512c2bfb 100644 --- a/teavm-samples/teavm-samples-video/pom.xml +++ b/teavm-samples/teavm-samples-video/pom.xml @@ -58,6 +58,20 @@ + + net.orfjackal.retrolambda + retrolambda-maven-plugin + 1.8.1 + + + retrolambda + process-classes + + process-main + + + + maven-war-plugin 2.4