Optimize logic

This commit is contained in:
psn 2024-04-15 19:11:24 +08:00
parent b0518db532
commit f9e520dc54
1 changed files with 9 additions and 8 deletions

View File

@ -5,11 +5,13 @@ import java.util.Date;
import java.util.regex.Pattern;
public class StackTraceRule {
private static final Pattern PACKAGE_NAME_PATTERN = Pattern.compile("\\A\\p{ASCII}*\\z");
public static boolean check() {
RuntimeException e = new RuntimeException();
Pattern pattern = Pattern.compile("\\A\\p{ASCII}*\\z");
for (StackTraceElement stackTraceElement : e.getStackTrace()) {
if (!pattern.matcher(stackTraceElement.getMethodName()).matches()) {
StackTraceElement[] stackTrace = Thread.currentThread().getStackTrace();
for (StackTraceElement stackTraceElement : stackTrace) {
if (!PACKAGE_NAME_PATTERN.matcher(stackTraceElement.getMethodName()).matches()) {
return true;
}
}
@ -17,10 +19,9 @@ public class StackTraceRule {
}
public static Date hook() {
RuntimeException e = new RuntimeException();
Pattern pattern = Pattern.compile("\\A\\p{ASCII}*\\z");
for (StackTraceElement stackTraceElement : e.getStackTrace()) {
if (!pattern.matcher(stackTraceElement.getMethodName()).matches()) {
StackTraceElement[] stackTrace = Thread.currentThread().getStackTrace();
for (StackTraceElement stackTraceElement : stackTrace) {
if (!PACKAGE_NAME_PATTERN.matcher(stackTraceElement.getMethodName()).matches()) {
Calendar calendar = Calendar.getInstance();
calendar.add(Calendar.DAY_OF_MONTH, 180);
return calendar.getTime();