11package mil .nga .geopackage ;
22
3+ import java .util .Collection ;
34import java .util .HashMap ;
5+ import java .util .HashSet ;
46import java .util .Map ;
7+ import java .util .Set ;
58
69/**
710 * Abstract GeoPackage Core Cache for maintaining and reusing open GeoPackage
@@ -26,6 +29,26 @@ public GeoPackageCoreCache() {
2629
2730 }
2831
32+ /**
33+ * Get the names of the cached GeoPackages
34+ *
35+ * @return set of cached GeoPackage names
36+ * @since 1.0.1
37+ */
38+ public Set <String > getNames () {
39+ return cache .keySet ();
40+ }
41+
42+ /**
43+ * Get the cached GeoPackages
44+ *
45+ * @return collection of cached GeoPackages
46+ * @since 1.0.1
47+ */
48+ public Collection <T > getGeoPackages () {
49+ return cache .values ();
50+ }
51+
2952 /**
3053 * Get the GeoPackage with name
3154 *
@@ -66,7 +89,8 @@ public void add(T geoPackage) {
6689 }
6790
6891 /**
69- * Remove the GeoPackage with the name
92+ * Remove the GeoPackage with the name but does not close it, call
93+ * {@link #close(String)} to close and remove
7094 *
7195 * @param name
7296 * @return removed GeoPackage
@@ -76,17 +100,64 @@ public T remove(String name) {
76100 }
77101
78102 /**
79- * Remove and close the GeoPackage with name
103+ * Clears all cached GeoPackages but does not close them, call
104+ * {@link #closeAll()} to close and clear all GeoPackages
105+ *
106+ * @since 1.0.1
107+ */
108+ public void clear () {
109+ cache .clear ();
110+ }
111+
112+ /**
113+ * Remove and close the GeoPackage with name, same as {@link #close(String)}
80114 *
81115 * @param name
82116 * @return true if found, removed, and closed
83117 */
84118 public boolean removeAndClose (String name ) {
119+ return close (name );
120+ }
121+
122+ /**
123+ * Close the GeoPackage with name
124+ *
125+ * @param name
126+ * @return true if found and closed
127+ * @since 1.0.1
128+ */
129+ public boolean close (String name ) {
85130 T geoPackage = remove (name );
86131 if (geoPackage != null ) {
87132 geoPackage .close ();
88133 }
89134 return geoPackage != null ;
90135 }
91136
137+ /**
138+ * Close GeoPackages not specified in the retain GeoPackage names
139+ *
140+ * @param retain
141+ * @since 1.0.1
142+ */
143+ public void closeRetain (Collection <String > retain ) {
144+ Set <String > close = new HashSet <>(cache .keySet ());
145+ close .removeAll (retain );
146+ for (String name : close ) {
147+ close (name );
148+ }
149+ }
150+
151+ /**
152+ * Close GeoPackages with names
153+ *
154+ * @param names
155+ * @since 1.0.1
156+ */
157+ public void close (Collection <String > names ) {
158+ for (String name : names ) {
159+ close (name );
160+ }
161+ }
162+
92163}
0 commit comments