1 package tim.prune.function.cache;
7 * Class to hold information about a single tile set
8 * within the overall Tile Cache.
12 /** Summary row info for whole tileset */
13 private RowInfo _rowInfo = null;
14 /** Path relative to mapcache root */
15 private String _path = null;
16 /** Comma-separated list of configs using this tileset */
17 private String _usedBy = null;
22 * @param inDir directory of tileset
23 * @param inPath String describing relative path from cache root
24 * @param inUsedBy String describing which configs use this Tileset
26 public TileSet(File inDir, String inPath, String inUsedBy)
30 _rowInfo = new RowInfo();
31 // Go through zoom directories and construct row info objects
32 if (inDir != null && inDir.exists() && inDir.isDirectory() && inDir.canRead())
34 for (File subdir : inDir.listFiles())
36 if (subdir != null && subdir.exists() && subdir.isDirectory()
37 && subdir.canRead() && isNumeric(subdir.getName()))
39 RowInfo row = makeRowInfo(subdir);
47 * Check if a directory name is numeric
48 * @param inName name of directory
49 * @return true if it only contains characters 0-9
51 public static boolean isNumeric(String inName)
53 if (inName == null || inName.equals("")) return false;
54 for (int i=0; i<inName.length(); i++)
56 char a = inName.charAt(i);
57 if (a < '0' || a > '9') return false;
63 * Check if a filename is numeric up until the first dot
64 * This appears to be much faster than scanning for a . with indexOf, then
65 * chopping to make a new String, and then calling isNumeric to scan through again
66 * @param inName name of file
67 * @return true if it only contains characters 0-9 before the first dot
69 public static boolean isNumericUntilDot(String inName)
71 if (inName == null || inName.equals("") || inName.charAt(0) == '.') {
81 if (c == '.') return true; // found the dot, so stop
82 if (c < '0' || c > '9') return false; // not numeric
86 catch (IndexOutOfBoundsException iobe) {}
87 // Didn't find a dot, so can't be a valid name
92 * Make a RowInfo object from the given directory
93 * @param inDir directory for a single zoom level
94 * @return RowInfo object describing files and size
96 private static RowInfo makeRowInfo(File inDir)
98 RowInfo row = new RowInfo();
99 row.setZoom(Integer.parseInt(inDir.getName()));
100 for (File subdir : inDir.listFiles())
102 if (subdir != null && subdir.exists() && subdir.isDirectory()
103 && subdir.canRead() && isNumeric(subdir.getName()))
105 // Found a directory of images (finally!)
106 for (File f : subdir.listFiles())
108 if (f != null && f.exists() && f.isFile() && f.canRead())
110 if (isNumericUntilDot(f.getName())) {
111 row.addTile(f.length());
121 * @return row info object
123 public RowInfo getRowInfo() {
127 /** @return relative path to tileset */
128 public String getPath() {
132 /** @return users of tileset */
133 public String getUsedBy() {