-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Handle wildcard parameter in Streams list API (#411)
- Loading branch information
1 parent
9ff07e2
commit 58eff83
Showing
6 changed files
with
456 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package com.michelin.ns4kafka.util; | ||
|
||
import java.util.List; | ||
import java.util.regex.Pattern; | ||
import lombok.AccessLevel; | ||
import lombok.NoArgsConstructor; | ||
|
||
/** | ||
* Regex utils. | ||
*/ | ||
@NoArgsConstructor(access = AccessLevel.PRIVATE) | ||
public class RegexUtils { | ||
/** | ||
* Convert wildcard strings list to regex patterns list. | ||
* | ||
* @param wildcardStrings The wildcard strings | ||
* @return A list of regex patterns | ||
*/ | ||
public static List<String> wildcardStringsToRegexPatterns(List<String> wildcardStrings) { | ||
return wildcardStrings.stream() | ||
.map(wildcardString -> "^" + wildcardString | ||
.replace(".", "\\.") | ||
.replace("*", ".*") | ||
.replace("?", ".") | ||
.replaceAll("^$", ".*") + "$") | ||
.toList(); | ||
} | ||
|
||
/** | ||
* Check if a string matches any pattern of a given list. | ||
* | ||
* @param resourceName The string | ||
* @param regexPatterns The regex patterns | ||
* @return true if any regex pattern matches the resourceName, false otherwise | ||
*/ | ||
public static boolean filterByPattern(String resourceName, List<String> regexPatterns) { | ||
return regexPatterns.stream() | ||
.anyMatch(pattern -> Pattern.compile(pattern).matcher(resourceName).matches()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.