canonical example by Tabnine
private Double calculateAverageGrade(Map<String, List<Integer>> gradesList, String studentName) throws Exception { return Optional.ofNullable(gradesList.get(studentName)) .map(list -> list.stream().collect(Collectors.averagingDouble(x -> x))) .orElseThrow(() -> new Exception("Student not found - " + studentName)); }
canonical example by Tabnine
canonical example by Tabnine
/** * Return declared "producible" types but only among those that also * match the "methods" and "consumes" conditions. */ public Set<MediaType> getProducibleMediaTypes() { return this.partialMatches.stream().filter(PartialMatch::hasConsumesMatch). flatMap(m -> m.getInfo().getProducesCondition().getProducibleMediaTypes().stream()). collect(Collectors.toCollection(LinkedHashSet::new)); }
/** * Get all methods in the supplied {@link Class class} and its superclasses * which are annotated with the supplied {@code annotationType} but * which are not <em>shadowed</em> by methods overridden in subclasses. * <p>Default methods on interfaces are also detected. * @param clazz the class for which to retrieve the annotated methods * @param annotationType the annotation type for which to search * @return all annotated methods in the supplied class and its superclasses * as well as annotated interface default methods */ private List<Method> getAnnotatedMethods(Class<?> clazz, Class<? extends Annotation> annotationType) { return Arrays.stream(ReflectionUtils.getUniqueDeclaredMethods(clazz)) .filter(method -> AnnotatedElementUtils.hasAnnotation(method, annotationType)) .collect(Collectors.toList()); }
private Mono<Map<String, Object>> initAttributes(ServerWebExchange exchange) { if (this.sessionAttributePredicate == null) { return EMPTY_ATTRIBUTES; } return exchange.getSession().map(session -> session.getAttributes().entrySet().stream() .filter(entry -> this.sessionAttributePredicate.test(entry.getKey())) .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue))); }
/** * Return declared "consumable" types but only among those that also * match the "methods" condition. */ public Set<MediaType> getConsumableMediaTypes() { return this.partialMatches.stream().filter(PartialMatch::hasMethodsMatch). flatMap(m -> m.getInfo().getConsumesCondition().getConsumableMediaTypes().stream()). collect(Collectors.toCollection(LinkedHashSet::new)); }
@Nullable private <T> T createSingleBean(Function<WebFluxConfigurer, T> factory, Class<T> beanType) { List<T> result = this.delegates.stream().map(factory).filter(Objects::nonNull).collect(Collectors.toList()); if (result.isEmpty()) { return null; } else if (result.size() == 1) { return result.get(0); } else { throw new IllegalStateException("More than one WebFluxConfigurer implements " + beanType.getSimpleName() + " factory method."); } }
private List<SyncHandlerMethodArgumentResolver> initBinderResolvers( ArgumentResolverConfigurer customResolvers, ReactiveAdapterRegistry reactiveRegistry, ConfigurableApplicationContext context) { return initResolvers(customResolvers, reactiveRegistry, context, false, Collections.emptyList()).stream() .filter(resolver -> resolver instanceof SyncHandlerMethodArgumentResolver) .map(resolver -> (SyncHandlerMethodArgumentResolver) resolver) .collect(Collectors.toList()); }