Skip to content

Commit

Permalink
make SortingCollection.spillToDisk public(#1061)
Browse files Browse the repository at this point in the history
downstream users need access to this method in order to create parallel implementations
  • Loading branch information
Nikolai Karulin authored and lbergelson committed Jan 17, 2018
1 parent c791472 commit e051a56
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/main/java/htsjdk/samtools/util/SortingCollection.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* The MIT License
*
* Copyright (c) 2009 The Broad Institute
* Copyright (c) 2018 The Broad Institute
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
Expand Down Expand Up @@ -215,7 +215,7 @@ public void setDestructiveIteration(boolean destructiveIteration) {
/**
* Sort the records in memory, write them to a file, and clear the buffer of records in memory.
*/
private void spillToDisk() {
public void spillToDisk() {
try {
Arrays.sort(this.ramRecords, 0, this.numRecordsInRam, this.comparator);
final Path f = newTempFile();
Expand Down
23 changes: 22 additions & 1 deletion src/test/java/htsjdk/samtools/util/SortingCollectionTest.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* The MIT License
*
* Copyright (c) 2009 The Broad Institute
* Copyright (c) 2018 The Broad Institute
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
Expand Down Expand Up @@ -103,6 +103,27 @@ public void testPositive(final String testName, final int numStringsToGenerate,
Assert.assertEquals(tmpDir().list().length, 0);
}

@Test
public void spillToDiskTest() {
final SortingCollection<String> sortingCollection = makeSortingCollection(10);
final String[] strings = new String[] {
"1", "2", "3"
};

for (String str : strings) {
sortingCollection.add(str);
}

Assert.assertEquals(tmpDir().list().length, 0);
sortingCollection.spillToDisk();
Assert.assertEquals(tmpDir().list().length, 1);

assertIteratorEqualsList(strings, sortingCollection.iterator());

sortingCollection.cleanup();
Assert.assertEquals(tmpDir().list().length, 0);
}

private void assertIteratorEqualsList(final String[] strings, final Iterator<String> sortingCollection) {
int i = 0;
while (sortingCollection.hasNext()) {
Expand Down

0 comments on commit e051a56

Please sign in to comment.