This class provides functionality for concurrently accumulating iterables of map entries, and the later efficiently sorting them or iterating over them via merge-sort. The concurrent nature of the class comes from the fact that iterables can be added to it without requiring synchronization between threads.
Important: Any added entry iterable must be already stricly ordered by the comparator that is going to be used for merge-sorting. Violating this requirement will result in incorrect operationg of the merge-sorted results.
Generally, an instance of this class is used in the following way:
- A new instance is created.
- Some arbitrary work is done by the caller, which results in one or more map entries that need to be sorted.
- Sorted iterables are added to the sorter instance, this can happen concurrently by multiple threads.
- The user decides to collect the entries, which is done by merge-sorting the previously collected sorted iterables and putting them into an appropriate collection, or iterator.
- The created collection/iterator can be used by the caller.
Using this class instead of directly putting the entries into a result collection can be more efficient, as the sorting can be done with fewer comparisons. However, in order for this class to work, the added iterables must be already sorted. If you're unsure whether the iterables that you're using with this class, don't use this, and fall back to some other solution, as the sorting algorithm in this class will break if unsorted iterables are added to it.
The iterables are to be added with their estimated sizes provided. With this size, the sorter can allocate a result storage for the sorted collections more efficiently, that can result in fewer reallocations. These sizes are estimates, clients are not required to provide actually correct values, but they are strongly encouraged to do so.
public enum | Enumeration for specifying which value should be kept if there are multiple conflicting keys. |
public | Creates a new empty instance. |
public void | Adds an iterable of entries with the estimated size to the sorter. |
public void | add( Adds a collection of entries to the sorter. |
public void | Adds the entries of a map to the sorter. |
public void | Adds the entries of a map with the estimated size to the sorter. |
public ConcurrentSkipListMap< | Executes the sorting for the currently added iterables and creates a new ConcurrentSkipListMap. |
public ConcurrentSkipListMap< | createConcurrentSkipListMap( Executes the sorting for the currently added iterables and creates a new ConcurrentSkipListMap. |
public ConcurrentSkipListMap< | createConcurrentSkipListMap( Executes the sorting for the currently added iterables and creates a new ConcurrentSkipListMap. |
public ConcurrentSkipListMap< | createConcurrentSkipListMap( Executes the sorting for the currently added iterables and creates a new ConcurrentSkipListMap. |
public NavigableMap< | Executes the sorting for the currently added iterables and creates a new immutable navigable map. |
public NavigableMap< | createImmutableNavigableMap( Executes the sorting for the currently added iterables and creates a new immutable navigable map. |
public NavigableMap< | createImmutableNavigableMap( Executes the sorting for the currently added iterables and creates a new immutable navigable map. |
public NavigableMap< | createImmutableNavigableMap( Executes the sorting for the currently added iterables and creates a new immutable navigable map. |
public TreeMap< | Executes the sorting for the currently added iterables and creates a new TreeMap. |
public TreeMap< | createTreeMap( Executes the sorting for the currently added iterables and creates a new TreeMap. |
public TreeMap< | createTreeMap( Executes the sorting for the currently added iterables and creates a new TreeMap. |
public TreeMap< | createTreeMap( Executes the sorting for the currently added iterables and creates a new TreeMap. |
public boolean | Checks if any iterables was added to this merge sorter. |
public Iterator< | iterator() Executes the sorting for the currently added iterables and returns an iterator for the entries. |
public Iterator< | iterator( Executes the sorting for the currently added iterables and returns an iterator for the entries. |
public Iterator< | iterator( Executes the sorting for the currently added iterables and returns an iterator for the entries. |
public Iterator< | iterator( Executes the sorting for the currently added iterables and returns an iterator for the entries. |
The iteration order of the entries must be sorted by the comparator that is going to be used for sorting.
null
.
The estimated size of the iterable will be based on the Collection.size(). If the collection is a
concurrent collection, consider calling add(
The iteration order of the entries must be sorted by the comparator that is going to be used for sorting.
null
.
The estimated size of the iterable will be based on the Map.size(). If the map is a concurrent map,
consider calling add(
The iteration order of the entries must be sorted by the comparator that is going to be used for sorting.
null
.The iteration order of the entries must be sorted by the comparator that is going to be used for sorting.
null
.Callers must ensure that all previously added iterables are sorted by their natural order.
This is the same as:
createConcurrentSkipListMap(MatchingKeyPolicy.DONT_CARE, null);
Callers must ensure that all previously added iterables are sorted by the argument comparator.
This is the same as:
createConcurrentSkipListMap(MatchingKeyPolicy.DONT_CARE, comparator);
null
to use the natural order of the
keys.Callers must ensure that all previously added iterables are sorted by their natural order.
This is the same as:
createConcurrentSkipListMap(matchingPolicy, null);
null
.Callers must ensure that all previously added iterables are sorted by the argument comparator.
null
to use the natural order of the
keys.null
.Callers must ensure that all previously added iterables are sorted by their natural order.
This is the same as:
createTreeMap(MatchingKeyPolicy.DONT_CARE, null);
Callers must ensure that all previously added iterables are sorted by the argument comparator.
This is the same as:
createTreeMap(MatchingKeyPolicy.DONT_CARE, comparator);
null
to use the natural order of the
keys.Callers must ensure that all previously added iterables are sorted by their natural order.
This is the same as:
createTreeMap(matchingPolicy, null);
null
.Callers must ensure that all previously added iterables are sorted by the argument comparator.
null
to use the natural order of the
keys.null
.Note that if there was any iterable added, the result of the sorting may still be empty.
true
if there is at least one iterable in this sorter.Callers must ensure that all previously added iterables are sorted by their natural order.
The actual sorting is done while the entries are being iterated. The class will not pre-allocate any storage or sort the entries before returning the iterator for the sorted entries.
The entries that the iterator iterates over are the same entry objects which are present in the iterables added to this sorter.
This is the same as:
iterator(MatchingKeyPolicy.DONT_CARE, null);
Callers must ensure that all previously added iterables are sorted by the argument comparator.
The actual sorting is done while the entries are being iterated. The class will not pre-allocate any storage or sort the entries before returning the iterator for the sorted entries.
The entries that the iterator iterates over are the same entry objects which are present in the iterables added to this sorter.
This is the same as:
iterator(MatchingKeyPolicy.DONT_CARE, comparator);
null
to use the natural order of the
keys.Callers must ensure that all previously added iterables are sorted by their natural order.
The actual sorting is done while the entries are being iterated. The class will not pre-allocate any storage or sort the entries before returning the iterator for the sorted entries.
The entries that the iterator iterates over are the same entry objects which are present in the iterables added to this sorter.
This is the same as:
iterator(matchingPolicy, null);
null
.Callers must ensure that all previously added iterables are sorted by the argument comparator.
The actual sorting is done while the entries are being iterated. The class will not pre-allocate any storage or sort the entries before returning the iterator for the sorted entries.
The entries that the iterator iterates over are the same entry objects which are present in the iterables added to this sorter.
null
to use the natural order of the
keys.null
.