Class AbstractBigDecimalAggregator<T>

Type Parameters:
T - the type of the value to extract from
All Implemented Interfaces:
ExternalizableLite, PortableObject, InvocableMap.EntryAggregator<Object,Object,BigDecimal>, InvocableMap.StreamingAggregator<Object,Object,Object,BigDecimal>, Serializable, Cloneable
Direct Known Subclasses:
BigDecimalAverage, BigDecimalMax, BigDecimalMin, BigDecimalSum

public abstract class AbstractBigDecimalAggregator<T> extends AbstractAggregator<Object,Object,T,Number,BigDecimal>
Abstract aggregator that processes Number values extracted from a set of entries in a Map and returns a result in a form of a BigDecimal value. All the extracted objects will be treated as BigDecimal, BigInteger or Java double values. If the set of entries is empty, a null result is returned.
Since:
Coherence 3.2
Author:
gg 2006.02.13, Gunnar Hillert 2022.06.01
See Also:
  • Field Details

    • m_count

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

      protected transient BigDecimal m_decResult
      The running result value.
    • m_scale

      protected Integer m_scale
      The scale used for the aggregated calculation. Is null by default, in which case the defaults of the underlying BigDecimal are being used.
    • m_mathContext

      protected MathContext m_mathContext
      The MathContext to provide the precision. Is null by default, in which case the defaults of the underlying BigDecimal are being used.
    • m_roundingMode

      protected RoundingMode m_roundingMode
      The RoundingMode used for the aggregated calculation. Is null by default, in which case the defaults of the underlying BigDecimal are being used.
    • m_fStripTrailingZeros

      protected boolean m_fStripTrailingZeros
      Shall trailing zeros be removed from the aggregation result? Defaults to false.
  • Constructor Details

    • AbstractBigDecimalAggregator

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

      public AbstractBigDecimalAggregator(ValueExtractor<? super T,? extends Number> extractor)
      Construct an AbstractBigDecimalAggregator object.
      Parameters:
      extractor - the extractor that provides a value in the form of any Java object that is a Number
    • AbstractBigDecimalAggregator

      public AbstractBigDecimalAggregator(String sMethod)
      Construct an AbstractBigDecimalAggregator object.
      Parameters:
      sMethod - the name of the method that returns a value in the form of any Java object that is a Number
  • Method Details

    • init

      protected void init(boolean fFinal)
      Initialize the aggregation result.
      Specified by:
      init in class AbstractAggregator<Object,Object,T,Number,BigDecimal>
      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 Object 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,Number,BigDecimal>
      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
    • equals

      public boolean equals(Object o)
      Description copied from class: AbstractAggregator
      Compares this object with another object for equality.
      Overrides:
      equals in class AbstractAggregator<Object,Object,T,Number,BigDecimal>
      Parameters:
      o - an object reference or null
      Returns:
      true iff the passed object reference is of the same class and has the same state as this object
    • hashCode

      public int hashCode()
      Description copied from class: AbstractAggregator
      Returns a hash code value for this object.
      Overrides:
      hashCode in class AbstractAggregator<Object,Object,T,Number,BigDecimal>
      Returns:
      a hash code value for this object
    • ensureBigDecimal

      public static BigDecimal ensureBigDecimal(Number num)
      Ensure the specified Number is a BigDecimal value or convert it into a new BigDecimal object.
      Parameters:
      num - a Number object
      Returns:
      a BigDecimal object that is equal to the passed in Number
    • getScale

      public Integer getScale()
      Returns the specified scale. Can be null.
      Returns:
      the scale to return. Can be null.
    • setScale

      public void setScale(Integer scale)
      Specifies the scale to be applied to the aggregated result. Typically, scale is set together with setRoundingMode(RoundingMode). However, if the specified scaling operation would require rounding then a ArithmeticException will be thrown. If setMathContext(MathContext) is specified and the operation supports the MathContext then the setScale(Integer) property is ignored.
      Parameters:
      scale - the scale to set.
    • getMathContext

      public MathContext getMathContext()
      Returns the specified MathContext or null.
      Returns:
      the MathContext. Can be null.
    • setMathContext

      public void setMathContext(MathContext mathContext)
      Sets the MathContext (allowing you to work with precision instead of scale). If a BigDecimal operation supports both MathContext or scale and both properties are specified, then the MathContext is used and the scale is ignored.
      Parameters:
      mathContext - the MathContext to set.
    • getRoundingMode

      public RoundingMode getRoundingMode()
      Returns the RoundingMode that is applied to aggregation results.
      Returns:
      The RoundingMode. Can be null.
    • setRoundingMode

      public void setRoundingMode(RoundingMode roundingMode)
      Sets the RoundingMode for the results, e.g. if scale is applied to the aggregation result.
      Parameters:
      roundingMode - the RoundingMode to set. Can be null.
    • isStripTrailingZeros

      public boolean isStripTrailingZeros()
      Shall trailing zeros be removed from the aggregation result?
      Returns:
      true if trailing zeros are removed.
    • setStripTrailingZeros

      public void setStripTrailingZeros(boolean fStripTrailingZeros)
      Allows you to set the property to true to remove trailing zeros from the aggregation result.
      Parameters:
      fStripTrailingZeros - Defaults to false if not set.