]> gitweb.fperrin.net Git - GpsPrune.git/blob - tim/prune/function/cache/RowInfo.java
Version 14, October 2012
[GpsPrune.git] / tim / prune / function / cache / RowInfo.java
1 package tim.prune.function.cache;
2
3 /**
4  * Class to hold the information for a single table row.
5  * Used to describe a tileset or for a single zoom level of a tileset.
6  */
7 public class RowInfo
8 {
9         private int _zoom = -1;
10         private int _minZoom = -1, _maxZoom = -1;
11         private int _numTiles = 0;
12         private long _totalSize = 0L;
13         private boolean _unexpected = false;
14
15
16         /**
17          * Set the zoom level
18          * @param inZoom zoom level
19          */
20         public void setZoom(int inZoom) {
21                 _zoom = inZoom;
22         }
23
24         /**
25          * Add a zoom level and adjust max/min
26          * @param inZoom zoom level
27          */
28         public void addZoom(int inZoom)
29         {
30                 if (_minZoom < 0 || _minZoom > inZoom)
31                         _minZoom = inZoom;
32                 if (_maxZoom < inZoom)
33                         _maxZoom = inZoom;
34         }
35
36         /**
37          * @return the zoom level
38          */
39         public int getZoom() {
40                 return _zoom;
41         }
42
43         /**
44          * @return the zoom range as a string
45          */
46         public String getZoomRange()
47         {
48                 if (_minZoom < 0 && _maxZoom < 0) return "";
49                 if (_minZoom == _maxZoom || _maxZoom < 0) return "" + _minZoom;
50                 if (_minZoom < 0) return "" + _maxZoom;
51                 return "" + _minZoom + " - " + _maxZoom;
52         }
53
54         /**
55          * Add a single tile of the given size
56          * @param inSize size in bytes
57          */
58         public void addTile(long inSize) {
59                 addTiles(1, inSize);
60         }
61
62         /**
63          * Add the given tiles
64          * @param inNumTiles number of tiles to add
65          * @param inSize total size of the tiles in bytes
66          */
67         public void addTiles(int inNumTiles, long inSize)
68         {
69                 _numTiles += inNumTiles;
70                 _totalSize += inSize;
71         }
72
73         /**
74          * @return the total number of tiles found
75          */
76         public int getNumTiles() {
77                 return _numTiles;
78         }
79
80         /**
81          * @return the total size of the tiles in bytes
82          */
83         public long getTotalSize() {
84                 return _totalSize;
85         }
86
87         /**
88          * Mark that an unexpected file or directory was found
89          * TODO: Is this needed?
90          */
91         public void foundUnexpected() {
92                 _unexpected = true;
93         }
94
95         /**
96          * @return true if any unexpected files or directories were found
97          */
98         public boolean wasUnexpected() {
99                 return _unexpected;
100         }
101
102         /**
103          * Add the given RowInfo object to this one
104          * @param inOther other row object
105          */
106         public void addRow(RowInfo inOther)
107         {
108                 if (inOther == null)
109                         return;
110                 _numTiles  += inOther._numTiles;
111                 _totalSize += inOther._totalSize;
112                 // TODO: Max age
113                 // Zoom range
114                 if (inOther._minZoom > 0)
115                         addZoom(inOther._minZoom);
116                 if (inOther._maxZoom > 0)
117                         addZoom(inOther._maxZoom);
118                 if (inOther._zoom > 0)
119                         addZoom(inOther._zoom);
120                 _unexpected = _unexpected || inOther._unexpected;
121         }
122 }