Class TopNAggregator<K,V,T,E>
- Type Parameters:
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 value
- All Implemented Interfaces:
ExternalizableLite, PortableObject, InvocableMap.EntryAggregator<K,V, E[]>, InvocableMap.StreamingAggregator<K, V, TopNAggregator.PartialResult<E>, E[]>, Serializable
- Since:
- 12.1.3
- Author:
- rhl 2013.04.24
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classThe sorted partial result.Nested classes/interfaces inherited from interface InvocableMap.StreamingAggregator
InvocableMap.StreamingAggregator.RetractionResult -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected Comparator<? super E> The Comparator used to order the extracted values.protected intThe maximum number of results to include in the aggregation result.protected ValueExtractor<? super T, ? extends E> The ValueExtractor used by this aggregator.protected booleanTrue iff this aggregator is to be used in parallel.Fields inherited from interface InvocableMap.StreamingAggregator
ALLOW_INCONSISTENCIES, BY_MEMBER, BY_PARTITION, CONTINUOUS, PARALLEL, PRESENT_ONLY, RETAINS_ENTRIES, SERIAL, STATE_CHECKPOINTABLE -
Constructor Summary
ConstructorsConstructorDescriptionDefault 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. -
Method Summary
Modifier and TypeMethodDescriptionbooleanaccumulate(InvocableMap.Entry<? extends K, ? extends V> entry) Accumulate one entry into the result.intA bit mask representing the set of characteristics of this aggregator.booleancombine(TopNAggregator.PartialResult<E> partialResult) Merge another partial result into the result.protected voidEnsure that this aggregator is initialized.booleanE[]Return the final result of the aggregation.Comparator<? super E> Obtain the comparator used by this aggregator.Return the partial result of the aggregation.ValueExtractor<? super T, ? extends E> Obtain the extractor used by this aggregator.inthashCode()voidRestore the contents of a user type instance by reading its state using the specified PofReader object.voidRestore the contents of this object by loading the object's state from the passed DataInput object.voidrestoreState(Object oState) Restore a maintenance-state snapshot into this empty supplied instance.retract(InvocableMap.Entry<? extends K, ? extends V> entry) Retract the contribution of a single entry from the aggregation result.Return a detached, serializer-compatible snapshot of the state required to continue incremental maintenance.supply()Create a new instance of this aggregator.voidwriteExternal(PofWriter out) Save the contents of a POF user type instance by writing its state using the specified PofWriter object.voidwriteExternal(DataOutput out) Save the contents of this object by storing the object's state into the passed DataOutput object.Methods inherited from class Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface InvocableMap.StreamingAggregator
accumulate, aggregate, finalizeResult, getMaintenanceStatus, isAllowInconsistencies, isByMember, isByPartition, isContinuous, isParallel, isPresentOnly, isRetainsEntries, isSerial, isStateCheckpointable, update
-
Field Details
-
m_fParallel
protected boolean m_fParallelTrue iff this aggregator is to be used in parallel. -
m_extractor
The ValueExtractor used by this aggregator. -
m_comparator
The Comparator used to order the extracted values. -
m_cResults
protected int m_cResultsThe maximum number of results to include in the aggregation result.
-
-
Constructor Details
-
TopNAggregator
public TopNAggregator()Default constructor. -
TopNAggregator
public 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.- Parameters:
extractor- the extractorcomparator- the comparator for extracted valuescResults- the maximum number of results to return
-
-
Method Details
-
supply
Description copied from interface:InvocableMap.StreamingAggregatorCreate a new instance of this aggregator. -
accumulate
Description copied from interface:InvocableMap.StreamingAggregatorAccumulate one entry into the result.- Specified by:
accumulatein interfaceInvocableMap.StreamingAggregator<K,V, T, E> - Parameters:
entry- the entry to accumulate into the aggregation result- Returns:
trueto continue the aggregation, andfalseto signal to the caller that the result is ready and the aggregation can be short-circuited
-
retract
public InvocableMap.StreamingAggregator.RetractionResult retract(InvocableMap.Entry<? extends K, ? extends V> entry) Description copied from interface:InvocableMap.StreamingAggregatorRetract the contribution of a single entry from the aggregation result.When the supplied entry is a
MapTrigger.Entry, an implementation should retract the entry's original value. Otherwise, it should retract the value represented by the supplied entry.The default implementation cannot retract an entry and requires the caller to rebuild the aggregation result.
-
combine
Description copied from interface:InvocableMap.StreamingAggregatorMerge another partial result into the result. -
getPartialResult
Description copied from interface:InvocableMap.StreamingAggregatorReturn the partial result of the aggregation.- Specified by:
getPartialResultin interfaceInvocableMap.StreamingAggregator<K,V, T, E> - Returns:
- the partial result of the aggregation
-
finalizeResult
Description copied from interface:InvocableMap.StreamingAggregatorReturn the final result of the aggregation.- Specified by:
finalizeResultin interfaceInvocableMap.StreamingAggregator<K,V, T, E> - Returns:
- the final result of the aggregation
-
characteristics
public int characteristics()Description copied from interface:InvocableMap.StreamingAggregatorA bit mask representing the set of characteristics of this aggregator.By default, characteristics are a combination of
InvocableMap.StreamingAggregator.PARALLELandInvocableMap.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).- Specified by:
characteristicsin interfaceInvocableMap.StreamingAggregator<K,V, T, E> - Returns:
- a bit mask representing the set of characteristics of this aggregator
- See Also:
-
snapshotState
Description copied from interface:InvocableMap.StreamingAggregatorReturn a detached, serializer-compatible snapshot of the state required to continue incremental maintenance.This method is used only when
InvocableMap.StreamingAggregator.STATE_CHECKPOINTABLEis advertised. The default implementation does not support state checkpointing.- Specified by:
snapshotStatein interfaceInvocableMap.StreamingAggregator<K,V, T, E> - Returns:
- a detached maintenance-state snapshot
-
restoreState
Description copied from interface:InvocableMap.StreamingAggregatorRestore a maintenance-state snapshot into this empty supplied instance.This method is used only when
InvocableMap.StreamingAggregator.STATE_CHECKPOINTABLEis advertised. The default implementation does not support state checkpointing.- Specified by:
restoreStatein interfaceInvocableMap.StreamingAggregator<K,V, T, E> - Parameters:
oState- the snapshot returned byInvocableMap.StreamingAggregator.snapshotState()
-
equals
-
hashCode
-
getValueExtractor
Obtain the extractor used by this aggregator.- Returns:
- the extractor
-
getComparator
Obtain the comparator used by this aggregator.- Returns:
- the comparator
-
ensureInitialized
protected void ensureInitialized()Ensure that this aggregator is initialized. -
readExternal
Description copied from interface:ExternalizableLiteRestore the contents of this object by loading the object's state from the passed DataInput object.- Specified by:
readExternalin interfaceExternalizableLite- Parameters:
in- the DataInput stream to read data from in order to restore the state of this object- Throws:
IOException- if an I/O exception occurs
-
writeExternal
Description copied from interface:ExternalizableLiteSave the contents of this object by storing the object's state into the passed DataOutput object.- Specified by:
writeExternalin interfaceExternalizableLite- Parameters:
out- the DataOutput stream to write the state of this object to- Throws:
IOException- if an I/O exception occurs
-
readExternal
Description copied from interface:PortableObjectRestore the contents of a user type instance by reading its state using the specified PofReader object.- Specified by:
readExternalin interfacePortableObject- Parameters:
in- the PofReader from which to read the object's state- Throws:
IOException- if an I/O error occurs
-
writeExternal
Description copied from interface:PortableObjectSave the contents of a POF user type instance by writing its state using the specified PofWriter object.- Specified by:
writeExternalin interfacePortableObject- Parameters:
out- the PofWriter to which to write the object's state- Throws:
IOException- if an I/O error occurs
-