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);
}