use of com.cinchapi.concourse.util.Navigation in project concourse by cinchapi.
the class Operations method browseNavigationKeyOptionalAtomic.
/**
* Perform "browse" functionality on a navigation key.
*
* @param key
* @param timestamp
* @param store
* @return a mapping from each possible destination value for a given
* navigation {@code key} to the records where the navigation could
* begin to retrieve the value by selecting the navigation
* {@code key}
*/
public static Map<TObject, Set<Long>> browseNavigationKeyOptionalAtomic(String key, long timestamp, Store store) {
String[] toks = key.split("\\.");
if (toks.length == 1) {
return timestamp == Time.NONE ? store.browse(key) : store.browse(key, timestamp);
} else {
String start = toks[0];
StringBuilder $key = new StringBuilder();
for (int i = 1; i < toks.length - 1; ++i) {
$key.append(toks[i]).append('.');
}
$key.append(toks[toks.length - 1]);
Map<TObject, Set<Long>> root = timestamp == Time.NONE ? store.browse(start) : store.browse(start, timestamp);
Map<TObject, Set<Long>> index = Maps.newLinkedHashMap();
root.entrySet().stream().filter(e -> e.getKey().getType() == Type.LINK).forEach(entry -> {
Link link = (Link) Convert.thriftToJava(entry.getKey());
Set<Long> nodes = entry.getValue();
for (long node : nodes) {
Set<TObject> values = traverseKeyRecordOptionalAtomic($key.toString(), link.longValue(), timestamp, store);
for (TObject value : values) {
index.computeIfAbsent(value, ignore -> Sets.newLinkedHashSet()).add(node);
}
}
});
return index;
}
}
Aggregations