class PermissionSubjectsMap extends AbstractMap<String, Map<String, Integer>> {

    Optional<Integer> getMaxWeightForAllPermissions(final Collection<String> subjectIds,
            final Collection<String> permissions) {

        validateSubjectIds(subjectIds);
        validatePermissions(permissions);

        return permissions.stream()
                .flatMap(permission -> {
                    final Map<String, Integer> permittedSubjects = getOrDefault(permission, Collections.emptyMap());
                    return intersect(subjectIds, permittedSubjects.keySet()).map(permittedSubjects::get);
                })
                .max(Comparator.naturalOrder());
    }

      PermissionSubjectsMap();

}