【发布时间】:2021-08-18 22:05:10
【问题描述】:
我正在尝试通过它的componentType来映射这个枚举的所有值。不幸的是,我不知道如何将它与数组映射,尝试使用toImmutableMap (v-> v.componentType, v-> v),但这仅适用于ImmutableMap<String, MatchType>,我需要将其映射为数组(MatchType []),有人能告诉我我该怎么做或者是否有更好的方法?
ImmutableMap<String, MatchType[]> findByComponentType = Arrays.stream(MatchType.values()).collect(toImmutableMap(v -> /** what to put here */));
示例:如果我使用findByComponentType.get("android.support.v4.app.Fragment"),它应该返回 SUPPORT_FRAGMENT 和 SUPPORT_FRAGMENT_PRE_API23。
private enum MatchType {
ACTIVITY(
"android.app.Activity",
"onCreate",
FRAMEWORK_FRAGMENT(
"android.app.Fragment",
"onAttach",
FRAMEWORK_FRAGMENT_PRE_API23(
"android.app.Fragment",
"onAttach",,
SUPPORT_FRAGMENT(
"android.support.v4.app.Fragment",
"onAttach",
SUPPORT_FRAGMENT_PRE_API23(
"android.support.v4.app.Fragment",
"onAttach");
MatchType(String componentType, String lifecycleMethod)
【问题讨论】:
-
你需要
groupingBy -
@BoristheSpider 感谢它的工作