Skip to content

Commit

Permalink
Reformatting the code base with Palantir
Browse files Browse the repository at this point in the history
  • Loading branch information
aaime committed Dec 23, 2024
1 parent 0e15ca0 commit e2f6559
Show file tree
Hide file tree
Showing 553 changed files with 12,759 additions and 19,392 deletions.
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
/**
* This program is free software: you can redistribute it and/or modify it under the terms of the
* GNU Lesser General Public License as published by the Free Software Foundation, either version 3
* of the License, or (at your option) any later version.
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General
* Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any
* later version.
*
* <p>This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* <p>This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
* <p>You should have received a copy of the GNU Lesser General Public License along with this
* program. If not, see <http://www.gnu.org/licenses/>.
* <p>You should have received a copy of the GNU Lesser General Public License along with this program. If not, see
* <http://www.gnu.org/licenses/>.
*
* <p>Copyright 2019
*/
Expand Down Expand Up @@ -56,8 +55,8 @@ public abstract class ArcGISCompactCache {
* @param zoom Zoom levl
* @param row Row
* @param col Column
* @return String containing complete path without file extension in the form of
* .../Lzz/RrrrrCcccc with the number of c and r at least 4.
* @return String containing complete path without file extension in the form of .../Lzz/RrrrrCcccc with the number
* of c and r at least 4.
*/
protected String buildBundleFilePath(int zoom, int row, int col) {
StringBuilder bundlePath = new StringBuilder(pathToCacheRoot);
Expand Down Expand Up @@ -96,9 +95,8 @@ protected String buildBundleFilePath(int zoom, int row, int col) {
* @param filePath Path to file
* @param offset Read at offset
* @param length Read length bytes
* @return ByteBuffer that contains read bytes and has byte order set to little endian. The
* length of the byte buffer is multiple of 4, so getInt() and getLong() can be used even
* when fewer bytes are read.
* @return ByteBuffer that contains read bytes and has byte order set to little endian. The length of the byte
* buffer is multiple of 4, so getInt() and getLong() can be used even when fewer bytes are read.
*/
protected ByteBuffer readFromLittleEndianFile(String filePath, long offset, int length) {
ByteBuffer result = null;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
/**
* This program is free software: you can redistribute it and/or modify it under the terms of the
* GNU Lesser General Public License as published by the Free Software Foundation, either version 3
* of the License, or (at your option) any later version.
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General
* Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any
* later version.
*
* <p>This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* <p>This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
* <p>You should have received a copy of the GNU Lesser General Public License along with this
* program. If not, see <http://www.gnu.org/licenses/>.
* <p>You should have received a copy of the GNU Lesser General Public License along with this program. If not, see
* <http://www.gnu.org/licenses/>.
*
* <p>Copyright 2019
*/
Expand All @@ -21,13 +20,12 @@
/**
* Implementation of ArcGIS compact caches for ArcGIS 10.0 - 10.2
*
* <p>The compact cache consists of bundle index files (*.bundlx) and bundle files (*.bundle), that
* contain the actual image data. Every .bundlx file contains a 16 byte header and 16 byte footer.
* Between header and footer is 128x128 matrix (16384 tiles) of 5 byte offsets. Every offset points
* to a 4 byte word in the corresponding .bundle file which contains the size of the tile image
* data. The actual image data starts at offset+4. If the size is zero there is no image data
* available and the index entry is not used. If the map cache has more than 128 rows or columns it
* is divided into several .bundlx and .bundle files.
* <p>The compact cache consists of bundle index files (*.bundlx) and bundle files (*.bundle), that contain the actual
* image data. Every .bundlx file contains a 16 byte header and 16 byte footer. Between header and footer is 128x128
* matrix (16384 tiles) of 5 byte offsets. Every offset points to a 4 byte word in the corresponding .bundle file which
* contains the size of the tile image data. The actual image data starts at offset+4. If the size is zero there is no
* image data available and the index entry is not used. If the map cache has more than 128 rows or columns it is
* divided into several .bundlx and .bundle files.
*
* @author Bjoern Saxe
*/
Expand All @@ -39,12 +37,11 @@ public class ArcGISCompactCacheV1 extends ArcGISCompactCache {
/**
* Constructs new ArcGIS 10.0-10.2 compact cache.
*
* @param pathToCacheRoot Path to compact cache directory (usually ".../_alllayers/"). Path must
* contain directories for zoom levels (named "Lxx").
* @param pathToCacheRoot Path to compact cache directory (usually ".../_alllayers/"). Path must contain directories
* for zoom levels (named "Lxx").
*/
public ArcGISCompactCacheV1(String pathToCacheRoot) {
if (pathToCacheRoot.endsWith("" + File.separatorChar))
this.pathToCacheRoot = pathToCacheRoot;
if (pathToCacheRoot.endsWith("" + File.separatorChar)) this.pathToCacheRoot = pathToCacheRoot;
else this.pathToCacheRoot = pathToCacheRoot + File.separatorChar;

indexCache = new BundlxCache(10000);
Expand All @@ -60,16 +57,14 @@ public Resource getBundleFileResource(int zoom, int row, int col) {
Resource res = null;

if ((entry = indexCache.get(key)) != null) {
if (entry.size > 0)
res = new BundleFileResource(entry.pathToBundleFile, entry.offset, entry.size);
if (entry.size > 0) res = new BundleFileResource(entry.pathToBundleFile, entry.offset, entry.size);
} else {

String basePath = buildBundleFilePath(zoom, row, col);
String pathToBundlxFile = basePath + BUNDLX_EXT;
String pathToBundleFile = basePath + BUNDLE_EXT;

if (!(new File(pathToBundleFile)).exists() || !(new File(pathToBundlxFile)).exists())
return null;
if (!(new File(pathToBundleFile)).exists() || !(new File(pathToBundlxFile)).exists()) return null;

long tileOffset = readTileStartOffset(pathToBundlxFile, row, col);
int tileSize = readTileSize(pathToBundleFile, tileOffset);
Expand All @@ -89,8 +84,7 @@ public Resource getBundleFileResource(int zoom, int row, int col) {
private long readTileStartOffset(String bundlxFile, int row, int col) {
int index = BUNDLX_MAXIDX * (col % BUNDLX_MAXIDX) + (row % BUNDLX_MAXIDX);

ByteBuffer idxBytes =
readFromLittleEndianFile(bundlxFile, (index * 5) + COMPACT_CACHE_HEADER_LENGTH, 5);
ByteBuffer idxBytes = readFromLittleEndianFile(bundlxFile, (index * 5) + COMPACT_CACHE_HEADER_LENGTH, 5);

return idxBytes.getLong();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
/**
* This program is free software: you can redistribute it and/or modify it under the terms of the
* GNU Lesser General Public License as published by the Free Software Foundation, either version 3
* of the License, or (at your option) any later version.
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General
* Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any
* later version.
*
* <p>This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* <p>This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
* <p>You should have received a copy of the GNU Lesser General Public License along with this
* program. If not, see <http://www.gnu.org/licenses/>.
* <p>You should have received a copy of the GNU Lesser General Public License along with this program. If not, see
* <http://www.gnu.org/licenses/>.
*
* <p>Copyright 2019
*/
Expand All @@ -22,14 +21,12 @@
/**
* Implementation of ArcGIS compact caches for ArcGIS 10.3
*
* <p>The compact cache consists of bundle files (*.bundle), that contain an index and the actual
* image data. Every .bundle file starts with a 64 byte header. After the header 128x128 matrix
* (16384 tiles) of 8 byte words. The first 5 bytes of every word is the offset that points to the
* tile image data inside the same .bundle file. The next 3 bytes is the size of the image data. The
* size of the image data is repeated at offset-4 in 4 byte word. Unused index entries use
* 04|00|00|00|00|00|00|00. If the size is zero than there is no image data available and the index
* entry is. If the map cache has more than 128 rows or columns it is divided into several .bundle
* files.
* <p>The compact cache consists of bundle files (*.bundle), that contain an index and the actual image data. Every
* .bundle file starts with a 64 byte header. After the header 128x128 matrix (16384 tiles) of 8 byte words. The first 5
* bytes of every word is the offset that points to the tile image data inside the same .bundle file. The next 3 bytes
* is the size of the image data. The size of the image data is repeated at offset-4 in 4 byte word. Unused index
* entries use 04|00|00|00|00|00|00|00. If the size is zero than there is no image data available and the index entry
* is. If the map cache has more than 128 rows or columns it is divided into several .bundle files.
*
* @author Bjoern Saxe
*/
Expand All @@ -41,12 +38,11 @@ public class ArcGISCompactCacheV2 extends ArcGISCompactCache {
/**
* Constructs new ArcGIS 10.3 compact cache.
*
* @param pathToCacheRoot Path to compact cache directory (usually ".../_alllayers/"). Path must
* contain directories for zoom levels (named "Lxx").
* @param pathToCacheRoot Path to compact cache directory (usually ".../_alllayers/"). Path must contain directories
* for zoom levels (named "Lxx").
*/
public ArcGISCompactCacheV2(String pathToCacheRoot) {
if (pathToCacheRoot.endsWith("" + File.separatorChar))
this.pathToCacheRoot = pathToCacheRoot;
if (pathToCacheRoot.endsWith("" + File.separatorChar)) this.pathToCacheRoot = pathToCacheRoot;
else this.pathToCacheRoot = pathToCacheRoot + File.separatorChar;

indexCache = new BundlxCache(10000);
Expand All @@ -62,8 +58,7 @@ public Resource getBundleFileResource(int zoom, int row, int col) {
Resource res = null;

if ((entry = indexCache.get(key)) != null) {
if (entry.size > 0)
res = new BundleFileResource(entry.pathToBundleFile, entry.offset, entry.size);
if (entry.size > 0) res = new BundleFileResource(entry.pathToBundleFile, entry.offset, entry.size);
} else {

String basePath = buildBundleFilePath(zoom, row, col);
Expand All @@ -73,8 +68,7 @@ public Resource getBundleFileResource(int zoom, int row, int col) {

entry = createCacheEntry(pathToBundleFile, row, col);

if (entry.size > 0)
res = new BundleFileResource(pathToBundleFile, entry.offset, entry.size);
if (entry.size > 0) res = new BundleFileResource(pathToBundleFile, entry.offset, entry.size);

indexCache.put(key, entry);
}
Expand All @@ -87,16 +81,16 @@ private BundlxCache.CacheEntry createCacheEntry(String bundleFile, int row, int
int index = BUNDLX_MAXIDX * (row % BUNDLX_MAXIDX) + (col % BUNDLX_MAXIDX);

// to save one addtional read, we read all 8 bytes in one read
ByteBuffer offsetAndSize =
readFromLittleEndianFile(bundleFile, (index * 8) + COMPACT_CACHE_HEADER_LENGTH, 8);
ByteBuffer offsetAndSize = readFromLittleEndianFile(bundleFile, (index * 8) + COMPACT_CACHE_HEADER_LENGTH, 8);

byte[] offsetBytes = new byte[8];
byte[] sizeBytes = new byte[4];

offsetAndSize.get(offsetBytes, 0, 5);
offsetAndSize.get(sizeBytes, 0, 3);

long tileOffset = ByteBuffer.wrap(offsetBytes).order(ByteOrder.LITTLE_ENDIAN).getLong();
long tileOffset =
ByteBuffer.wrap(offsetBytes).order(ByteOrder.LITTLE_ENDIAN).getLong();
int tileSize = ByteBuffer.wrap(sizeBytes).order(ByteOrder.LITTLE_ENDIAN).getInt();

return new BundlxCache.CacheEntry(bundleFile, tileOffset, tileSize);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
/**
* This program is free software: you can redistribute it and/or modify it under the terms of the
* GNU Lesser General Public License as published by the Free Software Foundation, either version 3
* of the License, or (at your option) any later version.
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General
* Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any
* later version.
*
* <p>This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* <p>This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
* <p>You should have received a copy of the GNU Lesser General Public License along with this
* program. If not, see <http://www.gnu.org/licenses/>.
* <p>You should have received a copy of the GNU Lesser General Public License along with this program. If not, see
* <http://www.gnu.org/licenses/>.
*
* <p>Copyright 2019
*/
Expand Down Expand Up @@ -57,7 +56,8 @@ public long transferTo(WritableByteChannel target) throws IOException {
FileChannel in = fin.getChannel()) {
final long size = tileSize;
long written = 0;
while ((written += in.transferTo(tileOffset + written, size, target)) < size) ;
while ((written += in.transferTo(tileOffset + written, size, target)) < size)
;
return size;
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
/**
* This program is free software: you can redistribute it and/or modify it under the terms of the
* GNU Lesser General Public License as published by the Free Software Foundation, either version 3
* of the License, or (at your option) any later version.
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General
* Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any
* later version.
*
* <p>This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* <p>This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
* <p>You should have received a copy of the GNU Lesser General Public License along with this
* program. If not, see <http://www.gnu.org/licenses/>.
* <p>You should have received a copy of the GNU Lesser General Public License along with this program. If not, see
* <http://www.gnu.org/licenses/>.
*
* <p>Copyright 2019
*/
Expand All @@ -20,8 +19,8 @@
/**
* Cache that stores data from .bundlx files.
*
* <p>Zoom, row, and column of the tile are used as key. Entries contain the path to the .bundle
* file, the size of the tile and the offset of the image data inside the .bundle file.
* <p>Zoom, row, and column of the tile are used as key. Entries contain the path to the .bundle file, the size of the
* tile and the offset of the image data inside the .bundle file.
*
* @author Bjoern Saxe
*/
Expand Down Expand Up @@ -79,8 +78,8 @@ public CacheEntry(String pathToBundleFile, long offset, int size) {
/**
* Cache that stores the path ot the .
*
* @param maxSize Maximum size of cache. If the size of the cache equals maxSize, adding a new
* entry will remove the least recently used entry from the cache.
* @param maxSize Maximum size of cache. If the size of the cache equals maxSize, adding a new entry will remove the
* least recently used entry from the cache.
*/
public BundlxCache(int maxSize) {
indexCache = CacheBuilder.newBuilder().maximumSize(maxSize).build();
Expand All @@ -90,8 +89,7 @@ public BundlxCache(int maxSize) {
* Get the entry for a key from the cache.
*
* @param key Key.
* @return Returns the entry. Returns null if the key has a null value or if the key has no
* entry.
* @return Returns the entry. Returns null if the key has a null value or if the key has no entry.
*/
public synchronized CacheEntry get(CacheKey key) {
return indexCache.getIfPresent(key);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
/**
* This program is free software: you can redistribute it and/or modify it under the terms of the
* GNU Lesser General Public License as published by the Free Software Foundation, either version 3
* of the License, or (at your option) any later version.
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General
* Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any
* later version.
*
* <p>This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* <p>This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
* <p>You should have received a copy of the GNU Lesser General Public License along with this
* program. If not, see <http://www.gnu.org/licenses/>.
* <p>You should have received a copy of the GNU Lesser General Public License along with this program. If not, see
* <http://www.gnu.org/licenses/>.
*
* <p>Copyright 2019
*/
Expand Down
Loading

0 comments on commit e2f6559

Please sign in to comment.