Skip to content

Commit

Permalink
Clarify confusing code
Browse files Browse the repository at this point in the history
  • Loading branch information
ramari16 committed Oct 9, 2024
1 parent 3ad5a31 commit c69e161
Showing 1 changed file with 6 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -220,24 +220,25 @@ public static void merge(VariantMetadataIndex variantMetadataIndex1, VariantMeta
String filePath = outputDirectory + VARIANT_METADATA_STORAGE_FILE_PREFIX + "_" + contig + ".bin";
FileBackedByteIndexedStorage<Integer, ConcurrentHashMap<String, String[]>> mergedFbbis = new FileBackedJavaIndexedStorage(Integer.class, ConcurrentHashMap.class, new File(filePath));

Map<Integer, ConcurrentHashMap<String, String[]>> mergedMockFbbis = new HashMap<>();
// Store the merged result here because FileBackedByteIndexedStorage must be written all at once
Map<Integer, ConcurrentHashMap<String, String[]>> mergedStagedFbbis = new HashMap<>();

FileBackedByteIndexedStorage<Integer, ConcurrentHashMap<String, String[]>> fbbis1 = variantMetadataIndex1.indexMap.get(contig);
FileBackedByteIndexedStorage<Integer, ConcurrentHashMap<String, String[]>> fbbis2 = variantMetadataIndex2.indexMap.get(contig);

fbbis1.keys().forEach(key -> {
mergedMockFbbis.put(key, fbbis1.get(key));
mergedStagedFbbis.put(key, fbbis1.get(key));
});
fbbis2.keys().forEach(key -> {
ConcurrentHashMap<String, String[]> metadataMap = mergedMockFbbis.get(key);
ConcurrentHashMap<String, String[]> metadataMap = mergedStagedFbbis.get(key);
if (metadataMap == null) {
mergedMockFbbis.put(key, fbbis2.get(key));
mergedStagedFbbis.put(key, fbbis2.get(key));
} else {
metadataMap.putAll(fbbis2.get(key));
}
});

mergedMockFbbis.forEach(mergedFbbis::put);
mergedStagedFbbis.forEach(mergedFbbis::put);
mergedFbbis.complete();
merged.indexMap.put(contig, mergedFbbis);
}
Expand Down

0 comments on commit c69e161

Please sign in to comment.