Interface Grouper<T>
- Type Parameters:
T
-
public interface Grouper<T>
User applications may implement this interface in order to customize the compution of groups in cases when the modifying the
key is not possible, or when the value determined by the Group
annotation needs customizing.
Grouper
acts as an interceptor, passing the previously computed value in. The group passed to the first
Grouper
will be that determined by @Group
(if @Group
is defined).
For example:
public class KXGrouper implements Grouper<String> { // A pattern that can extract from a "kX" (e.g. k1, k2) style key private static Pattern kPattern = Pattern.compile("(ˆk)(\\d)$"); public String computeGroup(String key, String group) { Matcher matcher = kPattern.matcher(key); if (matcher.matches()) { String g = Integer.parseInt(matcher.group(2)) % 2 + ""; return g; } else return null; } public Class<String> getKeyType() { return String.class; } }
You must set the
groupsEnabled
property to true in your configuration in order to use groups. You can specify an order list of groupers there.
- Author:
- Pete Muir
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptiondefault Object
computeGroup
(T key, Object group) Compute the group for a given key
-
Method Details
-
computeGroup
Compute the group for a given key- Parameters:
key
- the key to compute the group forgroup
- the group as currently computed, or null if no group has been determined yet- Returns:
- the group, or null if no group is defined
-
getKeyType
-