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.
Group
Modifier and Type | Method and Description |
---|---|
default Object |
computeGroup(T key,
Object group)
Compute the group for a given key
|
default String |
computeGroup(T key,
String group)
Deprecated.
Since 9.1
|
Class<T> |
getKeyType() |
default Object computeGroup(T key, Object group)
key
- the key to compute the group forgroup
- the group as currently computed, or null if no group has been determined yet@Deprecated default String computeGroup(T key, String group)
Copyright © 2021 JBoss by Red Hat. All rights reserved.