Move some constants in BinaryDictInputOutput to FormatSpec.

Change-Id: I6b12faf35b65238b9a64c82d4d1a6050f980e72e
main
Yuichiro Hanada 2013-08-14 18:39:14 +09:00
parent e18fdf804a
commit 665592774c
3 changed files with 20 additions and 22 deletions

View File

@ -39,8 +39,6 @@ import java.util.Stack;
public final class BinaryDictIOUtils {
private static final boolean DBG = false;
private static final int MSB24 = 0x800000;
private static final int SINT24_MAX = 0x7FFFFF;
private static final int MAX_JUMPS = 10000;
private BinaryDictIOUtils() {
@ -921,8 +919,8 @@ public final class BinaryDictIOUtils {
// reached the end of the array.
final int linkAddressPosition = buffer.position();
int nextLink = buffer.readUnsignedInt24();
if ((nextLink & MSB24) != 0) {
nextLink = -(nextLink & SINT24_MAX);
if ((nextLink & FormatSpec.MSB24) != 0) {
nextLink = -(nextLink & FormatSpec.SINT24_MAX);
}
if (nextLink == FormatSpec.NO_FORWARD_LINK_ADDRESS) {
/*

View File

@ -449,10 +449,6 @@ public final class BinaryDictInputOutput {
}
}
private static final int UINT8_MAX = 0xFF;
private static final int UINT16_MAX = 0xFFFF;
private static final int UINT24_MAX = 0xFFFFFF;
/**
* Compute the size, in bytes, that an address will occupy.
*
@ -464,22 +460,18 @@ public final class BinaryDictInputOutput {
* @return the byte size.
*/
static int getByteSize(final int address) {
assert(address <= UINT24_MAX);
assert(address <= FormatSpec.UINT24_MAX);
if (!hasChildrenAddress(address)) {
return 0;
} else if (Math.abs(address) <= UINT8_MAX) {
} else if (Math.abs(address) <= FormatSpec.UINT8_MAX) {
return 1;
} else if (Math.abs(address) <= UINT16_MAX) {
} else if (Math.abs(address) <= FormatSpec.UINT16_MAX) {
return 2;
} else {
return 3;
}
}
private static final int SINT24_MAX = 0x7FFFFF;
private static final int MSB8 = 0x80;
private static final int MSB24 = 0x800000;
// End utility methods.
// This method is responsible for finding a nice ordering of the nodes that favors run-time
@ -814,7 +806,8 @@ public final class BinaryDictInputOutput {
buffer[index] = buffer[index + 1] = buffer[index + 2] = 0;
} else {
final int absAddress = Math.abs(address);
buffer[index++] = (byte)((address < 0 ? MSB8 : 0) | (0xFF & (absAddress >> 16)));
buffer[index++] =
(byte)((address < 0 ? FormatSpec.MSB8 : 0) | (0xFF & (absAddress >> 16)));
buffer[index++] = (byte)(0xFF & (absAddress >> 8));
buffer[index++] = (byte)(0xFF & absAddress);
}
@ -978,8 +971,8 @@ public final class BinaryDictInputOutput {
buffer[index] = buffer[index + 1] = buffer[index + 2] = 0;
} else {
final int absAddress = Math.abs(address);
assert(absAddress <= SINT24_MAX);
buffer[index] = (byte)((address < 0 ? MSB8 : 0)
assert(absAddress <= FormatSpec.SINT24_MAX);
buffer[index] = (byte)((address < 0 ? FormatSpec.MSB8 : 0)
| ((absAddress >> 16) & 0xFF));
buffer[index + 1] = (byte)((absAddress >> 8) & 0xFF);
buffer[index + 2] = (byte)(absAddress & 0xFF);
@ -1300,8 +1293,8 @@ public final class BinaryDictInputOutput {
if (options.mSupportsDynamicUpdate) {
final int address = buffer.readUnsignedInt24();
if (address == 0) return FormatSpec.NO_CHILDREN_ADDRESS;
if ((address & MSB24) != 0) {
return -(address & SINT24_MAX);
if ((address & FormatSpec.MSB24) != 0) {
return -(address & FormatSpec.SINT24_MAX);
} else {
return address;
}
@ -1324,8 +1317,8 @@ public final class BinaryDictInputOutput {
final FormatOptions formatOptions) {
if (supportsDynamicUpdate(formatOptions)) {
final int parentAddress = buffer.readUnsignedInt24();
final int sign = ((parentAddress & MSB24) != 0) ? -1 : 1;
return sign * (parentAddress & SINT24_MAX);
final int sign = ((parentAddress & FormatSpec.MSB24) != 0) ? -1 : 1;
return sign * (parentAddress & FormatSpec.SINT24_MAX);
} else {
return FormatSpec.NO_PARENT_ADDRESS;
}

View File

@ -263,6 +263,13 @@ public final class FormatSpec {
static final int NOT_VALID_WORD = -99;
static final int SIGNED_CHILDREN_ADDRESS_SIZE = 3;
static final int UINT8_MAX = 0xFF;
static final int UINT16_MAX = 0xFFFF;
static final int UINT24_MAX = 0xFFFFFF;
static final int SINT24_MAX = 0x7FFFFF;
static final int MSB8 = 0x80;
static final int MSB24 = 0x800000;
/**
* Options about file format.
*/