|
1 | 1 | package io.tiledb; |
2 | 2 |
|
| 3 | +import com.google.common.collect.BiMap; |
| 4 | +import com.google.common.collect.HashBiMap; |
3 | 5 | import io.tiledb.cloud.rest_api.model.ArrayBrowserData; |
4 | 6 | import io.tiledb.cloud.rest_api.model.ArrayInfo; |
5 | 7 | import io.tiledb.util.Util; |
|
13 | 15 | import java.util.logging.Logger; |
14 | 16 |
|
15 | 17 | public class TileDBCloudTablesResultSet implements ResultSet { |
16 | | - public static HashMap<String, String> uris = new HashMap<>(); |
| 18 | + public static BiMap<String, String> shortUUIDToUri = HashBiMap.create(); |
17 | 19 | private List<ArrayInfo> arraysOwned = new ArrayList<ArrayInfo>(); |
18 | 20 | private List<ArrayInfo> arraysShared = new ArrayList<ArrayInfo>(); |
19 | 21 | private List<ArrayInfo> arraysPublic = new ArrayList<ArrayInfo>(); |
@@ -47,24 +49,41 @@ private void populateURIs() { |
47 | 49 | for (ArrayInfo arrayInfo : arraysOwned) { |
48 | 50 | String key = Util.getUUIDStart(arrayInfo.getTiledbUri()); |
49 | 51 | String value = arrayInfo.getTiledbUri(); |
50 | | - uris.put(key, value); |
| 52 | + putURI(key, value); |
51 | 53 | } |
52 | 54 |
|
53 | 55 | // Iterate through arraysShared and add entries to the HashMap |
54 | 56 | for (ArrayInfo arrayInfo : arraysShared) { |
55 | 57 | String key = Util.getUUIDStart(arrayInfo.getTiledbUri()); |
56 | 58 | String value = arrayInfo.getTiledbUri(); |
57 | | - uris.put(key, value); |
| 59 | + putURI(key, value); |
58 | 60 | } |
59 | 61 |
|
60 | 62 | // Iterate through arraysPublic and add entries to the HashMap |
61 | 63 | for (ArrayInfo arrayInfo : arraysPublic) { |
62 | 64 | String key = Util.getUUIDStart(arrayInfo.getTiledbUri()); |
63 | 65 | String value = arrayInfo.getTiledbUri(); |
64 | | - uris.put(key, value); |
| 66 | + putURI(key, value); |
65 | 67 | } |
66 | 68 | } |
67 | 69 |
|
| 70 | + /** |
| 71 | + * Puts a short UUID and value to the hashmap. If the key exists it will append "-1" or "-2", etc. |
| 72 | + * |
| 73 | + * @param key |
| 74 | + * @param value |
| 75 | + */ |
| 76 | + private void putURI(String key, String value) { |
| 77 | + int counter = 1; |
| 78 | + while (shortUUIDToUri.containsKey(key)) { |
| 79 | + key = key + "-" + counter; |
| 80 | + counter++; |
| 81 | + } |
| 82 | + // we might have an array that is both public and shared. In such cases there is |
| 83 | + // no need to display the array twice |
| 84 | + if (!shortUUIDToUri.inverse().containsKey(value)) shortUUIDToUri.put(key, value); |
| 85 | + } |
| 86 | + |
68 | 87 | public TileDBCloudTablesResultSet() { |
69 | 88 | this.numberOfArrays = 0; |
70 | 89 | } |
@@ -109,7 +128,7 @@ public String getString(int columnIndex) throws SQLException { |
109 | 128 | + "/" |
110 | 129 | + currentArray.getName() |
111 | 130 | + "][" |
112 | | - + Util.getUUIDStart(currentArray.getTiledbUri()) |
| 131 | + + shortUUIDToUri.inverse().get(currentArray.getTiledbUri()) |
113 | 132 | + "]"; |
114 | 133 | } |
115 | 134 |
|
@@ -213,7 +232,7 @@ public String getString(String columnLabel) throws SQLException { |
213 | 232 | + "/" |
214 | 233 | + currentArray.getName() |
215 | 234 | + "][" |
216 | | - + Util.getUUIDStart(currentArray.getTiledbUri()) |
| 235 | + + shortUUIDToUri.inverse().get(currentArray.getTiledbUri()) |
217 | 236 | + "]"; |
218 | 237 | case "REMARKS": |
219 | 238 | return ownership + " TileDB URI: " + currentArray.getTiledbUri(); |
|
0 commit comments