From ead9cb2c77b8b06cb045d245d4197f6a1a507301 Mon Sep 17 00:00:00 2001 From: Igor Artamonov Date: Thu, 5 Sep 2019 00:31:10 -0400 Subject: [PATCH] solution: debug utility to extract method from matcher --- .../io/emeraldpay/dshackle/upstream/Selector.kt | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/src/main/kotlin/io/emeraldpay/dshackle/upstream/Selector.kt b/src/main/kotlin/io/emeraldpay/dshackle/upstream/Selector.kt index 76170fbe..3e7ebee0 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/upstream/Selector.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/upstream/Selector.kt @@ -59,7 +59,18 @@ class Selector { return matcher } if (matcher is MultiMatcher) { - return matcher.getLabelMatcher() + return matcher.getMatcher(LabelSelectorMatcher::class.java) + } + return null + } + + @JvmStatic + fun extractMethod(matcher: Matcher): MethodMatcher? { + if (matcher is MethodMatcher) { + return matcher + } + if (matcher is MultiMatcher) { + return matcher.getMatcher(MethodMatcher::class.java) } return null } @@ -94,8 +105,8 @@ class Selector { return matchers.all { it.matches(up) } } - fun getLabelMatcher(): LabelSelectorMatcher? { - return matchers.find { it is LabelSelectorMatcher } as LabelSelectorMatcher? + fun getMatcher(type: Class): T? { + return matchers.find { type.isAssignableFrom(it.javaClass) } as T? } }