Interface AttributeAggregator
public interface AttributeAggregator
An attribute aggregator can, unsurprisingly, aggregate values of a certain
attribute data type. For example, there may be a data type called "Rich Text".
An aggregator can take values of "Rich Text" and aggregate the values into a
single value. Maybe the aggregation creates a single document out of multiple
documents. The most common anticipated use for aggregators is to sum values
of number types, where "sum" is an aggregator. Other aggregators on that type
might be "mean", "max", "min" and so on. These aggregated values can also
be used by calculations, since an aggregated value must have the same type
as the values it aggregates.
- Author:
- Per-Erik
-
Method Summary
Modifier and TypeMethodDescriptionaggregate
(List<PreparedAttribute> scalars) Returns a prepared attribute for the aggregated value of the scalar prepared attributes.getID()
Returns a universally unique id for aggregators of this kind.getName()
Returns a displayable name in the current default locale or if a name is not available in that locale, a default displayable name.boolean
isSupported
(AttributeDataType type) Returns true if the values of the given data type can be handled by this aggregator, false otherwise.prepare
(String value, String refinement, AttributeDataType dataType) Prepares the value for aggregation.
-
Method Details
-
isSupported
Returns true if the values of the given data type can be handled by this aggregator, false otherwise.- Parameters:
type
- The type in question- Returns:
- True if the values of the given data type can be handled by this aggregator, false otherwise.
-
getName
String getName()Returns a displayable name in the current default locale or if a name is not available in that locale, a default displayable name.- Returns:
- a best effort localized name.
-
getID
String getID()Returns a universally unique id for aggregators of this kind. (Not a unique id per instance, but per class/type.)- Returns:
- A universally unique id.
-
aggregate
Returns a prepared attribute for the aggregated value of the scalar prepared attributes. Note that the returned attribute may change the refinement, since the scalars may not have the same refienement. If this attribute aggregator for some reason can't aggregate the scalars, the returned value is a prepared attribute containing some default value.- Parameters:
scalars
- A non-empty list of prepared attributes to aggregate. All elements in the list are of the same data type and has been approved by isSupported.- Returns:
- A prepared attribute containing the aggregated value.
-
prepare
Prepares the value for aggregation. Some implementations may not need any preparation and can thus return a simple wrapper around the value, refinement and data type. Some implementations might need to fetch external data (external to the string value) before the aggregation can be properly performed (such as when the value is an id in some database).
Returning from this method indicates that the agreggator is ready to perform aggregation on the value.
NOTE: Since the refinement and data type may change for a value, this method may be called with values that are not consistent with the refinement and data type. If this is the case, the value was created for a different data type or a different refienement and should therefore be treated as the empty string (no value has been set yet).- Parameters:
value
- the value of the attributerefinement
- the attribute's refinementdataType
- the data type of the attribute- Returns:
- a prepared attribute whos data this aggregator is ready to use
-