]> gitweb.fperrin.net Git - GpsPrune.git/blob - tim/prune/function/cache/TileSet.java
Version 17.2, February 2015
[GpsPrune.git] / tim / prune / function / cache / TileSet.java
1 package tim.prune.function.cache;
2
3 import java.io.File;
4
5
6 /**
7  * Class to hold information about a single tile set
8  * within the overall Tile Cache.
9  */
10 public class TileSet
11 {
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;
18
19
20         /**
21          * Constructor
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
25          */
26         public TileSet(File inDir, String inPath, String inUsedBy)
27         {
28                 _path = inPath;
29                 _usedBy = 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())
33                 {
34                         for (File subdir : inDir.listFiles())
35                         {
36                                 if (subdir != null && subdir.exists() && subdir.isDirectory()
37                                         && subdir.canRead() && isNumeric(subdir.getName()))
38                                 {
39                                         RowInfo row = makeRowInfo(subdir);
40                                         _rowInfo.addRow(row);
41                                 }
42                         }
43                 }
44         }
45
46         /**
47          * Check if a directory name is numeric
48          * @param inName name of directory
49          * @return true if it only contains characters 0-9
50          */
51         public static boolean isNumeric(String inName)
52         {
53                 if (inName == null || inName.equals("")) return false;
54                 for (int i=0; i<inName.length(); i++)
55                 {
56                         char a = inName.charAt(i);
57                         if (a < '0' || a > '9') return false;
58                 }
59                 return true;
60         }
61
62         /**
63          * Make a RowInfo object from the given directory
64          * @param inDir directory for a single zoom level
65          * @return RowInfo object describing files and size
66          */
67         private static RowInfo makeRowInfo(File inDir)
68         {
69                 RowInfo row = new RowInfo();
70                 row.setZoom(Integer.parseInt(inDir.getName()));
71                 for (File subdir : inDir.listFiles())
72                 {
73                         if (subdir != null && subdir.exists() && subdir.isDirectory()
74                                 && subdir.canRead() && isNumeric(subdir.getName()))
75                         {
76                                 // Found a directory of images (finally!)
77                                 for (File f : subdir.listFiles())
78                                 {
79                                         if (f != null && f.exists() && f.isFile() && f.canRead())
80                                         {
81                                                 final String filename = f.getName();
82                                                 int dotpos = filename.lastIndexOf('.');
83                                                 if (dotpos > 0 && isNumeric(filename.substring(0, dotpos))) {
84                                                         row.addTile(f.length());
85                                                 }
86                                         }
87                                 }
88                         }
89                 }
90                 return row;
91         }
92
93         /**
94          * @return row info object
95          */
96         public RowInfo getRowInfo() {
97                 return _rowInfo;
98         }
99
100         /** @return relative path to tileset */
101         public String getPath() {
102                 return _path;
103         }
104
105         /** @return users of tileset */
106         public String getUsedBy() {
107                 return _usedBy;
108         }
109 }