formatting

This commit is contained in:
Hannes Janetzek
2013-02-04 20:14:58 +01:00
parent 303e0cb4ce
commit f2b7a9fdf8
72 changed files with 403 additions and 240 deletions

View File

@@ -22,7 +22,7 @@ final class Deserializer {
* Converts five bytes of a byte array to an unsigned long.
* <p>
* The byte order is big-endian.
*
*
* @param buffer
* the byte array.
* @param offset
@@ -30,7 +30,8 @@ final class Deserializer {
* @return the long value.
*/
static long getFiveBytesLong(byte[] buffer, int offset) {
return (buffer[offset] & 0xffL) << 32 | (buffer[offset + 1] & 0xffL) << 24 | (buffer[offset + 2] & 0xffL) << 16
return (buffer[offset] & 0xffL) << 32 | (buffer[offset + 1] & 0xffL) << 24
| (buffer[offset + 2] & 0xffL) << 16
| (buffer[offset + 3] & 0xffL) << 8 | (buffer[offset + 4] & 0xffL);
}
@@ -38,7 +39,7 @@ final class Deserializer {
* Converts four bytes of a byte array to a signed int.
* <p>
* The byte order is big-endian.
*
*
* @param buffer
* the byte array.
* @param offset
@@ -46,7 +47,8 @@ final class Deserializer {
* @return the int value.
*/
static int getInt(byte[] buffer, int offset) {
return buffer[offset] << 24 | (buffer[offset + 1] & 0xff) << 16 | (buffer[offset + 2] & 0xff) << 8
return buffer[offset] << 24 | (buffer[offset + 1] & 0xff) << 16
| (buffer[offset + 2] & 0xff) << 8
| (buffer[offset + 3] & 0xff);
}
@@ -54,7 +56,7 @@ final class Deserializer {
* Converts eight bytes of a byte array to a signed long.
* <p>
* The byte order is big-endian.
*
*
* @param buffer
* the byte array.
* @param offset
@@ -62,16 +64,18 @@ final class Deserializer {
* @return the long value.
*/
static long getLong(byte[] buffer, int offset) {
return (buffer[offset] & 0xffL) << 56 | (buffer[offset + 1] & 0xffL) << 48 | (buffer[offset + 2] & 0xffL) << 40
return (buffer[offset] & 0xffL) << 56 | (buffer[offset + 1] & 0xffL) << 48
| (buffer[offset + 2] & 0xffL) << 40
| (buffer[offset + 3] & 0xffL) << 32 | (buffer[offset + 4] & 0xffL) << 24
| (buffer[offset + 5] & 0xffL) << 16 | (buffer[offset + 6] & 0xffL) << 8 | (buffer[offset + 7] & 0xffL);
| (buffer[offset + 5] & 0xffL) << 16 | (buffer[offset + 6] & 0xffL) << 8
| (buffer[offset + 7] & 0xffL);
}
/**
* Converts two bytes of a byte array to a signed int.
* <p>
* The byte order is big-endian.
*
*
* @param buffer
* the byte array.
* @param offset

View File

@@ -37,7 +37,8 @@ class IndexCache {
/**
* Maximum size in bytes of one index block.
*/
private static final int SIZE_OF_INDEX_BLOCK = INDEX_ENTRIES_PER_BLOCK * SubFileParameter.BYTES_PER_INDEX_ENTRY;
private static final int SIZE_OF_INDEX_BLOCK = INDEX_ENTRIES_PER_BLOCK
* SubFileParameter.BYTES_PER_INDEX_ENTRY;
private final Map<IndexCacheEntryKey, byte[]> map;
private final RandomAccessFile randomAccessFile;
@@ -63,11 +64,13 @@ class IndexCache {
}
/**
* Returns the index entry of a block in the given map file. If the required index entry is not cached, it will be
* Returns the index entry of a block in the given map file. If the required
* index entry is not cached, it will be
* read from the map file index and put in the cache.
*
*
* @param subFileParameter
* the parameters of the map file for which the index entry is needed.
* the parameters of the map file for which the index entry is
* needed.
* @param blockNumber
* the number of the block in the map file.
* @return the index entry or -1 if the block number is invalid.
@@ -83,13 +86,15 @@ class IndexCache {
long indexBlockNumber = blockNumber / INDEX_ENTRIES_PER_BLOCK;
// create the cache entry key for this request
IndexCacheEntryKey indexCacheEntryKey = new IndexCacheEntryKey(subFileParameter, indexBlockNumber);
IndexCacheEntryKey indexCacheEntryKey = new IndexCacheEntryKey(subFileParameter,
indexBlockNumber);
// check for cached index block
byte[] indexBlock = this.map.get(indexCacheEntryKey);
if (indexBlock == null) {
// cache miss, seek to the correct index block in the file and read it
long indexBlockPosition = subFileParameter.indexStartAddress + indexBlockNumber * SIZE_OF_INDEX_BLOCK;
long indexBlockPosition = subFileParameter.indexStartAddress + indexBlockNumber
* SIZE_OF_INDEX_BLOCK;
int remainingIndexSize = (int) (subFileParameter.indexEndAddress - indexBlockPosition);
int indexBlockSize = Math.min(SIZE_OF_INDEX_BLOCK, remainingIndexSize);

View File

@@ -26,7 +26,7 @@ class IndexCacheEntryKey {
/**
* Creates an immutable key to be stored in a map.
*
*
* @param subFileParameter
* the parameters of the map file.
* @param indexBlockNumber
@@ -48,7 +48,8 @@ class IndexCacheEntryKey {
IndexCacheEntryKey other = (IndexCacheEntryKey) obj;
if (this.subFileParameter == null && other.subFileParameter != null) {
return false;
} else if (this.subFileParameter != null && !this.subFileParameter.equals(other.subFileParameter)) {
} else if (this.subFileParameter != null
&& !this.subFileParameter.equals(other.subFileParameter)) {
return false;
} else if (this.indexBlockNumber != other.indexBlockNumber) {
return false;
@@ -66,7 +67,8 @@ class IndexCacheEntryKey {
*/
private int calculateHashCode() {
int result = 7;
result = 31 * result + ((this.subFileParameter == null) ? 0 : this.subFileParameter.hashCode());
result = 31 * result
+ ((this.subFileParameter == null) ? 0 : this.subFileParameter.hashCode());
result = 31 * result + (int) (this.indexBlockNumber ^ (this.indexBlockNumber >>> 32));
return result;
}

View File

@@ -38,7 +38,7 @@ import android.os.Environment;
* A class for reading binary map files.
* <p>
* This class is not thread-safe. Each thread should use its own instance.
*
*
* @see <a
* href="http://code.google.com/p/mapsforge/wiki/SpecificationBinaryMapFile">Specification</a>
*/
@@ -387,7 +387,7 @@ public class MapDatabase implements IMapDatabase {
/**
* Processes a single block and executes the callback functions on all map
* elements.
*
*
* @param queryParameters
* the parameters of the current query.
* @param subFileParameter
@@ -567,7 +567,7 @@ public class MapDatabase implements IMapDatabase {
/**
* Processes the block signature, if present.
*
*
* @return true if the block signature could be processed successfully,
* false otherwise.
*/
@@ -585,7 +585,7 @@ public class MapDatabase implements IMapDatabase {
/**
* Processes the given number of POIs.
*
*
* @param mapDatabaseCallback
* the callback which handles the extracted POIs.
* @param numberOfPois
@@ -801,7 +801,7 @@ public class MapDatabase implements IMapDatabase {
/**
* Processes the given number of ways.
*
*
* @param queryParameters
* the parameters of the current query.
* @param mapDatabaseCallback

View File

@@ -43,7 +43,7 @@ public class ReadBuffer {
/**
* Returns one signed byte from the read buffer.
*
*
* @return the byte value.
*/
public byte readByte() {
@@ -51,9 +51,11 @@ public class ReadBuffer {
}
/**
* Reads the given amount of bytes from the file into the read buffer and resets the internal buffer position. If
* the capacity of the read buffer is too small, a larger one is created automatically.
*
* Reads the given amount of bytes from the file into the read buffer and
* resets the internal buffer position. If
* the capacity of the read buffer is too small, a larger one is created
* automatically.
*
* @param length
* the amount of bytes to read from the file.
* @return true if the whole data was read successfully, false otherwise.
@@ -82,7 +84,7 @@ public class ReadBuffer {
* Converts four bytes from the read buffer to a signed int.
* <p>
* The byte order is big-endian.
*
*
* @return the int value.
*/
public int readInt() {
@@ -100,7 +102,7 @@ public class ReadBuffer {
* Converts eight bytes from the read buffer to a signed long.
* <p>
* The byte order is big-endian.
*
*
* @return the long value.
*/
public long readLong() {
@@ -123,7 +125,7 @@ public class ReadBuffer {
* Converts two bytes from the read buffer to a signed int.
* <p>
* The byte order is big-endian.
*
*
* @return the int value.
*/
public int readShort() {
@@ -134,9 +136,10 @@ public class ReadBuffer {
/**
* Converts a variable amount of bytes from the read buffer to a signed int.
* <p>
* The first bit is for continuation info, the other six (last byte) or seven (all other bytes) bits are for data.
* The second bit in the last byte indicates the sign of the number.
*
* The first bit is for continuation info, the other six (last byte) or
* seven (all other bytes) bits are for data. The second bit in the last
* byte indicates the sign of the number.
*
* @return the value.
*/
public int readSignedInt() {
@@ -192,11 +195,13 @@ public class ReadBuffer {
}
/**
* Converts a variable amount of bytes from the read buffer to a signed int array.
* Converts a variable amount of bytes from the read buffer to a signed int
* array.
* <p>
* The first bit is for continuation info, the other six (last byte) or seven (all other bytes) bits are for data.
* The second bit in the last byte indicates the sign of the number.
*
* The first bit is for continuation info, the other six (last byte) or
* seven (all other bytes) bits are for data. The second bit in the last
* byte indicates the sign of the number.
*
* @param values
* result values
* @param length
@@ -322,10 +327,12 @@ public class ReadBuffer {
// }
/**
* Converts a variable amount of bytes from the read buffer to an unsigned int.
* Converts a variable amount of bytes from the read buffer to an unsigned
* int.
* <p>
* The first bit is for continuation info, the other seven bits are for data.
*
* The first bit is for continuation info, the other seven bits are for
* data.
*
* @return the int value.
*/
public int readUnsignedInt() {
@@ -368,7 +375,7 @@ public class ReadBuffer {
/**
* Decodes a variable amount of bytes from the read buffer to a string.
*
*
* @return the UTF-8 decoded string (may be null).
*/
public String readUTF8EncodedString() {
@@ -387,7 +394,7 @@ public class ReadBuffer {
/**
* Decodes the given amount of bytes from the read buffer to a string.
*
*
* @param stringLength
* the length of the string in bytes.
* @return the UTF-8 decoded string (may be null).
@@ -396,7 +403,8 @@ public class ReadBuffer {
if (stringLength > 0 && mBufferPosition + stringLength <= mBufferData.length) {
mBufferPosition += stringLength;
try {
return new String(mBufferData, mBufferPosition - stringLength, stringLength, CHARSET_UTF8);
return new String(mBufferData, mBufferPosition - stringLength, stringLength,
CHARSET_UTF8);
} catch (UnsupportedEncodingException e) {
throw new IllegalStateException(e);
}
@@ -407,7 +415,7 @@ public class ReadBuffer {
/**
* Decodes a variable amount of bytes from the read buffer to a string.
*
*
* @param position
* buffer offset position of string
* @return the UTF-8 decoded string (may be null).
@@ -436,7 +444,7 @@ public class ReadBuffer {
/**
* Sets the buffer position to the given offset.
*
*
* @param bufferPosition
* the buffer position.
*/
@@ -446,7 +454,7 @@ public class ReadBuffer {
/**
* Skips the given number of bytes in the read buffer.
*
*
* @param bytes
* the number of bytes to skip.
*/

View File

@@ -80,7 +80,7 @@ public class MapFileHeader {
/**
* Reads and validates the header block from the map file.
*
*
* @param readBuffer
* the ReadBuffer for the file data.
* @param fileSize

View File

@@ -19,7 +19,7 @@ import org.oscim.database.mapfile.MapDatabase;
/**
* Contains the immutable metadata of a map file.
*
*
* @see MapDatabase#getMapInfo()
*/
public class MapFileInfo extends org.oscim.database.MapInfo {

View File

@@ -59,7 +59,8 @@ final class OptionalFields {
*/
private static final int START_ZOOM_LEVEL_MAX = 22;
static OpenResult readOptionalFields(ReadBuffer readBuffer, MapFileInfoBuilder mapFileInfoBuilder) {
static OpenResult readOptionalFields(ReadBuffer readBuffer,
MapFileInfoBuilder mapFileInfoBuilder) {
OptionalFields optionalFields = new OptionalFields(readBuffer.readByte());
mapFileInfoBuilder.optionalFields = optionalFields;
@@ -106,13 +107,15 @@ final class OptionalFields {
if (this.hasStartPosition) {
// get and check the start position latitude (4 byte)
int mapStartLatitude = readBuffer.readInt();
if (mapStartLatitude < RequiredFields.LATITUDE_MIN || mapStartLatitude > RequiredFields.LATITUDE_MAX) {
if (mapStartLatitude < RequiredFields.LATITUDE_MIN
|| mapStartLatitude > RequiredFields.LATITUDE_MAX) {
return new OpenResult("invalid map start latitude: " + mapStartLatitude);
}
// get and check the start position longitude (4 byte)
int mapStartLongitude = readBuffer.readInt();
if (mapStartLongitude < RequiredFields.LONGITUDE_MIN || mapStartLongitude > RequiredFields.LONGITUDE_MAX) {
if (mapStartLongitude < RequiredFields.LONGITUDE_MIN
|| mapStartLongitude > RequiredFields.LONGITUDE_MAX) {
return new OpenResult("invalid map start longitude: " + mapStartLongitude);
}

View File

@@ -104,11 +104,13 @@ final class RequiredFields {
return new OpenResult("invalid longitude range: " + minLongitude + SPACE + maxLongitude);
}
mapFileInfoBuilder.boundingBox = new BoundingBox(minLatitude, minLongitude, maxLatitude, maxLongitude);
mapFileInfoBuilder.boundingBox = new BoundingBox(minLatitude, minLongitude, maxLatitude,
maxLongitude);
return OpenResult.SUCCESS;
}
static OpenResult readFileSize(ReadBuffer readBuffer, long fileSize, MapFileInfoBuilder mapFileInfoBuilder) {
static OpenResult readFileSize(ReadBuffer readBuffer, long fileSize,
MapFileInfoBuilder mapFileInfoBuilder) {
// get and check the file size (8 bytes)
long headerFileSize = readBuffer.readLong();
if (headerFileSize != fileSize) {
@@ -174,7 +176,8 @@ final class RequiredFields {
return OpenResult.SUCCESS;
}
static OpenResult readProjectionName(ReadBuffer readBuffer, MapFileInfoBuilder mapFileInfoBuilder) {
static OpenResult readProjectionName(ReadBuffer readBuffer,
MapFileInfoBuilder mapFileInfoBuilder) {
// get and check the projection name
String projectionName = readBuffer.readUTF8EncodedString();
if (!MERCATOR.equals(projectionName)) {

View File

@@ -120,14 +120,18 @@ public class SubFileParameter {
this.hashCodeValue = calculateHashCode();
// calculate the XY numbers of the boundary tiles in this sub-file
this.boundaryTileBottom = MercatorProjection.latitudeToTileY(subFileParameterBuilder.boundingBox.minLatitudeE6
/ COORDINATES_DIVISOR, this.baseZoomLevel);
this.boundaryTileLeft = MercatorProjection.longitudeToTileX(subFileParameterBuilder.boundingBox.minLongitudeE6
/ COORDINATES_DIVISOR, this.baseZoomLevel);
this.boundaryTileTop = MercatorProjection.latitudeToTileY(subFileParameterBuilder.boundingBox.maxLatitudeE6
/ COORDINATES_DIVISOR, this.baseZoomLevel);
this.boundaryTileRight = MercatorProjection.longitudeToTileX(subFileParameterBuilder.boundingBox.maxLongitudeE6
/ COORDINATES_DIVISOR, this.baseZoomLevel);
this.boundaryTileBottom = MercatorProjection.latitudeToTileY(
subFileParameterBuilder.boundingBox.minLatitudeE6
/ COORDINATES_DIVISOR, this.baseZoomLevel);
this.boundaryTileLeft = MercatorProjection.longitudeToTileX(
subFileParameterBuilder.boundingBox.minLongitudeE6
/ COORDINATES_DIVISOR, this.baseZoomLevel);
this.boundaryTileTop = MercatorProjection.latitudeToTileY(
subFileParameterBuilder.boundingBox.maxLatitudeE6
/ COORDINATES_DIVISOR, this.baseZoomLevel);
this.boundaryTileRight = MercatorProjection.longitudeToTileX(
subFileParameterBuilder.boundingBox.maxLongitudeE6
/ COORDINATES_DIVISOR, this.baseZoomLevel);
// calculate the horizontal and vertical amount of blocks in this sub-file
this.blocksWidth = this.boundaryTileRight - this.boundaryTileLeft + 1;