]> gitweb.fperrin.net Git - GpsPrune.git/blobdiff - tim/prune/function/cache/TileSet.java
Version 18, July 2015
[GpsPrune.git] / tim / prune / function / cache / TileSet.java
index 3e308ba6366081a7530f6f1e77b4e74c8ffcd086..525696e518e8566289b90cb11691930fbef9e2fc 100644 (file)
@@ -1,7 +1,6 @@
 package tim.prune.function.cache;
 
 import java.io.File;
-import java.util.ArrayList;
 
 
 /**
@@ -16,8 +15,6 @@ public class TileSet
        private String _path = null;
        /** Comma-separated list of configs using this tileset */
        private String _usedBy = null;
-       /** List of infos for each zoom level */
-       private ArrayList<RowInfo> _zoomLevels = null;
 
 
        /**
@@ -31,7 +28,6 @@ public class TileSet
                _path = inPath;
                _usedBy = inUsedBy;
                _rowInfo = new RowInfo();
-               _zoomLevels = new ArrayList<RowInfo>();
                // Go through zoom directories and construct row info objects
                if (inDir != null && inDir.exists() && inDir.isDirectory() && inDir.canRead())
                {
@@ -41,7 +37,6 @@ public class TileSet
                                        && subdir.canRead() && isNumeric(subdir.getName()))
                                {
                                        RowInfo row = makeRowInfo(subdir);
-                                       _zoomLevels.add(row);
                                        _rowInfo.addRow(row);
                                }
                        }
@@ -64,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
@@ -83,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());
                                                }
                                        }