Skip to content

Commit

Permalink
Fixes whitespace with <space> instead of tab
Browse files Browse the repository at this point in the history
  • Loading branch information
Michel Pigassou committed Sep 28, 2016
1 parent 4d12616 commit 87a3bb9
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 49 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -150,9 +150,9 @@ protected Row parseRow(XInputStream is, TableMapEvent tme, BitColumn usedColumns
break;
case MySQLConstants.TYPE_NEWDECIMAL:
final int precision = meta & 0xFF;
final int scale = meta >> 8;
final int decimalLength = MySQLUtils.getDecimalBinarySize(precision, scale);
columns.add(DecimalColumn.valueOf(MySQLUtils.toDecimal(precision, scale, is.readBytes(decimalLength)), precision, scale));
final int scale = meta >> 8;
final int decimalLength = MySQLUtils.getDecimalBinarySize(precision, scale);
columns.add(DecimalColumn.valueOf(MySQLUtils.toDecimal(precision, scale, is.readBytes(decimalLength)), precision, scale));
break;
case MySQLConstants.TYPE_STRING:
final int stringLength = length < 256 ? is.readInt(1) : is.readInt(2);
Expand Down
92 changes: 46 additions & 46 deletions src/main/java/com/google/code/or/common/util/MySQLUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,9 @@ public static java.sql.Time toTime(int value) {
final int m = (int)(value % 100);
final int h = (int)(value / 100);
final Calendar c = Calendar.getInstance();
c.set(1970, 0, 1, h, m, s);
c.set(Calendar.MILLISECOND, 0);
return new java.sql.Time(c.getTimeInMillis());
c.set(1970, 0, 1, h, m, s);
c.set(Calendar.MILLISECOND, 0);
return new java.sql.Time(c.getTimeInMillis());
}

public static java.sql.Time toTime2(int value, int fraction, int width) {
Expand Down Expand Up @@ -121,9 +121,9 @@ public static java.util.Date toDatetime(long value) {
final int month = (int)(value % 100);
final int year = (int)(value / 100);
final Calendar c = Calendar.getInstance();
c.set(year, month - 1, day, hour, minute, second);
c.set(Calendar.MILLISECOND, 0);
return c.getTime();
c.set(year, month - 1, day, hour, minute, second);
c.set(Calendar.MILLISECOND, 0);
return c.getTime();
}

public static java.util.Date toDatetime2(long value, int fraction, int width) {
Expand Down Expand Up @@ -170,51 +170,51 @@ public static java.sql.Timestamp datetime2ToTimestamp(long value, int fraction,

public static BigDecimal toDecimal(int precision, int scale, byte[] value) {
//
final boolean positive = (value[0] & 0x80) == 0x80;
value[0] ^= 0x80;
if (!positive) {
for (int i = 0; i < value.length; i++) {
value[i] ^= 0xFF;
}
}

//
final int x = precision - scale;
final int ipDigits = x / DIGITS_PER_4BYTES;
final int ipDigitsX = x - ipDigits * DIGITS_PER_4BYTES;
final int ipSize = (ipDigits << 2) + DECIMAL_BINARY_SIZE[ipDigitsX];
int offset = DECIMAL_BINARY_SIZE[ipDigitsX];
BigDecimal ip = offset > 0 ? BigDecimal.valueOf(CodecUtils.toInt(value, 0, offset)) : BigDecimal.ZERO;
for(; offset < ipSize; offset += 4) {
final int i = CodecUtils.toInt(value, offset, 4);
ip = ip.movePointRight(DIGITS_PER_4BYTES).add(BigDecimal.valueOf(i));
}

//
int shift = 0;
BigDecimal fp = BigDecimal.ZERO;
for (; shift + DIGITS_PER_4BYTES <= scale; shift += DIGITS_PER_4BYTES, offset += 4) {
final int i = CodecUtils.toInt(value, offset, 4);
fp = fp.add(BigDecimal.valueOf(i).movePointLeft(shift + DIGITS_PER_4BYTES));
}
if(shift < scale) {
final int i = CodecUtils.toInt(value, offset, DECIMAL_BINARY_SIZE[scale - shift]);
fp = fp.add(BigDecimal.valueOf(i).movePointLeft(scale));
}

//
return positive ? POSITIVE_ONE.multiply(ip.add(fp)) : NEGATIVE_ONE.multiply(ip.add(fp));
final boolean positive = (value[0] & 0x80) == 0x80;
value[0] ^= 0x80;
if (!positive) {
for (int i = 0; i < value.length; i++) {
value[i] ^= 0xFF;
}
}

//
final int x = precision - scale;
final int ipDigits = x / DIGITS_PER_4BYTES;
final int ipDigitsX = x - ipDigits * DIGITS_PER_4BYTES;
final int ipSize = (ipDigits << 2) + DECIMAL_BINARY_SIZE[ipDigitsX];
int offset = DECIMAL_BINARY_SIZE[ipDigitsX];
BigDecimal ip = offset > 0 ? BigDecimal.valueOf(CodecUtils.toInt(value, 0, offset)) : BigDecimal.ZERO;
for(; offset < ipSize; offset += 4) {
final int i = CodecUtils.toInt(value, offset, 4);
ip = ip.movePointRight(DIGITS_PER_4BYTES).add(BigDecimal.valueOf(i));
}

//
int shift = 0;
BigDecimal fp = BigDecimal.ZERO;
for (; shift + DIGITS_PER_4BYTES <= scale; shift += DIGITS_PER_4BYTES, offset += 4) {
final int i = CodecUtils.toInt(value, offset, 4);
fp = fp.add(BigDecimal.valueOf(i).movePointLeft(shift + DIGITS_PER_4BYTES));
}
if(shift < scale) {
final int i = CodecUtils.toInt(value, offset, DECIMAL_BINARY_SIZE[scale - shift]);
fp = fp.add(BigDecimal.valueOf(i).movePointLeft(scale));
}

//
return positive ? POSITIVE_ONE.multiply(ip.add(fp)) : NEGATIVE_ONE.multiply(ip.add(fp));
}

/**
*
*/
public static int getDecimalBinarySize(int precision, int scale) {
final int x = precision - scale;
final int ipDigits = x / DIGITS_PER_4BYTES;
final int fpDigits = scale / DIGITS_PER_4BYTES;
final int ipDigitsX = x - ipDigits * DIGITS_PER_4BYTES;
final int fpDigitsX = scale - fpDigits * DIGITS_PER_4BYTES;
return (ipDigits << 2) + DECIMAL_BINARY_SIZE[ipDigitsX] + (fpDigits << 2) + DECIMAL_BINARY_SIZE[fpDigitsX];
}
final int ipDigits = x / DIGITS_PER_4BYTES;
final int fpDigits = scale / DIGITS_PER_4BYTES;
final int ipDigitsX = x - ipDigits * DIGITS_PER_4BYTES;
final int fpDigitsX = scale - fpDigits * DIGITS_PER_4BYTES;
return (ipDigits << 2) + DECIMAL_BINARY_SIZE[ipDigitsX] + (fpDigits << 2) + DECIMAL_BINARY_SIZE[fpDigitsX];
}
}

0 comments on commit 87a3bb9

Please sign in to comment.