Skip to content

Commit

Permalink
Restore previous APIs for compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
nathanlws committed Oct 10, 2013
1 parent e2622e5 commit 20d686e
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/main/java/com/fasterxml/sort/IteratingSorter.java
Expand Up @@ -91,7 +91,7 @@ public Iterator<T> sort(DataReader<T> inputReader)
return null;
}
_mergerInputs = presorted;
_merger = merge(presorted);
_merger = _createMergeReader(merge(presorted));
iterator = new MergerIterator<T>(_merger);
}
} finally {
Expand Down
12 changes: 12 additions & 0 deletions src/main/java/com/fasterxml/sort/Sorter.java
Expand Up @@ -38,6 +38,18 @@ protected Sorter(SortConfig config) {
super(config);
}

protected Sorter<T> withReaderFactory(DataReaderFactory<T> f) {
return new Sorter<T>(_config, f, _writerFactory, _comparator);
}

protected Sorter<T> withWriterFactory(DataWriterFactory<T> f) {
return new Sorter<T>(_config, _readerFactory, f, _comparator);
}

protected Sorter<T> withComparator(Comparator<T> cmp) {
return new Sorter<T>(_config, _readerFactory, _writerFactory, cmp);
}


/*
/**********************************************************************
Expand Down
30 changes: 26 additions & 4 deletions src/main/java/com/fasterxml/sort/SorterBase.java
Expand Up @@ -241,10 +241,21 @@ protected File _writePresorted(Object[] items) throws IOException
*/

/**
* Main-level merge method called during once during sorting.
* @return DataReader that will produced a fully sorted stream.
* Main-level merge method that sorts the given input and writes to final output.
*/
protected DataReader<T> merge(List<File> presorted)
protected void merge(List<File> presorted, DataWriter<T> resultWriter)
throws IOException
{
List<File> inputs = merge(presorted);
// and then last around to produce the result file
_merge(inputs, resultWriter);
}

/**
* Main-level merge method that sorts the given input.
* @return List of files that are individually sorted and ready for final merge.
*/
protected List<File> merge(List<File> presorted)
throws IOException
{
// Ok, let's see how many rounds we should have...
Expand All @@ -264,7 +275,18 @@ protected DataReader<T> merge(List<File> presorted)
// and then switch result files to be input files
inputs = outputs;
}
return _createMergeReader(inputs);
return inputs;
}

protected void _writeAll(DataWriter<T> resultWriter, Object[] items)
throws IOException
{
// need to go through acrobatics, due to type erasure... works, if ugly:
@SuppressWarnings("unchecked")
DataWriter<Object> writer = (DataWriter<Object>) resultWriter;
for (Object item : items) {
writer.writeEntry(item);
}
}

@SuppressWarnings("resource")
Expand Down

0 comments on commit 20d686e

Please sign in to comment.