X-Git-Url: http://gitweb.fperrin.net/?p=GpsPrune.git;a=blobdiff_plain;f=tim%2Fprune%2Ffunction%2Fcache%2FTileSet.java;fp=tim%2Fprune%2Ffunction%2Fcache%2FTileSet.java;h=525696e518e8566289b90cb11691930fbef9e2fc;hp=ca2b81a442fdf2b57136a1232132ef0a4b1c644b;hb=0a2480df5845e2d7190dfdec9b2653b1609e853d;hpb=2154b1969ac2995cca46546f217f53c066b0b749 diff --git a/tim/prune/function/cache/TileSet.java b/tim/prune/function/cache/TileSet.java index ca2b81a..525696e 100644 --- a/tim/prune/function/cache/TileSet.java +++ b/tim/prune/function/cache/TileSet.java @@ -59,6 +59,35 @@ public class TileSet return true; } + /** + * Check if a filename is numeric up until the first dot + * This appears to be much faster than scanning for a . with indexOf, then + * chopping to make a new String, and then calling isNumeric to scan through again + * @param inName name of file + * @return true if it only contains characters 0-9 before the first dot + */ + public static boolean isNumericUntilDot(String inName) + { + if (inName == null || inName.equals("") || inName.charAt(0) == '.') { + return false; + } + try + { + char c = '.'; + int i = 0; + do + { + c = inName.charAt(i); + if (c == '.') return true; // found the dot, so stop + if (c < '0' || c > '9') return false; // not numeric + i++; + } while (c != '\0'); + } + catch (IndexOutOfBoundsException iobe) {} + // Didn't find a dot, so can't be a valid name + return false; + } + /** * Make a RowInfo object from the given directory * @param inDir directory for a single zoom level @@ -78,9 +107,7 @@ public class TileSet { if (f != null && f.exists() && f.isFile() && f.canRead()) { - final String filename = f.getName(); - int dotpos = filename.lastIndexOf('.'); - if (dotpos > 0 && isNumeric(filename.substring(0, dotpos))) { + if (isNumericUntilDot(f.getName())) { row.addTile(f.length()); } }