K - the type of the Map entry keysV - the type of the Map entry valuesT - the type of the value to extract fromE - the type of the extracted valuepublic class TopNAggregator<K,V,T,E> extends Object implements InvocableMap.StreamingAggregator<K,V,TopNAggregator.PartialResult<E>,E[]>, ExternalizableLite, PortableObject
| Modifier and Type | Class and Description |
|---|---|
static class |
TopNAggregator.PartialResult<E>
The sorted partial result.
|
| Modifier and Type | Field and Description |
|---|---|
protected Comparator<? super E> |
m_comparator
The Comparator used to order the extracted values.
|
protected int |
m_cResults
The maximum number of results to include in the aggregation result.
|
protected ValueExtractor<? super T,? extends E> |
m_extractor
The ValueExtractor used by this aggregator.
|
protected boolean |
m_fParallel
True iff this aggregator is to be used in parallel.
|
BY_MEMBER, BY_PARTITION, PARALLEL, PRESENT_ONLY, RETAINS_ENTRIES, SERIAL| Constructor and Description |
|---|
TopNAggregator()
Default constructor.
|
TopNAggregator(ValueExtractor<? super T,? extends E> extractor, Comparator<? super E> comparator, int cResults)
Construct a TopNAggregator that will aggregate the top extracted values, as determined by the specified comparator.
|
| Modifier and Type | Method and Description |
|---|---|
boolean |
accumulate(InvocableMap.Entry<? extends K,? extends V> entry)
Accumulate one entry into the result.
|
int |
characteristics()
A bit mask representing the set of characteristics of this aggregator.
|
boolean |
combine(TopNAggregator.PartialResult<E> partialResult)
Merge another partial result into the result.
|
protected void |
ensureInitialized()
Ensure that this aggregator is initialized.
|
E[] |
finalizeResult()
Return the final result of the aggregation.
|
TopNAggregator.PartialResult<E> |
getPartialResult()
Return the partial result of the aggregation.
|
void |
readExternal(DataInput in)
Restore the contents of this object by loading the object's state from the passed DataInput object.
|
void |
readExternal(PofReader in)
Restore the contents of a user type instance by reading its state using the specified PofReader object.
|
InvocableMap.StreamingAggregator<K,V,TopNAggregator.PartialResult<E>,E[]> |
supply()
Create a new instance of this aggregator.
|
void |
writeExternal(DataOutput out)
Save the contents of this object by storing the object's state into the passed DataOutput object.
|
void |
writeExternal(PofWriter out)
Save the contents of a POF user type instance by writing its state using the specified PofWriter object.
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitaccumulate, aggregate, isByMember, isByPartition, isParallel, isPresentOnly, isRetainsEntries, isSerialprotected boolean m_fParallel
protected ValueExtractor<? super T,? extends E> m_extractor
protected Comparator<? super E> m_comparator
protected int m_cResults
public TopNAggregator()
public TopNAggregator(ValueExtractor<? super T,? extends E> extractor, Comparator<? super E> comparator, int cResults)
extractor - the extractorcomparator - the comparator for extracted valuescResults - the maximum number of results to returnpublic InvocableMap.StreamingAggregator<K,V,TopNAggregator.PartialResult<E>,E[]> supply()
InvocableMap.StreamingAggregatorsupply in interface InvocableMap.StreamingAggregator<K,V,TopNAggregator.PartialResult<E>,E[]>public boolean accumulate(InvocableMap.Entry<? extends K,? extends V> entry)
InvocableMap.StreamingAggregatoraccumulate in interface InvocableMap.StreamingAggregator<K,V,TopNAggregator.PartialResult<E>,E[]>entry - the entry to accumulate into the aggregation resultpublic boolean combine(TopNAggregator.PartialResult<E> partialResult)
InvocableMap.StreamingAggregatorcombine in interface InvocableMap.StreamingAggregator<K,V,TopNAggregator.PartialResult<E>,E[]>partialResult - the partial result to mergepublic TopNAggregator.PartialResult<E> getPartialResult()
InvocableMap.StreamingAggregatorgetPartialResult in interface InvocableMap.StreamingAggregator<K,V,TopNAggregator.PartialResult<E>,E[]>public E[] finalizeResult()
InvocableMap.StreamingAggregatorfinalizeResult in interface InvocableMap.StreamingAggregator<K,V,TopNAggregator.PartialResult<E>,E[]>public int characteristics()
InvocableMap.StreamingAggregatorBe default, characteristics are a combination of InvocableMap.StreamingAggregator.PARALLEL and InvocableMap.StreamingAggregator.RETAINS_ENTRIES, which is sub-optimal and should be overridden by the aggregator implementation if the aggregator does not need to retain entries (which is often the case).
characteristics in interface InvocableMap.StreamingAggregator<K,V,TopNAggregator.PartialResult<E>,E[]>InvocableMap.StreamingAggregator.PARALLEL, InvocableMap.StreamingAggregator.SERIAL, InvocableMap.StreamingAggregator.BY_MEMBER, InvocableMap.StreamingAggregator.BY_PARTITION, InvocableMap.StreamingAggregator.RETAINS_ENTRIES, InvocableMap.StreamingAggregator.PRESENT_ONLYprotected void ensureInitialized()
public void readExternal(DataInput in) throws IOException
ExternalizableLitereadExternal in interface ExternalizableLitein - the DataInput stream to read data from in order to restore the state of this objectIOException - if an I/O exception occursNotActiveException - if the object is not in its initial state, and therefore cannot be deserialized intopublic void writeExternal(DataOutput out) throws IOException
ExternalizableLitewriteExternal in interface ExternalizableLiteout - the DataOutput stream to write the state of this object toIOException - if an I/O exception occurspublic void readExternal(PofReader in) throws IOException
PortableObjectreadExternal in interface PortableObjectin - the PofReader from which to read the object's stateIOException - if an I/O error occurspublic void writeExternal(PofWriter out) throws IOException
PortableObjectwriteExternal in interface PortableObjectout - the PofWriter to which to write the object's stateIOException - if an I/O error occurs