1 package tim.prune.function.cache;
4 import java.util.ArrayList;
8 * Class to hold information about a single tile set
9 * within the overall Tile Cache.
13 /** Summary row info for whole tileset */
14 private RowInfo _rowInfo = null;
15 /** Path relative to mapcache root */
16 private String _path = null;
17 /** Comma-separated list of configs using this tileset */
18 private String _usedBy = null;
19 /** List of infos for each zoom level */
20 private ArrayList<RowInfo> _zoomLevels = null;
25 * @param inDir directory of tileset
26 * @param inPath String describing relative path from cache root
27 * @param inUsedBy String describing which configs use this Tileset
29 public TileSet(File inDir, String inPath, String inUsedBy)
33 _rowInfo = new RowInfo();
34 _zoomLevels = new ArrayList<RowInfo>();
35 // Go through zoom directories and construct row info objects
36 if (inDir != null && inDir.exists() && inDir.isDirectory() && inDir.canRead())
38 for (File subdir : inDir.listFiles())
40 if (subdir != null && subdir.exists() && subdir.isDirectory()
41 && subdir.canRead() && isNumeric(subdir.getName()))
43 RowInfo row = makeRowInfo(subdir);
52 * Check if a directory name is numeric
53 * @param inName name of directory
54 * @return true if it only contains characters 0-9
56 public static boolean isNumeric(String inName)
58 if (inName == null || inName.equals("")) return false;
59 for (int i=0; i<inName.length(); i++)
61 char a = inName.charAt(i);
62 if (a < '0' || a > '9') return false;
68 * Make a RowInfo object from the given directory
69 * @param inDir directory for a single zoom level
70 * @return RowInfo object describing files and size
72 private static RowInfo makeRowInfo(File inDir)
74 RowInfo row = new RowInfo();
75 row.setZoom(Integer.parseInt(inDir.getName()));
76 for (File subdir : inDir.listFiles())
78 if (subdir != null && subdir.exists() && subdir.isDirectory()
79 && subdir.canRead() && isNumeric(subdir.getName()))
81 // Found a directory of images (finally!)
82 for (File f : subdir.listFiles())
84 if (f != null && f.exists() && f.isFile() && f.canRead())
86 final String filename = f.getName();
87 int dotpos = filename.lastIndexOf('.');
88 if (dotpos > 0 && isNumeric(filename.substring(0, dotpos))) {
89 row.addTile(f.length());
99 * @return row info object
101 public RowInfo getRowInfo() {
105 /** @return relative path to tileset */
106 public String getPath() {
110 /** @return users of tileset */
111 public String getUsedBy() {