From bcc3f4a221281e1d3568cd8bef3904407045c065 Mon Sep 17 00:00:00 2001 From: Tim Fennell Date: Thu, 16 Jun 2016 21:15:05 -0400 Subject: [PATCH] Removed PollableTreeSet in SortingCollection as it was no longer necessary. (#642) Replaced with direct usage of TreeSet.pollFirst(). One advantage (other than removing unneeded code) is that this now only has to search the tree once, instead of twice for poll() then remove(). --- .../samtools/util/SortingCollection.java | 26 +++---------------- 1 file changed, 4 insertions(+), 22 deletions(-) diff --git a/src/main/java/htsjdk/samtools/util/SortingCollection.java b/src/main/java/htsjdk/samtools/util/SortingCollection.java index 681f458944..6babd4e35a 100644 --- a/src/main/java/htsjdk/samtools/util/SortingCollection.java +++ b/src/main/java/htsjdk/samtools/util/SortingCollection.java @@ -393,10 +393,10 @@ public void remove() { * location in the PriorityQueue */ class MergingIterator implements CloseableIterator { - private final PollableTreeSet queue; + private final TreeSet queue; MergingIterator() { - this.queue = new PollableTreeSet(new PeekFileRecordIteratorComparator()); + this.queue = new TreeSet(new PeekFileRecordIteratorComparator()); int n = 0; for (final File f : SortingCollection.this.files) { final FileRecordIterator it = new FileRecordIterator(f); @@ -418,7 +418,7 @@ public T next() { throw new NoSuchElementException(); } - final PeekFileRecordIterator fileIterator = queue.poll(); + final PeekFileRecordIterator fileIterator = queue.pollFirst(); final T ret = fileIterator.next(); if (fileIterator.hasNext()) { this.queue.add(fileIterator); @@ -436,7 +436,7 @@ public void remove() { public void close() { while (!this.queue.isEmpty()) { - final PeekFileRecordIterator it = this.queue.poll(); + final PeekFileRecordIterator it = this.queue.pollFirst(); ((CloseableIterator)it.getUnderlyingIterator()).close(); } } @@ -511,22 +511,4 @@ public int compare(final PeekFileRecordIterator lhs, final PeekFileRecordIterato else return result; } } - - /** Little class that provides the Java 1.5 TreeSet with a poll() method */ - static class PollableTreeSet extends TreeSet { - PollableTreeSet(final Comparator comparator) { - super(comparator); - } - - public T poll() { - if (isEmpty()) { - return null; - } - else { - final T t = first(); - remove(t); - return t; - } - } - } }