diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml new file mode 100644 index 0000000..68319a1 --- /dev/null +++ b/.github/workflows/codeql-analysis.yml @@ -0,0 +1,72 @@ +# For most projects, this workflow file will not need changing; you simply need +# to commit it to your repository. +# +# You may wish to alter this file to override the set of languages analyzed, +# or to provide custom queries or build logic. +# +# ******** NOTE ******** +# We have attempted to detect the languages in your repository. Please check +# the `language` matrix defined below to confirm you have the correct set of +# supported CodeQL languages. +# ******** NOTE ******** + +name: "CodeQL" + +on: + push: + branches: [ develop ] + pull_request: + # The branches below must be a subset of the branches above + branches: [ develop ] + schedule: + # https://crontab.guru/ + - cron: '25 8 11 * *' + +jobs: + analyze: + name: Analyze + runs-on: ubuntu-latest + + strategy: + fail-fast: false + matrix: + language: [ 'java' ] + # CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python' ] + # Learn more... + # https://docs.github.com/en/github/finding-security-vulnerabilities-and-errors-in-your-code/configuring-code-scanning#overriding-automatic-language-detection + + steps: + - name: Checkout repository + uses: actions/checkout@v2.3.4 + + # Initializes the CodeQL tools for scanning. + - name: Initialize CodeQL + uses: github/codeql-action/init@v1 + with: + languages: ${{ matrix.language }} + # If you wish to specify custom queries, you can do so here or in a config file. + # By default, queries listed here will override any specified in a config file. + # Prefix the list here with "+" to use these queries and those in the config file. + # queries: ./path/to/local/query, your-org/your-repo/queries@main + + # Autobuild attempts to build any compiled languages (C/C++, C#, or Java). + # If this step fails, then you should remove it and run the build manually (see below) + - name: Autobuild + uses: github/codeql-action/autobuild@v1 + + # ℹī¸ Command-line programs to run using the OS shell. + # 📚 https://git.io/JvXDl + + # ✏ī¸ If the Autobuild fails above, remove it and uncomment the following three lines + # and modify them (or add more) to build your code if your project + # uses a compiled language + + #- run: | + # make bootstrap + # make release + + - name: Perform CodeQL Analysis + uses: github/codeql-action/analyze@v1 + + +### EOF ### diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml new file mode 100644 index 0000000..e6e6e10 --- /dev/null +++ b/.github/workflows/maven.yml @@ -0,0 +1,38 @@ +# This workflow will build a Java project with Maven +# For more information see: https://help.github.com/actions/language-and-framework-guides/building-and-testing-java-with-maven + +name: Java CI with Maven + +on: + push: + branches: [ develop ] + pull_request: + branches: [ develop ] + +jobs: + build: + + runs-on: ubuntu-latest + + strategy: + matrix: + java: [ 8, 11, 16 ] + name: Java ${{ matrix.java }} sample + steps: + - uses: actions/checkout@v2.3.4 + - name: Set up JDK + uses: actions/setup-java@v2 + with: + distribution: 'adopt' + java-version: ${{ matrix.java }} + - name: Cache Maven packages + uses: actions/cache@v2.1.5 + with: + path: ~/.m2 + key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }} + restore-keys: ${{ runner.os }}-m2 + - name: Build with Maven + run: mvn --show-version -B package --file pom.xml + + +### EOF ### diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 0d31a76..0000000 --- a/.travis.yml +++ /dev/null @@ -1,20 +0,0 @@ -# Travis CI - -language: java - -sudo: false - -jdk: - - oraclejdk11 - - openjdk13 - - openjdk12 - - openjdk11 - - openjdk10 - - openjdk9 - - openjdk8 - -cache: - directories: - - $HOME/.m2 - -# EOF diff --git a/CHANGELOG.md b/CHANGELOG.md index 26bd987..38b2be6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,56 +1,121 @@ DoubDabC Changelog =================== -## WIP -Released on 20XX-XX-XX +The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), +and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). -## v2.101.10 -Released on 2020-02-02 + +## [Unreleased] + +## [2.101.12] - 2021-05-12 + +### Added +- Add GitHub Actions (JavaCI and CodeQL). + +### Removed +- Remove Travis CI integration. + +### Changed +- Change CHANGELOG.md format to keepchangelog.com style. + +### Security +- responding to junit security issue GHSA-269g-pwp5-87pp + + +## [2.101.10] - 2020-02-02 + +### Security - responding to checkstyle security issue GHSA-763g-fqq7-48wg -## v2.101.8 -Released on 2019-03-19 + +## [2.101.8] - 2019-03-19 + +### Security - responding to checkstyle security issue CVE-2019-9658 -## v2.101.6 -Released on 2018-08-08 -- BugFix: Missing copies when 8N+1 length decimal. Fixed #25 -- Move PMD & Checkstyle config files to folder. + +## [2.101.6] - 2018-08-08 + +### Added - Add Mersenne prime#32 (2^756839 -1) benchmark test. -## v2.101.4 -Released on 2017-06-22 -- Correspond to Maven 3.5 +### Changed +- Move PMD & Checkstyle config files to folder. + +### Fixed +- BugFix: Missing copies when 8N+1 length decimal. Fixed #25 + + +## [2.101.4] - 2017-06-22 + +### Added - add JarabraDix info to README -## v2.101.2 -Released on 2017-04-24 +### Changed +- Correspond to Maven 3.5 + + +## [2.101.2] - 2017-04-24 + +### Added +- Add BcdArrays + +### Changed - Merge DecimalText and DecimalOut to BcdSequence -- Extended Writer class removed. See JarabraDix new project. - Split BcdUtils class from BcdRegister -- Add BcdArrays -## v1.103.2 -Released on 2017-03-22 +### Removed +- Extended Writer class removed. See JarabraDix new project. + + +## [1.103.2] - 2017-03-22 + +### Added - Add DecimalWriter which supports print(int) #16 + +### Removed - Remove overblown terms on perfomance #20 -## v1.102.6 -Released on 2017-02-19 -- Speed-up Arabic-num converting + +## [1.102.6] - 2017-02-19 + +### Added - Add .travis.yml for Travis CI #18 - Add header to Javadoc pages -## v1.102.4 -Released on 2017-02-02 -- Speed-up converting +### Changed +- Speed-up Arabic-num converting + + +## [1.102.4] - 2017-02-02 + +### Added - Add static code analysis report plugin. (checkstyle,PMD,FindBugs) - Add code coverage report plugin. (Jacoco) - Add SCM info to POM. #13 - Add CHANGELOG.md #14 -## v1.101.2 -Released on 2017-01-03 +### Changed +- Speed-up converting + + +## [1.102.2] - 2017-01-03 + +### Added - Initial Release + +[Unreleased]: https://github.com/olyutorskii/DoubDabC/compare/v2.101.12...HEAD +[2.101.12]: https://github.com/olyutorskii/DoubDabC/compare/v2.101.10...v2.101.12 +[2.101.10]: https://github.com/olyutorskii/DoubDabC/compare/v2.101.8...v2.101.10 +[2.101.8]: https://github.com/olyutorskii/DoubDabC/compare/v2.101.6...v2.101.8 +[2.101.6]: https://github.com/olyutorskii/DoubDabC/compare/v2.101.4...v2.101.6 +[2.101.4]: https://github.com/olyutorskii/DoubDabC/compare/v2.101.2...v2.101.4 +[2.101.2]: https://github.com/olyutorskii/DoubDabC/compare/v1.103.2...v2.101.2 +[1.103.2]: https://github.com/olyutorskii/DoubDabC/compare/v1.102.6...v1.103.2 +[1.102.6]: https://github.com/olyutorskii/DoubDabC/compare/v1.102.4...v1.102.6 +[1.102.4]: https://github.com/olyutorskii/DoubDabC/compare/v1.102.2...v1.102.4 +[1.102.2]: https://github.com/olyutorskii/DoubDabC/releases/tag/v1.102.2 + + --- EOF --- diff --git a/README.md b/README.md index f06c9c8..390895b 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,7 @@ # DoubDabC # -[![Build Status](https://travis-ci.org/olyutorskii/DoubDabC.svg?branch=master)](https://travis-ci.org/olyutorskii/DoubDabC) +![Java CI with Maven](https://github.com/olyutorskii/DoubDabC/workflows/Java%20CI%20with%20Maven/badge.svg) +![CodeQL](https://github.com/olyutorskii/DoubDabC/workflows/CodeQL/badge.svg) ----------------------------------------------------------------------- diff --git a/config/checkstyle/checkstyle.xml b/config/checkstyle/checkstyle.xml index fd08674..73babc4 100644 --- a/config/checkstyle/checkstyle.xml +++ b/config/checkstyle/checkstyle.xml @@ -6,7 +6,7 @@ - + @@ -54,7 +54,7 @@ - + @@ -81,7 +81,7 @@ - + @@ -151,6 +151,7 @@ + @@ -178,6 +179,7 @@ + @@ -205,6 +207,7 @@ + @@ -230,6 +233,8 @@ + + + @@ -301,6 +307,7 @@ + @@ -310,6 +317,9 @@ + + + @@ -336,10 +346,12 @@ + + @@ -347,19 +359,7 @@ - + @@ -373,25 +373,8 @@ - - - - - - + + diff --git a/config/pmd/pmdrules.xml b/config/pmd/pmdrules.xml index e46d531..9a1c5fc 100644 --- a/config/pmd/pmdrules.xml +++ b/config/pmd/pmdrules.xml @@ -2,16 +2,16 @@ @@ -29,6 +29,7 @@ + @@ -39,6 +40,7 @@ + @@ -52,13 +54,13 @@ + - diff --git a/pom.xml b/pom.xml index 0e0cca1..6ad99cc 100644 --- a/pom.xml +++ b/pom.xml @@ -16,7 +16,7 @@ io.github.olyutorskii doubdabc - 2.101.10 + 2.101.12 jar DoubDabC @@ -111,7 +111,7 @@ junit junit - 4.13.1 + 4.13.2 test @@ -141,7 +141,7 @@ org.apache.maven.plugins maven-resources-plugin - 3.1.0 + 3.2.0 @@ -153,19 +153,19 @@ org.apache.maven.plugins maven-surefire-plugin - 3.0.0-M4 + 3.0.0-M5 org.apache.maven.plugins maven-surefire-report-plugin - 3.0.0-M4 + 3.0.0-M5 org.jacoco jacoco-maven-plugin - 0.8.5 + 0.8.7 @@ -177,7 +177,7 @@ org.apache.maven.plugins maven-source-plugin - 3.1.0 + 3.2.1 @@ -195,42 +195,42 @@ org.apache.maven.plugins maven-site-plugin - 3.8.2 + 3.9.1 org.apache.maven.plugins maven-assembly-plugin - 3.2.0 + 3.3.0 org.apache.maven.plugins maven-project-info-reports-plugin - 3.0.0 + 3.1.2 org.apache.maven.plugins maven-javadoc-plugin - 3.1.1 + 3.2.0 org.apache.maven.plugins maven-jxr-plugin - 3.0.0 + 3.1.1 org.apache.maven.plugins maven-checkstyle-plugin - 3.1.0 + 3.1.2 com.puppycrawl.tools checkstyle - 8.29 + 8.42 @@ -238,13 +238,32 @@ org.apache.maven.plugins maven-pmd-plugin - 3.12.0 + 3.14.0 + + + net.sourceforge.pmd + pmd-core + 6.34.0 + + + net.sourceforge.pmd + pmd-java + 6.34.0 + + com.github.spotbugs spotbugs-maven-plugin - 3.1.12.2 + 4.2.3 + + + com.github.spotbugs + spotbugs + 4.2.3 + + @@ -294,7 +313,7 @@ - [3.3.9,) + [3.3.9,) [1.8,) @@ -393,6 +412,7 @@ org.apache.maven.plugins maven-assembly-plugin + posix src/assembly/src.xml @@ -404,7 +424,7 @@ maven-pmd-plugin - ${project.basedir}/config/pmd/pmdrules.xml + config/pmd/pmdrules.xml diff --git a/src/main/java/io/github/olyutorskii/doubdabc/BcdArrays.java b/src/main/java/io/github/olyutorskii/doubdabc/BcdArrays.java index 137ba5e..7e8dc27 100644 --- a/src/main/java/io/github/olyutorskii/doubdabc/BcdArrays.java +++ b/src/main/java/io/github/olyutorskii/doubdabc/BcdArrays.java @@ -24,7 +24,7 @@ public final class BcdArrays { /** * Hidden constructor. */ - private BcdArrays(){ + private BcdArrays() { assert false; } @@ -45,7 +45,7 @@ private BcdArrays(){ * @return output length */ public static int int2ArabicArray(final int iVal, - final char[] cbuf, final int offset){ + final char[] cbuf, final int offset) { int iHigh = 0b0; int iLow = 0b0; @@ -53,12 +53,12 @@ public static int int2ArabicArray(final int iVal, boolean noHalfCarry = true; int sig = 0; - for(int bitCt = 0; bitCt < Integer.SIZE; bitCt++){ + for (int bitCt = 0; bitCt < Integer.SIZE; bitCt++) { final int scanMask = MSB_INTMASK >>> bitCt; final int bitAppear = iVal & scanMask; - if(skipLeading){ - if(bitAppear == 0b0) continue; + if (skipLeading) { + if (bitAppear == 0b0) continue; skipLeading = false; } sig++; @@ -69,29 +69,29 @@ public static int int2ArabicArray(final int iVal, bqVal = BcdUtils.toBiQuinary(iLow); shiftedBcd = bqVal << 1; - if(bitAppear == 0b0){ + if (bitAppear == 0b0) { iLow = shiftedBcd; - }else{ + } else { iLow = shiftedBcd | LSB_INTMASK; } // through iHigh // if iLow has 8-bcd "67108863"(2^26-1) or lower - if(sig < 27) continue; + if (sig < 27) continue; int halfCarry = bqVal & MSB_INTMASK; - if(noHalfCarry){ - if(halfCarry == 0b0) continue; + if (noHalfCarry) { + if (halfCarry == 0b0) continue; noHalfCarry = false; } bqVal = BcdUtils.toBiQuinary(iHigh); shiftedBcd = bqVal << 1; - if(halfCarry == 0b0){ + if (halfCarry == 0b0) { iHigh = shiftedBcd; - }else{ + } else { iHigh = shiftedBcd | LSB_INTMASK; } } @@ -99,23 +99,23 @@ public static int int2ArabicArray(final int iVal, int cidx = offset; final int clzLow; - if(iHigh == 0b0){ + if (iHigh == 0b0) { clzLow = BcdUtils.clzNibble(iLow); - }else{ + } else { clzLow = 0; final int clzHigh = BcdUtils.clzNibble(iHigh); - for(int bcdCt = clzHigh; bcdCt < INT_SLOTS; bcdCt++){ + for (int bcdCt = clzHigh; bcdCt < INT_SLOTS; bcdCt++) { final int nibble = (iHigh >>> ((7 - bcdCt) << 2)) & BCD_MASK; - final char decimalCh = (char)(nibble | ARABICUC_MASK); + final char decimalCh = (char) (nibble | ARABICUC_MASK); cbuf[cidx++] = decimalCh; } } - for(int bcdCt = clzLow; bcdCt < INT_SLOTS; bcdCt++){ + for (int bcdCt = clzLow; bcdCt < INT_SLOTS; bcdCt++) { final int nibble = (iLow >>> ((7 - bcdCt) << 2)) & BCD_MASK; - final char decimalCh = (char)(nibble | ARABICUC_MASK); + final char decimalCh = (char) (nibble | ARABICUC_MASK); cbuf[cidx++] = decimalCh; } diff --git a/src/main/java/io/github/olyutorskii/doubdabc/BcdRegister.java b/src/main/java/io/github/olyutorskii/doubdabc/BcdRegister.java index e2815ed..c12ddb9 100644 --- a/src/main/java/io/github/olyutorskii/doubdabc/BcdRegister.java +++ b/src/main/java/io/github/olyutorskii/doubdabc/BcdRegister.java @@ -75,7 +75,7 @@ public class BcdRegister { 'A', 'B', 'C', 'D', 'E', 'F', }; - static{ + static { assert 0b1 << PRIMIDX_SHIFT == PRIM_SLOTS; assert (-1 & NBLIDX_MASK) == PRIM_SLOTS - 1; assert HEXCH_TBL.length == 0b1 << BcdUtils.BCD_BITSIZE; @@ -96,10 +96,10 @@ public class BcdRegister { * @param maxDigits decimal digits to store result. * @throws IllegalArgumentException not positive digits. */ - public BcdRegister(int maxDigits) throws IllegalArgumentException{ + public BcdRegister(int maxDigits) throws IllegalArgumentException { super(); - if(maxDigits <= 0) throw new IllegalArgumentException(); + if (maxDigits <= 0) throw new IllegalArgumentException(); this.maxDigits = fittingContainer(maxDigits); this.ibuf = new int[this.maxDigits / PRIM_SLOTS]; @@ -112,7 +112,7 @@ public BcdRegister(int maxDigits) throws IllegalArgumentException{ /** * Constructor for decimals with unsigned int32. */ - public BcdRegister(){ + public BcdRegister() { this(MAX_COL_UINT32); return; } @@ -124,7 +124,7 @@ public BcdRegister(){ * @param digits decimal digits * @return rounded value */ - private static int fittingContainer(int digits){ + private static int fittingContainer(int digits) { int result; result = digits; @@ -139,9 +139,9 @@ private static int fittingContainer(int digits){ /** * Clear all decimal digits to Zero. */ - public void clear(){ + public void clear() { int buflen = this.ibuf.length; - for(int idx = 0; idx < buflen; idx++){ + for (int idx = 0; idx < buflen; idx++) { this.ibuf[idx] = 0; } @@ -157,7 +157,7 @@ public void clear(){ * * @return digits holder width */ - public int getMaxDigits(){ + public int getMaxDigits() { return this.maxDigits; } @@ -168,7 +168,7 @@ public int getMaxDigits(){ * @return decimal value from 0 to 9 * @throws IndexOutOfBoundsException invalid position. */ - public int getDigit(int digitPos) throws IndexOutOfBoundsException{ + public int getDigit(int digitPos) throws IndexOutOfBoundsException { int iIdx; int iMod; @@ -206,18 +206,18 @@ public int getDigit(int digitPos) throws IndexOutOfBoundsException{ * @throws IndexOutOfBoundsException too small array or negative offset. */ public int toIntArray(int[] dst, int offset) - throws IndexOutOfBoundsException{ + throws IndexOutOfBoundsException { int digitsCt = getPrecision(); int addPos = digitsCt - 1; - bufloop: for(int iVal : this.ibuf){ - for(int nblIdx = 0; nblIdx < PRIM_SLOTS; nblIdx++){ + bufloop: for (int iVal : this.ibuf) { + for (int nblIdx = 0; nblIdx < PRIM_SLOTS; nblIdx++) { int shPos = nblIdx << 2; // = nblIdx * 4; dst[offset + addPos] = (iVal >>> shPos) & NIBBLE_MASK; - if(addPos <= 0) break bufloop; + if (addPos <= 0) break bufloop; addPos--; } @@ -234,10 +234,10 @@ public int toIntArray(int[] dst, int offset) * @param carryOver LSB is 1 if true. * @return true if MSB overflow */ - public boolean pushLsb(boolean carryOver){ + public boolean pushLsb(boolean carryOver) { int pushInt; - if(carryOver) pushInt = MSB_PRIMMASK; - else pushInt = 0; + if (carryOver) pushInt = MSB_PRIMMASK; + else pushInt = 0; boolean result = pushLsb(pushInt); @@ -252,16 +252,16 @@ public boolean pushLsb(boolean carryOver){ * @param carryOver LSB is 1 if non-zero. * @return true if MSB overflow */ - public boolean pushLsb(int carryOver){ + public boolean pushLsb(int carryOver) { int lastMsbTest = carryOver; int buflen = this.ibuf.length; - for(int idx = 0; idx < buflen; idx++){ + for (int idx = 0; idx < buflen; idx++) { int oldVal = this.ibuf[idx]; int fixVal = BcdUtils.toBiQuinary(oldVal); int newVal = fixVal << 1; - if(lastMsbTest != 0) newVal |= LSB_PRIMMASK; + if (lastMsbTest != 0) newVal |= LSB_PRIMMASK; this.ibuf[idx] = newVal; lastMsbTest = fixVal & MSB_PRIMMASK; @@ -287,13 +287,13 @@ public boolean pushLsb(int carryOver){ * * @return decimal precision. */ - public int getPrecision(){ - if(this.precision > 0){ + public int getPrecision() { + if (this.precision > 0) { return this.precision; } int result = calcPrecision(); - if(result == 0) result = 1; + if (result == 0) result = 1; this.precision = result; @@ -311,17 +311,17 @@ public int getPrecision(){ * * @return decimal precision. */ - private int calcPrecision(){ + private int calcPrecision() { int result = this.maxDigits; int idxMax = this.ibuf.length - 1; - for(int iIdx = idxMax; iIdx >= 0; iIdx--){ + for (int iIdx = idxMax; iIdx >= 0; iIdx--) { int iVal = this.ibuf[iIdx]; int clz = BcdUtils.clzNibble(iVal); result -= clz; - if(clz != PRIM_SLOTS){ + if (clz != PRIM_SLOTS) { break; } } @@ -336,12 +336,12 @@ private int calcPrecision(){ * @return {@inheritDoc} */ @Override - public String toString(){ + public String toString() { StringBuilder sb = new StringBuilder(); boolean dumped = false; int validCols = getPrecision(); - for(int colCt = validCols - 1; colCt >= 0; colCt--){ + for (int colCt = validCols - 1; colCt >= 0; colCt--) { int iIdx = colCt >>> PRIMIDX_SHIFT; // = colCt / 8; int nblIdx = colCt & NBLIDX_MASK; @@ -354,7 +354,7 @@ public String toString(){ iVal >>>= shiftWidth; int nibble = iVal & NIBBLE_MASK; - if(dumped){ + if (dumped) { sb.append(SP); } @@ -374,7 +374,7 @@ public String toString(){ * @param sb output * @param nibble BCD nibble value. (0 =< nibble < 10) */ - private void dumpNibble(StringBuilder sb, int nibble){ + private void dumpNibble(StringBuilder sb, int nibble) { int b3 = (nibble >> 3) & LSB_PRIMMASK; int b2 = (nibble >> 2) & LSB_PRIMMASK; int b1 = (nibble >> 1) & LSB_PRIMMASK; diff --git a/src/main/java/io/github/olyutorskii/doubdabc/BcdSequence.java b/src/main/java/io/github/olyutorskii/doubdabc/BcdSequence.java index a321e53..415964a 100644 --- a/src/main/java/io/github/olyutorskii/doubdabc/BcdSequence.java +++ b/src/main/java/io/github/olyutorskii/doubdabc/BcdSequence.java @@ -18,7 +18,7 @@ * *

There is some API for character-output classes. */ -public class BcdSequence implements CharSequence{ +public class BcdSequence implements CharSequence { private static final int ARABIC_UC_MASK = 0b0011_0000; @@ -34,7 +34,7 @@ public class BcdSequence implements CharSequence{ * @param decimal BCD register * @throws NullPointerException argument is null */ - public BcdSequence(BcdRegister decimal) throws NullPointerException{ + public BcdSequence(BcdRegister decimal) throws NullPointerException { super(); this.decimal = decimal; @@ -54,10 +54,10 @@ public BcdSequence(BcdRegister decimal) throws NullPointerException{ * @return digits length * @throws IOException If an I/O error occurs */ - public int flushDigitTo(Appendable app) throws IOException{ + public int flushDigitTo(Appendable app) throws IOException { int length = buildChar(); - for(int idx = 0; idx < length; idx++){ + for (int idx = 0; idx < length; idx++) { char decimalCh = this.charBuf[idx]; app.append(decimalCh); } @@ -71,12 +71,12 @@ public int flushDigitTo(Appendable app) throws IOException{ * @param cBuf output * @return digits length * @throws BufferOverflowException - * If buffer's current position is not smaller than its limit + * If buffer's current position is not smaller than its limit * @throws ReadOnlyBufferException - * If buffer is read-only + * If buffer is read-only */ public int flushDigitTo(CharBuffer cBuf) - throws BufferOverflowException, ReadOnlyBufferException{ + throws BufferOverflowException, ReadOnlyBufferException { int length = buildChar(); cBuf.put(this.charBuf, 0, length); return length; @@ -89,7 +89,7 @@ public int flushDigitTo(CharBuffer cBuf) * @return digits length * @throws IOException If an I/O error occurs */ - public int flushDigitTo(Writer writer) throws IOException{ + public int flushDigitTo(Writer writer) throws IOException { int length = buildChar(); writer.write(this.charBuf, 0, length); return length; @@ -101,7 +101,7 @@ public int flushDigitTo(Writer writer) throws IOException{ * @param buf output * @return digits length */ - public int flushDigitTo(StringBuffer buf){ + public int flushDigitTo(StringBuffer buf) { int length = buildChar(); buf.append(this.charBuf, 0, length); return length; @@ -113,7 +113,7 @@ public int flushDigitTo(StringBuffer buf){ * @param buf output * @return digits length */ - public int flushDigitTo(StringBuilder buf){ + public int flushDigitTo(StringBuilder buf) { int length = buildChar(); buf.append(this.charBuf, 0, length); return length; @@ -127,7 +127,7 @@ public int flushDigitTo(StringBuilder buf){ * @return digits columns */ @Override - public int length(){ + public int length() { int result = this.decimal.getPrecision(); return result; } @@ -138,20 +138,21 @@ public int length(){ * @param index digit position starting 0 * @return digit character ('0' to '9') * @throws IndexOutOfBoundsException - * Argument is negative, or, not less than length() + * Argument is negative, or, not less than length() */ @Override - public char charAt(int index) throws IndexOutOfBoundsException{ + public char charAt(int index) throws IndexOutOfBoundsException { int precision = this.decimal.getPrecision(); - if(index < 0 || precision <= index) + if (index < 0 || precision <= index) { throw new IndexOutOfBoundsException(); + } int digitPos = precision - index - 1; int digit = this.decimal.getDigit(digitPos); // map [0 - 9](int) to ['0' - '9'](char) - char result = (char)( digit | ARABIC_UC_MASK ); + char result = (char) ( digit | ARABIC_UC_MASK ); return result; } @@ -169,11 +170,11 @@ public char charAt(int index) throws IndexOutOfBoundsException{ */ @Override public CharSequence subSequence(int start, int end) - throws IndexOutOfBoundsException{ - if(start < 0 || end < start) throw new IndexOutOfBoundsException(); + throws IndexOutOfBoundsException { + if (start < 0 || end < start) throw new IndexOutOfBoundsException(); int precision = this.decimal.getPrecision(); - if(end > precision) throw new IndexOutOfBoundsException(); + if (end > precision) throw new IndexOutOfBoundsException(); copyChar(start, end); String result = new String(this.charBuf, start, end - start); @@ -187,7 +188,7 @@ public CharSequence subSequence(int start, int end) * @return fixed string */ @Override - public String toString(){ + public String toString() { int precision = this.decimal.getPrecision(); buildChar(); String result = new String(this.charBuf, 0, precision); @@ -198,7 +199,7 @@ public String toString(){ * Build char array data. * @return digits length */ - private int buildChar(){ + private int buildChar() { int precision = this.decimal.getPrecision(); int result = copyChar(0, precision); return result; @@ -210,15 +211,15 @@ private int buildChar(){ * @param end end * @return digits length */ - private int copyChar(int start, int end){ + private int copyChar(int start, int end) { int length = end - start; this.decimal.toIntArray(this.intBuf, 0); - for(int idx = start; idx < end; idx++){ + for (int idx = start; idx < end; idx++) { int digit = this.intBuf[idx]; // map [0 - 9](int) to ['0' - '9'](char) - char decimalCh = (char)( digit | ARABIC_UC_MASK ); + char decimalCh = (char) ( digit | ARABIC_UC_MASK ); this.charBuf[idx] = decimalCh; } diff --git a/src/main/java/io/github/olyutorskii/doubdabc/BcdUtils.java b/src/main/java/io/github/olyutorskii/doubdabc/BcdUtils.java index 7a62cf8..d391b50 100644 --- a/src/main/java/io/github/olyutorskii/doubdabc/BcdUtils.java +++ b/src/main/java/io/github/olyutorskii/doubdabc/BcdUtils.java @@ -36,22 +36,20 @@ public final class BcdUtils { private static final int INT_SLOTS = Integer.SIZE / BCD_BITSIZE; private static final int LONG_SLOTS = Long.SIZE / BCD_BITSIZE; - private static final int[] BQ_TBL; + private static final int[] BQ_TBL = new int[256]; - static{ + static { // build lookup table for Packed-BCD to Bi-quinary conversion - BQ_TBL = new int[256]; - int[] bqline = new int[]{ - 0x00, 0x01, 0x02, 0x03, 0x04, - 0x08, 0x09, 0x0a, 0x0b, 0x0c, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 + 0b0_000, 0b0_001, 0b0_010, 0b0_011, 0b0_100, + 0b1_000, 0b1_001, 0b1_010, 0b1_011, 0b1_100, + 0, 0, 0, 0, 0, 0, }; int idx = 0; - for(int highDec : bqline){ + for (int highDec : bqline) { int highSft = highDec << BCD_BITSIZE; - for(int lowDec : bqline){ + for (int lowDec : bqline) { int bqNblNbl = highSft | lowDec; BQ_TBL[idx++] = bqNblNbl; } @@ -64,7 +62,7 @@ public final class BcdUtils { /** * Hiden constructor. */ - private BcdUtils(){ + private BcdUtils() { assert false; } @@ -83,7 +81,7 @@ private BcdUtils(){ * @param iVal int value * @return modified value */ - public static int toBiQuinary(int iVal){ + public static int toBiQuinary(int iVal) { int idx3 = iVal >>> 24; int idx2 = iVal >>> 16 & BYTE_MASK; int idx1 = iVal >>> 8 & BYTE_MASK; @@ -170,31 +168,31 @@ public static long toBiQuinary(long lVal) { * @param iVal int value * @return Zero nibbles */ - public static int clzNibble(int iVal){ - if(iVal == 0){ + public static int clzNibble(int iVal) { + if (iVal == 0) { return INT_SLOTS; } int b2; - if((iVal & 0xff_ff_00_00) == 0){ + if ((iVal & 0xff_ff_00_00) == 0) { b2 = 0b0100; iVal <<= 16; - }else{ + } else { b2 = 0b0000; } int b1; - if((iVal & 0xff_00_00_00) == 0){ + if ((iVal & 0xff_00_00_00) == 0) { b1 = 0b0010; iVal <<= 8; - }else{ + } else { b1 = 0b0000; } int b0; - if((iVal & 0xf0_00_00_00) == 0){ + if ((iVal & 0xf0_00_00_00) == 0) { b0 = 0b0001; - }else{ + } else { b0 = 0b0000; } @@ -217,39 +215,39 @@ public static int clzNibble(int iVal){ * @param lVal long value * @return Zero nibbles */ - public static int clzNibble(long lVal){ - if(lVal == 0){ + public static int clzNibble(long lVal) { + if (lVal == 0) { return LONG_SLOTS; } int b3; - if((lVal & 0xff_ff_ff_ff_00_00_00_00L) == 0){ + if ((lVal & 0xff_ff_ff_ff_00_00_00_00L) == 0) { b3 = 0b1000; lVal <<= 32; - }else{ + } else { b3 = 0b0000; } int b2; - if((lVal & 0xff_ff_00_00_00_00_00_00L) == 0){ + if ((lVal & 0xff_ff_00_00_00_00_00_00L) == 0) { b2 = 0b0100; lVal <<= 16; - }else{ + } else { b2 = 0b0000; } int b1; - if((lVal & 0xff_00_00_00_00_00_00_00L) == 0){ + if ((lVal & 0xff_00_00_00_00_00_00_00L) == 0) { b1 = 0b0010; lVal <<= 8; - }else{ + } else { b1 = 0b0000; } int b0; - if((lVal & 0xf0_00_00_00_00_00_00_00L) == 0){ + if ((lVal & 0xf0_00_00_00_00_00_00_00L) == 0) { b0 = 0b0001; - }else{ + } else { b0 = 0b0000; } diff --git a/src/main/java/io/github/olyutorskii/doubdabc/BitFeeder.java b/src/main/java/io/github/olyutorskii/doubdabc/BitFeeder.java index c042c2f..e5110f4 100644 --- a/src/main/java/io/github/olyutorskii/doubdabc/BitFeeder.java +++ b/src/main/java/io/github/olyutorskii/doubdabc/BitFeeder.java @@ -22,7 +22,7 @@ public final class BitFeeder { /** * Hidden constructor. */ - private BitFeeder(){ + private BitFeeder() { assert false; } @@ -37,7 +37,7 @@ private BitFeeder(){ * @param iVal 32bit integer * @return true if MSB overflow */ - public static boolean feedUInt32(BcdRegister bs, int iVal){ + public static boolean feedUInt32(BcdRegister bs, int iVal) { bs.clear(); boolean skipping = true; @@ -67,25 +67,25 @@ public static boolean feedUInt32(BcdRegister bs, int iVal){ * @param lVal 64bit integer * @return true if MSB overflow */ - public static boolean feedUInt64(BcdRegister bs, long lVal){ + public static boolean feedUInt64(BcdRegister bs, long lVal) { bs.clear(); boolean skipping = true; boolean result = false; - for(int ct = 0; ct < Long.SIZE; ct++){ + for (int ct = 0; ct < Long.SIZE; ct++) { long scanMask = MSB_LONGMASK >>> ct; long bitScanned = lVal & scanMask; - if(skipping){ - if(bitScanned == 0b0L) continue; + if (skipping) { + if (bitScanned == 0b0L) continue; skipping = false; } int newLsbInt; - if(bitScanned == 0L){ + if (bitScanned == 0L) { newLsbInt = 0; - }else{ + } else { newLsbInt = 1; } @@ -105,17 +105,17 @@ public static boolean feedUInt64(BcdRegister bs, long lVal){ * @param bigInt big integer * @return true if MSB overflow */ - public static boolean feedBigInteger(BcdRegister bs, BigInteger bigInt){ + public static boolean feedBigInteger(BcdRegister bs, BigInteger bigInt) { bs.clear(); boolean result = false; int sign = bigInt.signum(); - if(sign < 0) result |= bs.pushLsb(true); + if (sign < 0) result |= bs.pushLsb(true); int msbPos = bigInt.bitLength() - 1; - for(int bitIndex = msbPos; bitIndex >= 0; bitIndex--){ + for (int bitIndex = msbPos; bitIndex >= 0; bitIndex--) { boolean newLsb = bigInt.testBit(bitIndex); result |= bs.pushLsb(newLsb); } @@ -131,14 +131,14 @@ public static boolean feedBigInteger(BcdRegister bs, BigInteger bigInt){ * @param bitSet bit set * @return true if MSB overflow */ - public static boolean feedBitSet(BcdRegister bs, BitSet bitSet){ + public static boolean feedBitSet(BcdRegister bs, BitSet bitSet) { bs.clear(); int msbPos = bitSet.length() - 1; boolean result = false; - for(int bitIndex = msbPos; bitIndex >= 0; bitIndex--){ + for (int bitIndex = msbPos; bitIndex >= 0; bitIndex--) { boolean newLsb = bitSet.get(bitIndex); result |= bs.pushLsb(newLsb); }