All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.tangosol.util.aggregator.AbstractComparableAggregator Maven / Gradle / Ivy

There is a newer version: 24.09
Show newest version
/*
 * Copyright (c) 2000, 2022, Oracle and/or its affiliates.
 *
 * Licensed under the Universal Permissive License v 1.0 as shown at
 * https://oss.oracle.com/licenses/upl.
 */

package com.tangosol.util.aggregator;


import com.tangosol.io.pof.PofReader;
import com.tangosol.io.pof.PofWriter;

import com.tangosol.util.ValueExtractor;

import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;

import java.util.Comparator;

import jakarta.json.bind.annotation.JsonbProperty;


/**
* 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 {@link Comparable}, or
  • *
  • The AbstractComparableAggregator has to be provided with a * {@link Comparator} object.
  • *
* If the set of entries passed to {@link #accumulate} is empty, a * null result is returned. * * @param the type of the value to extract from * @param the type of the aggregation result * * @author gg 2006.02.13 * @since Coherence 3.2 */ public abstract class AbstractComparableAggregator extends AbstractAggregator { // ----- constructors --------------------------------------------------- /** * Default constructor (necessary for the ExternalizableLite interface). */ public AbstractComparableAggregator() { super(); } /** * Construct an AbstractComparableAggregator object. * * @param extractor the extractor that provides a value in the form of * any object that implements the {@link Comparable} * interface */ public > AbstractComparableAggregator(ValueExtractor extractor) { super((ValueExtractor) extractor); } /** * Construct an AbstractComparableAggregator object. * * @param extractor the extractor that provides an object to be compared * @param comparator the comparator used to compare the extracted object */ public AbstractComparableAggregator(ValueExtractor extractor, Comparator comparator) { super(extractor); m_comparator = comparator; } /** * Construct an AbstractComparableAggregator object. * * @param sMethod the name of the method that returns a value in the form * of any object that implements the {@link Comparable} * interface */ public AbstractComparableAggregator(String sMethod) { super(sMethod); } // ----- AbstractAggregator methods ------------------------------------- /** * {@inheritDoc} */ protected void init(boolean fFinal) { m_count = 0; m_oResult = null; } /** * {@inheritDoc} */ protected R finalizeResult(boolean fFinal) { return m_count == 0 ? null : m_oResult; } // ----- ExternalizableLite interface ----------------------------------- /** * {@inheritDoc} */ public void readExternal(DataInput in) throws IOException { super.readExternal(in); m_comparator = readObject(in); } /** * {@inheritDoc} */ public void writeExternal(DataOutput out) throws IOException { super.writeExternal(out); writeObject(out, m_comparator); } // ----- PortableObject interface --------------------------------------- /** * {@inheritDoc} */ public void readExternal(PofReader in) throws IOException { super.readExternal(in); m_comparator = in.readObject(2); } /** * {@inheritDoc} */ public void writeExternal(PofWriter out) throws IOException { super.writeExternal(out); out.writeObject(2, m_comparator); } // ----- data members --------------------------------------------------- /** * The count of processed entries. */ protected transient int m_count; /** * The running result value. */ protected transient R m_oResult; /** * The comparator to use for comparing extracted values. */ @JsonbProperty("comparator") protected Comparator m_comparator; }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy