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(); @Override Set<Entry<String, Map<String, Integer>>> entrySet(); @Override Map<String, Integer> put(final String key, final Map<String, Integer> value); @Override boolean equals(final Object o); @Override int hashCode();  }
@Test public void getMaxWeightForAllPermissionsReturnsEmptyOptionalForEmptySubjectsMap() { final Optional<Integer> maxWeightForAllPermissions = underTest.getMaxWeightForAllPermissions(subjectIds, permissions); assertThat(maxWeightForAllPermissions).isEmpty(); }