-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #21 from Rylern/main
Small refactoring
- Loading branch information
Showing
8 changed files
with
151 additions
and
125 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
34 changes: 34 additions & 0 deletions
34
src/main/java/io/github/qupath/logviewer/LogMessagePredicates.java
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,34 @@ | ||
package io.github.qupath.logviewer; | ||
|
||
import java.util.regex.Pattern; | ||
import java.util.function.Predicate; | ||
import java.util.regex.PatternSyntaxException; | ||
|
||
public class LogMessagePredicates { | ||
public static Predicate<LogMessage> createPredicateFromRegex(String regex) { | ||
if (regex == null || regex.isEmpty()) | ||
return logMessage -> true; | ||
|
||
try { | ||
Pattern pattern = Pattern.compile(regex); | ||
return logMessage -> pattern.matcher(logMessage.message()).find(); | ||
} catch (PatternSyntaxException e) { | ||
return logMessage -> false; | ||
} | ||
} | ||
|
||
public static Predicate<LogMessage> createPredicateContains(String text) { | ||
if (text == null || text.isEmpty()) | ||
return logMessage -> true; | ||
|
||
return logMessage -> logMessage.message().contains(text); | ||
} | ||
|
||
public static Predicate<LogMessage> createPredicateContainsIgnoreCase(String text) { | ||
if (text == null || text.isEmpty()) | ||
return logMessage -> true; | ||
|
||
String textLower = text.toLowerCase(); | ||
return logMessage -> logMessage.message().toLowerCase().contains(textLower); | ||
} | ||
} |
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.