From e051a566748ee30c3bac50dce2a49230251c0918 Mon Sep 17 00:00:00 2001 From: Nikolai Karulin Date: Wed, 17 Jan 2018 20:25:59 +0300 Subject: [PATCH] make SortingCollection.spillToDisk public(#1061) downstream users need access to this method in order to create parallel implementations --- .../samtools/util/SortingCollection.java | 4 ++-- .../samtools/util/SortingCollectionTest.java | 23 ++++++++++++++++++- 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/src/main/java/htsjdk/samtools/util/SortingCollection.java b/src/main/java/htsjdk/samtools/util/SortingCollection.java index 0dacb56c93..46b84c117b 100644 --- a/src/main/java/htsjdk/samtools/util/SortingCollection.java +++ b/src/main/java/htsjdk/samtools/util/SortingCollection.java @@ -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 @@ -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(); diff --git a/src/test/java/htsjdk/samtools/util/SortingCollectionTest.java b/src/test/java/htsjdk/samtools/util/SortingCollectionTest.java index 7254a877a4..9722de8a9e 100644 --- a/src/test/java/htsjdk/samtools/util/SortingCollectionTest.java +++ b/src/test/java/htsjdk/samtools/util/SortingCollectionTest.java @@ -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 @@ -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 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 sortingCollection) { int i = 0; while (sortingCollection.hasNext()) {