TreeBasedPolicyEnforcer implements Enforcer { public static TreeBasedPolicyEnforcer createInstance(final Policy policy) { checkNotNull(policy, "policy"); final Map<String, PolicyTreeNode> tree = new HashMap<>(); final Set<PolicyEntry> policyEntries = policy.getEntriesSet(); policyEntries.forEach(policyEntry -> { final Subjects subjects = policyEntry.getSubjects(); subjects.forEach(subject -> { final SubjectId subjectId = subject.getId(); final String subjectIdString = subjectId.toString(); final PolicyTreeNode parentNode = tree.computeIfAbsent(subjectIdString, SubjectNode::of); final Resources resources = policyEntry.getResources(); resources.forEach(resource -> { final PolicyTreeNode rootChild = parentNode.computeIfAbsent(resource.getType(), t -> { final Set<String> emptySet = Collections.emptySet(); return ResourceNode.of(parentNode, t, EffectedPermissions.newInstance(emptySet, emptySet)); }); addResourceSubTree((ResourceNode) rootChild, resource, resource.getPath()); }); }); }); return new TreeBasedPolicyEnforcer(tree); } private  TreeBasedPolicyEnforcer(final Map<String, PolicyTreeNode> tree); static TreeBasedPolicyEnforcer createInstance(final Policy policy); @Override boolean hasUnrestrictedPermissions(final ResourceKey resourceKey,
            final AuthorizationContext authorizationContext, final Permissions permissions); @Override EffectedSubjectIds getSubjectIdsWithPermission(final ResourceKey resourceKey,
            final Permissions permissions); @Override EffectedSubjects getSubjectsWithPermission(final ResourceKey resourceKey, final Permissions permissions); @Override Set<String> getSubjectIdsWithPartialPermission(final ResourceKey resourceKey,
            final Permissions permissions); @Override Set<AuthorizationSubject> getSubjectsWithPartialPermission(final ResourceKey resourceKey,
            final Permissions permissions); @Override boolean hasPartialPermissions(final ResourceKey resourceKey, final AuthorizationContext authorizationContext,
            final Permissions permissions); @Override JsonObject buildJsonView(
            final ResourceKey resourceKey,
            final Iterable<JsonField> jsonFields,
            final AuthorizationContext authorizationContext,
            final Permissions permissions); @Override String toString();  }
@Test public void tryToCreateInstanceWithNullPolicy() { assertThatExceptionOfType(NullPointerException.class) .isThrownBy(() -> TreeBasedPolicyEnforcer.createInstance(null)) .withMessage("The %s must not be null!", "policy") .withNoCause(); }