Skip to content

Commit 20d686e

Browse files
committed
Restore previous APIs for compatibility
1 parent e2622e5 commit 20d686e

File tree

3 files changed

+39
-5
lines changed

3 files changed

+39
-5
lines changed

src/main/java/com/fasterxml/sort/IteratingSorter.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ public Iterator<T> sort(DataReader<T> inputReader)
9191
return null;
9292
}
9393
_mergerInputs = presorted;
94-
_merger = merge(presorted);
94+
_merger = _createMergeReader(merge(presorted));
9595
iterator = new MergerIterator<T>(_merger);
9696
}
9797
} finally {

src/main/java/com/fasterxml/sort/Sorter.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,18 @@ protected Sorter(SortConfig config) {
3838
super(config);
3939
}
4040

41+
protected Sorter<T> withReaderFactory(DataReaderFactory<T> f) {
42+
return new Sorter<T>(_config, f, _writerFactory, _comparator);
43+
}
44+
45+
protected Sorter<T> withWriterFactory(DataWriterFactory<T> f) {
46+
return new Sorter<T>(_config, _readerFactory, f, _comparator);
47+
}
48+
49+
protected Sorter<T> withComparator(Comparator<T> cmp) {
50+
return new Sorter<T>(_config, _readerFactory, _writerFactory, cmp);
51+
}
52+
4153

4254
/*
4355
/**********************************************************************

src/main/java/com/fasterxml/sort/SorterBase.java

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -241,10 +241,21 @@ protected File _writePresorted(Object[] items) throws IOException
241241
*/
242242

243243
/**
244-
* Main-level merge method called during once during sorting.
245-
* @return DataReader that will produced a fully sorted stream.
244+
* Main-level merge method that sorts the given input and writes to final output.
246245
*/
247-
protected DataReader<T> merge(List<File> presorted)
246+
protected void merge(List<File> presorted, DataWriter<T> resultWriter)
247+
throws IOException
248+
{
249+
List<File> inputs = merge(presorted);
250+
// and then last around to produce the result file
251+
_merge(inputs, resultWriter);
252+
}
253+
254+
/**
255+
* Main-level merge method that sorts the given input.
256+
* @return List of files that are individually sorted and ready for final merge.
257+
*/
258+
protected List<File> merge(List<File> presorted)
248259
throws IOException
249260
{
250261
// Ok, let's see how many rounds we should have...
@@ -264,7 +275,18 @@ protected DataReader<T> merge(List<File> presorted)
264275
// and then switch result files to be input files
265276
inputs = outputs;
266277
}
267-
return _createMergeReader(inputs);
278+
return inputs;
279+
}
280+
281+
protected void _writeAll(DataWriter<T> resultWriter, Object[] items)
282+
throws IOException
283+
{
284+
// need to go through acrobatics, due to type erasure... works, if ugly:
285+
@SuppressWarnings("unchecked")
286+
DataWriter<Object> writer = (DataWriter<Object>) resultWriter;
287+
for (Object item : items) {
288+
writer.writeEntry(item);
289+
}
268290
}
269291

270292
@SuppressWarnings("resource")

0 commit comments

Comments
 (0)