com.hazelcast.mapreduce.aggregation
KeyIn
- the input key typeValueIn
- the input value typeValueOut
- the supplied value type@Beta public abstract class Supplier<KeyIn,ValueIn,ValueOut> extends Object implements Serializable
IMap
or MultiMap
to an
aggregation. Suppliers can also be used to filter elements based on keys or values
using KeyPredicate
s or
Predicate
s.PropertyExtractor
implementation to extract or transform selected values to another value type. This is necessary
if you don't want to aggregate the actual value type of the maps, but an attribute of it.
The following examples using Java 8 Lambda syntax but everything is fully Java 6 or 7 compatible
using implementations of the interfaces.
// Select all values, no need to transform Supplier supplier = Supplier.all(); // Select all values but transform to Integer Supplier supplier = Supplier.all((value) -> value.intValue()); // Select only values where the value is bigger than 50 Supplier supplier = Supplier.fromPredicate((entry) -> entry.getValue().intValue() > 50); // Select only values where the value is bigger than 50 and than chain it to a // supplier transformation to transform it into an Integer Supplier supplier = Supplier.fromPredicate((entry) -> entry.getValue().intValue() > 50, Supplier.all((value) -> value.intValue())); // Select only values where the key starts with "Foo" Supplier supplier = Supplier.fromKeyPredicate((key) -> key.startsWith("Foo")); // Select only values where the key starts with "Foo" and than chain it to a // supplier transformation to transform it into an Integer Supplier supplier = Supplier.fromKeyPredicate((key) -> key.startsWith("Foo"), Supplier.all((value) -> value.intValue()));
Constructor and Description |
---|
Supplier() |
Modifier and Type | Method and Description |
---|---|
static <KeyIn,ValueIn,ValueOut> |
all()
The predefined Supplier selects all values and does not perform any kind of data
transformation.
|
static <KeyIn,ValueIn,ValueOut> |
all(PropertyExtractor<ValueIn,ValueOut> propertyExtractor)
The predefined Supplier selects all values and performs the given
PropertyExtractor s transformation to the
input data. |
abstract ValueOut |
apply(Map.Entry<KeyIn,ValueIn> entry)
The apply method is used to apply the actual filtering or extraction / transformation
to the input entry.
If the input value should be ignored by the aggregation, the Supplier has to return |
static <KeyIn,ValueIn,ValueOut> |
fromKeyPredicate(KeyPredicate<KeyIn> keyPredicate)
The predefined Supplier selects values using the given
KeyPredicate
and does not perform any kind of data transformation. |
static <KeyIn,ValueIn,ValueOut> |
fromKeyPredicate(KeyPredicate<KeyIn> keyPredicate,
Supplier<KeyIn,ValueIn,ValueOut> chainedSupplier)
The predefined Supplier selects values using the given
KeyPredicate
and chains the filtered value to the given Supplier which might perform data transformation. |
static <KeyIn,ValueIn,ValueOut> |
fromPredicate(Predicate<KeyIn,ValueIn> predicate)
The predefined Supplier selects values using the given
Predicate
and does not perform any kind of data transformation. |
static <KeyIn,ValueIn,ValueOut> |
fromPredicate(Predicate<KeyIn,ValueIn> predicate,
Supplier<KeyIn,ValueIn,ValueOut> chainedSupplier)
The predefined Supplier selects values using the given
Predicate
and chains the filtered value to the given Supplier which might perform data transformation. |
public abstract ValueOut apply(Map.Entry<KeyIn,ValueIn> entry)
nullas the supplied value, therefor
nullis not a legal value itself!
entry
- the entry key-value pair to supply to the aggregationpublic static <KeyIn,ValueIn,ValueOut> Supplier<KeyIn,ValueIn,ValueOut> all()
KeyIn
- the input key typeValueIn
- the input value typeValueOut
- the supplied value typepublic static <KeyIn,ValueIn,ValueOut> Supplier<KeyIn,ValueIn,ValueOut> all(PropertyExtractor<ValueIn,ValueOut> propertyExtractor)
PropertyExtractor
s transformation to the
input data. The returned value type of the transformation needs to match the expected
value type of the aggregation.KeyIn
- the input key typeValueIn
- the input value typeValueOut
- the supplied value typepublic static <KeyIn,ValueIn,ValueOut> Supplier<KeyIn,ValueIn,ValueOut> fromPredicate(Predicate<KeyIn,ValueIn> predicate)
Predicate
and does not perform any kind of data transformation. Input value types need to match the
aggregations expected value type to make this Supplier work.KeyIn
- the input key typeValueIn
- the input value typeValueOut
- the supplied value typepublic static <KeyIn,ValueIn,ValueOut> Supplier<KeyIn,ValueIn,ValueOut> fromPredicate(Predicate<KeyIn,ValueIn> predicate, Supplier<KeyIn,ValueIn,ValueOut> chainedSupplier)
Predicate
and chains the filtered value to the given Supplier which might perform data transformation.KeyIn
- the input key typeValueIn
- the input value typeValueOut
- the supplied value typepublic static <KeyIn,ValueIn,ValueOut> Supplier<KeyIn,ValueIn,ValueOut> fromKeyPredicate(KeyPredicate<KeyIn> keyPredicate)
KeyPredicate
and does not perform any kind of data transformation. Input value types need to match the
aggregations expected value type to make this Supplier work.KeyIn
- the input key typeValueIn
- the input value typeValueOut
- the supplied value typepublic static <KeyIn,ValueIn,ValueOut> Supplier<KeyIn,ValueIn,ValueOut> fromKeyPredicate(KeyPredicate<KeyIn> keyPredicate, Supplier<KeyIn,ValueIn,ValueOut> chainedSupplier)
KeyPredicate
and chains the filtered value to the given Supplier which might perform data transformation.KeyIn
- the input key typeValueIn
- the input value typeValueOut
- the supplied value typeCopyright © 2015 Hazelcast, Inc.. All Rights Reserved.