Class AbstractComparableAggregator<T,R>

Type Parameters:
T - the type of the value to extract from
R - the type of the aggregation result
All Implemented Interfaces:
ExternalizableLite, PortableObject, InvocableMap.EntryAggregator<Object,Object,R>, InvocableMap.StreamingAggregator<Object,Object,Object,R>, Serializable, Cloneable
Direct Known Subclasses:
ComparableMax, ComparableMin

public abstract class AbstractComparableAggregator<T,R> extends AbstractAggregator<Object,Object,T,R,R>
Abstract aggregator that processes values extracted from a set of entries in a Map, with knowledge of how to compare those values. There are two way to use the AbstractComparableAggregator:
  • All the extracted objects must implement Comparable, or
  • The AbstractComparableAggregator has to be provided with a Comparator object.
If the set of entries passed to AbstractAggregator.accumulate(com.tangosol.util.Streamer<? extends com.tangosol.util.InvocableMap.Entry<? extends K, ? extends V>>) is empty, a null result is returned.
Since:
Coherence 3.2
Author:
gg 2006.02.13
See Also:
  • Field Details

    • m_count

      protected transient int m_count
      The count of processed entries.
    • m_oResult

      protected transient R m_oResult
      The running result value.
    • m_comparator

      protected Comparator<? super R> m_comparator
      The comparator to use for comparing extracted values.
  • Constructor Details

    • AbstractComparableAggregator

      public AbstractComparableAggregator()
      Default constructor (necessary for the ExternalizableLite interface).
    • AbstractComparableAggregator

      public AbstractComparableAggregator(ValueExtractor<? super T,? extends E> extractor)
      Construct an AbstractComparableAggregator object.
      Parameters:
      extractor - the extractor that provides a value in the form of any object that implements the Comparable interface
    • AbstractComparableAggregator

      public AbstractComparableAggregator(ValueExtractor<? super T,? extends R> extractor, Comparator<? super R> comparator)
      Construct an AbstractComparableAggregator object.
      Parameters:
      extractor - the extractor that provides an object to be compared
      comparator - the comparator used to compare the extracted object
    • AbstractComparableAggregator

      public AbstractComparableAggregator(String sMethod)
      Construct an AbstractComparableAggregator object.
      Parameters:
      sMethod - the name of the method that returns a value in the form of any object that implements the Comparable interface
  • Method Details

    • init

      protected void init(boolean fFinal)
      Initialize the aggregation result.
      Specified by:
      init in class AbstractAggregator<Object,Object,T,R,R>
      Parameters:
      fFinal - true is passed if the aggregation process that is being initialized must produce a final aggregation result; this will only be false if a parallel approach is being used and the initial (partial) aggregation process is being initialized
    • finalizeResult

      protected R finalizeResult(boolean fFinal)
      Obtain the result of the aggregation.

      If the fFinal parameter is true, the returned object must be the final result of the aggregation; otherwise, the returned object will be treated as a partial result that should be incorporated into the final result.

      Specified by:
      finalizeResult in class AbstractAggregator<Object,Object,T,R,R>
      Parameters:
      fFinal - true to indicate that the final result of the aggregation process should be returned; this will only be false if a parallel approach is being used
      Returns:
      the result of the aggregation process
    • readExternal

      public void readExternal(DataInput in) throws IOException
      Restore the contents of this object by loading the object's state from the passed DataInput object.
      Specified by:
      readExternal in interface ExternalizableLite
      Overrides:
      readExternal in class AbstractAggregator<Object,Object,T,R,R>
      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

      public void writeExternal(DataOutput out) throws IOException
      Save the contents of this object by storing the object's state into the passed DataOutput object.
      Specified by:
      writeExternal in interface ExternalizableLite
      Overrides:
      writeExternal in class AbstractAggregator<Object,Object,T,R,R>
      Parameters:
      out - the DataOutput stream to write the state of this object to
      Throws:
      IOException - if an I/O exception occurs
    • readExternal

      public void readExternal(PofReader in) throws IOException
      Restore the contents of a user type instance by reading its state using the specified PofReader object.
      Specified by:
      readExternal in interface PortableObject
      Overrides:
      readExternal in class AbstractAggregator<Object,Object,T,R,R>
      Parameters:
      in - the PofReader from which to read the object's state
      Throws:
      IOException - if an I/O error occurs
    • writeExternal

      public void writeExternal(PofWriter out) throws IOException
      Save the contents of a POF user type instance by writing its state using the specified PofWriter object.
      Specified by:
      writeExternal in interface PortableObject
      Overrides:
      writeExternal in class AbstractAggregator<Object,Object,T,R,R>
      Parameters:
      out - the PofWriter to which to write the object's state
      Throws:
      IOException - if an I/O error occurs