Source:
private TreeMap<ResourcePattern, VersionedAcls> prepareAclCache() { Map<ResourcePattern, Set<AclEntry>> aclEntries = new HashMap<>(); for (int resourceId = 0; resourceId < resourceCount; resourceId++) { ResourcePattern resource = new ResourcePattern( (resourceId % 10 == 0) ? ResourceType.GROUP : ResourceType.TOPIC, "resource-" + resourceId, (resourceId % 5 == 0) ? PatternType.PREFIXED : PatternType.LITERAL); Set<AclEntry> entries = aclEntries.computeIfAbsent(resource, k -> new HashSet<>()); for (int aclId = 0; aclId < aclCount; aclId++) { AccessControlEntry ace = new AccessControlEntry(principal.toString() + aclId, "*", AclOperation.READ, AclPermissionType.ALLOW); entries.add(new AclEntry(ace)); } } ResourcePattern resourceWildcard = new ResourcePattern(ResourceType.TOPIC, ResourcePattern.WILDCARD_RESOURCE, PatternType.LITERAL); ResourcePattern resourcePrefix = new ResourcePattern(ResourceType.TOPIC, "resource-", PatternType.PREFIXED); Set<AclEntry> entriesWildcard = aclEntries.computeIfAbsent(resourceWildcard, k -> new HashSet<>()); Set<AclEntry> entriesPrefix = aclEntries.computeIfAbsent(resourceWildcard, k -> new HashSet<>()); for (int hostId = 0; hostId < hostCount; hostId++) { AccessControlEntry ace = new AccessControlEntry(principal.toString(), "127.0.0." + hostId, AclOperation.READ, AclPermissionType.ALLOW); entriesWildcard.add(new AclEntry(ace)); entriesPrefix.add(new AclEntry(ace)); } TreeMap<ResourcePattern, VersionedAcls> aclCache = new TreeMap<>(new AclAuthorizer.ResourceOrdering()); for (Map.Entry<ResourcePattern, Set<AclEntry>> entry : aclEntries.entrySet()) { aclCache = aclCache.updated(entry.getKey(), new VersionedAcls(JavaConverters.asScalaSetConverter(entry.getValue()).asScala().toSet(), 1)); } return aclCache; }

Target:
private TreeMap<ResourcePattern, VersionedAcls> prepareAclCache() { Map<ResourcePattern, Set<AclEntry>> aclEntries = new HashMap<>(); for (int resourceId = 0; resourceId < resourceCount; resourceId++) { ResourcePattern resource = new ResourcePattern( (resourceId % 10 == 0) ? ResourceType.GROUP : ResourceType.TOPIC, "resource-" + resourceId, (resourceId % 5 == 0) ? PatternType.PREFIXED : PatternType.LITERAL); Set<AclEntry> entries = aclEntries.computeIfAbsent(resource, k -> new HashSet<>()); for (int aclId = 0; aclId < aclCount; aclId++) { AccessControlEntry ace = new AccessControlEntry(principal.toString() + aclId, "*", AclOperation.READ, AclPermissionType.ALLOW); entries.add(new AclEntry(ace)); } } ResourcePattern resourceWildcard = new ResourcePattern(ResourceType.TOPIC, ResourcePattern.WILDCARD_RESOURCE, PatternType.LITERAL); ResourcePattern resourcePrefix = new ResourcePattern(ResourceType.TOPIC, "resource-", PatternType.PREFIXED); Set<AclEntry> entriesWildcard = aclEntries.computeIfAbsent(resourceWildcard, k -> new HashSet<>()); Set<AclEntry> entriesPrefix = aclEntries.computeIfAbsent(resourcePrefix, k -> new HashSet<>()); for (int hostId = 0; hostId < hostPreCount; hostId++) { AccessControlEntry ace = new AccessControlEntry(principal.toString(), "127.0.0." + hostId, AclOperation.READ, AclPermissionType.ALLOW); entriesPrefix.add(new AclEntry(ace)); } for (int hostId = 0; hostId < resourceCount / 10; hostId++) { AccessControlEntry ace = new AccessControlEntry(principal.toString(), "127.0.0." + hostId, AclOperation.READ, AclPermissionType.ALLOW); entriesWildcard.add(new AclEntry(ace)); } TreeMap<ResourcePattern, VersionedAcls> aclCache = new TreeMap<>(new AclAuthorizer.ResourceOrdering()); for (Map.Entry<ResourcePattern, Set<AclEntry>> entry : aclEntries.entrySet()) { aclCache = aclCache.updated(entry.getKey(), new VersionedAcls(JavaConverters.asScalaSetConverter(entry.getValue()).asScala().toSet(), 1)); } return aclCache; }