public interface UserMentionScanner
Modifier and Type | Interface and Description |
---|---|
static interface |
UserMentionScanner.UserMention
Represents the location and content of a user mention in the text.
|
Modifier and Type | Method and Description |
---|---|
Set<String> |
getMentionedUsers(CharSequence text,
int maxMentions)
Returns all mentioned
user names in the text. |
void |
processMentions(CharSequence text,
Consumer<UserMentionScanner.UserMention> callback)
Calls
callback for each user mention found in text . |
String |
renderMention(String username)
Renders the full user mention for a
user name . |
Optional<CharSequence> |
replaceMentions(CharSequence text,
Function<UserMentionScanner.UserMention,Optional<String>> replacementFunction)
Replaces all user mentions with the string returned from the passed
replacementFunction . |
@Nonnull Set<String> getMentionedUsers(@Nonnull CharSequence text, int maxMentions)
user names
in the text.
Note that the case of the user name returned matches the case used in the text and might not be identical to the
case of the ApplicationUser's name
.
text
- text to search for user mentionsmaxMentions
- maximum size of the returned setuser names
mentionedvoid processMentions(@Nonnull CharSequence text, @Nonnull Consumer<UserMentionScanner.UserMention> callback)
callback
for each user mention found in text
.text
- text to search for user mentionscallback
- callback that gets called for every user mention found@Nonnull String renderMention(@Nonnull String username)
user name
.username
- user name
to render@Nonnull Optional<CharSequence> replaceMentions(@Nonnull CharSequence text, @Nonnull Function<UserMentionScanner.UserMention,Optional<String>> replacementFunction)
replacementFunction
.
Return types for both the replacementFunction
as well as this method are Optional
so the calling
code can perform more efficient operations when no replacements have taken place.
Example usage:
String replacedText = userMentionScanner.replaceMentions(text, mention ->
Optional.of(userMentionScanner.renderMention(mention.getUsername().replace("_", "-"))))
.orElse(text);
text
- text to search and replace user mentions inreplacementFunction
- function that optionally returns a replacement for the full mention of the userOptional.empty()
if no replacement took placeCopyright © 2019 Atlassian. All rights reserved.