From 320d6a28b60873c8e8163b27ed1389978aed4ee6 Mon Sep 17 00:00:00 2001 From: Luck Date: Sun, 4 Nov 2018 01:05:41 +0000 Subject: some misc refactoring --- .../java/me/lucko/spark/sampler/ThreadGrouper.java | 19 +++++-------------- 1 file changed, 5 insertions(+), 14 deletions(-) (limited to 'spark-common/src/main/java/me/lucko/spark/sampler/ThreadGrouper.java') diff --git a/spark-common/src/main/java/me/lucko/spark/sampler/ThreadGrouper.java b/spark-common/src/main/java/me/lucko/spark/sampler/ThreadGrouper.java index 0707df6..72cd4dc 100644 --- a/spark-common/src/main/java/me/lucko/spark/sampler/ThreadGrouper.java +++ b/spark-common/src/main/java/me/lucko/spark/sampler/ThreadGrouper.java @@ -40,33 +40,24 @@ public interface ThreadGrouper { /** * Implementation of {@link ThreadGrouper} that just groups by thread name. */ - ThreadGrouper BY_NAME = new ByName(); - - final class ByName implements ThreadGrouper { - @Override - public String getGroup(String threadName) { - return threadName; - } - } + ThreadGrouper BY_NAME = threadName -> threadName; /** * Implementation of {@link ThreadGrouper} that attempts to group by the name of the pool * the thread originated from. */ - ThreadGrouper BY_POOL = new ByPool(); - - final class ByPool implements ThreadGrouper { - private static final Pattern THREAD_POOL_PATTERN = Pattern.compile("^(.*)[-#] ?\\d+$"); + ThreadGrouper BY_POOL = new ThreadGrouper() { + private final Pattern pattern = Pattern.compile("^(.*)[-#] ?\\d+$"); @Override public String getGroup(String threadName) { - Matcher matcher = THREAD_POOL_PATTERN.matcher(threadName); + Matcher matcher = this.pattern.matcher(threadName); if (!matcher.matches()) { return threadName; } return matcher.group(1).trim() + " (Combined)"; } - } + }; } -- cgit