/** * Configure path prefixes to apply to controller methods. * <p>Prefixes are used to enrich the mappings of every {@code @RequestMapping} * method whose controller type is matched by a corresponding * {@code Predicate} in the map. The prefix for the first matching predicate * is used, assuming the input map has predictable order. * <p>Consider using {@link org.springframework.web.method.HandlerTypePredicate * HandlerTypePredicate} to group controllers. * @param prefixes a map with path prefixes as key * @since 5.1 * @see org.springframework.web.method.HandlerTypePredicate */ public void setPathPrefixes(Map<String, Predicate<Class<?>>> prefixes) { this.pathPrefixes.clear(); prefixes.entrySet().stream() .filter(entry -> StringUtils.hasText(entry.getKey())) .forEach(entry -> this.pathPrefixes.put(entry.getKey(), entry.getValue())); }
/** * Provide the TaskScheduler to use for SockJS endpoints for which a task * scheduler has not been explicitly registered. This method must be called * prior to {@link #getHandlerMapping()}. */ protected void setTaskScheduler(TaskScheduler scheduler) { this.registrations.stream() .map(ServletWebSocketHandlerRegistration::getSockJsServiceRegistration) .filter(Objects::nonNull) .filter(r -> r.getTaskScheduler() == null) .forEach(registration -> registration.setTaskScheduler(scheduler)); }
private static void validatePropertySet(SetRequest request, @Nullable PropertyDefinition definition) { checkRequest(definition != null, "Setting '%s' is undefined", request.getKey()); checkRequest(PropertyType.PROPERTY_SET.equals(definition.type()), "Parameter '%s' is used for setting of property set type only", PARAM_FIELD_VALUES); Set<String> fieldKeys = definition.fields().stream().map(PropertyFieldDefinition::key).collect(Collectors.toSet()); ListMultimap<String, String> valuesByFieldKeys = ArrayListMultimap.create(fieldKeys.size(), request.getFieldValues().size() * fieldKeys.size()); request.getFieldValues().stream() .map(oneFieldValues -> readOneFieldValues(oneFieldValues, request.getKey())) .peek(map -> checkRequest(map.values().stream().anyMatch(StringUtils::isNotBlank), MSG_NO_EMPTY_VALUE)) .flatMap(map -> map.entrySet().stream()) .peek(entry -> valuesByFieldKeys.put(entry.getKey(), entry.getValue())) .forEach(entry -> checkRequest(fieldKeys.contains(entry.getKey()), "Unknown field key '%s' for setting '%s'", entry.getKey(), request.getKey())); checkFieldType(request, definition, valuesByFieldKeys); }
private void parseFileIntoList(List<String> lines, Set<String> whitelist, Set<String> blacklist){ lines.stream() .filter(line -> !line.matches("#.*|\\s*")) .forEach(line -> { if (line.startsWith("!")) { String withoutExclamation = line.substring(1); if (!withoutExclamation.isEmpty()) { blacklist.add(withoutExclamation); } } else { whitelist.add(line); } }); }
private List<Symbol> getPushedDownGroupingSet(AggregationNode aggregation, Set<Symbol> availableSymbols, Set<Symbol> requiredJoinSymbols) { List<Symbol> groupingSet = aggregation.getGroupingKeys(); // keep symbols that are directly from the join's child (availableSymbols) List<Symbol> pushedDownGroupingSet = groupingSet.stream() .filter(availableSymbols::contains) .collect(Collectors.toList()); // add missing required join symbols to grouping set Set<Symbol> existingSymbols = new HashSet<>(pushedDownGroupingSet); requiredJoinSymbols.stream() .filter(existingSymbols::add) .forEach(pushedDownGroupingSet::add); return pushedDownGroupingSet; }
@Override public void upgrade() { this.indexSetService.findAll() .stream() .map(mongoIndexSetFactory::create) .flatMap(indexSet -> getReopenedIndices(indexSet).stream()) .map(indexName -> { LOG.debug("Marking index {} to be reopened using alias.", indexName); return indexName; }) .forEach(indices::markIndexReopened); }
/** * Create a new {@link MockMultipartHttpServletRequest} based on the * supplied {@code ServletContext} and the {@code MockMultipartFiles} * added to this builder. */ @Override protected final MockHttpServletRequest createServletRequest(ServletContext servletContext) { MockMultipartHttpServletRequest request = new MockMultipartHttpServletRequest(servletContext); this.files.stream().forEach(request::addFile); this.parts.values().stream().flatMap(Collection::stream).forEach(request::addPart); if (!this.parts.isEmpty()) { new StandardMultipartHttpServletRequest(request) .getMultiFileMap().values().stream().flatMap(Collection::stream) .forEach(request::addFile); } return request; }
public void setCookies(@Nullable Cookie... cookies) { this.cookies = (ObjectUtils.isEmpty(cookies) ? null : cookies); this.headers.remove(HttpHeaders.COOKIE); if (this.cookies != null) { Arrays.stream(this.cookies) .map(c -> c.getName() + '=' + (c.getValue() == null ? "" : c.getValue())) .forEach(value -> doAddHeaderValue(HttpHeaders.COOKIE, value, false)); } }
@Nullable private Collection<CacheOperation> parseCacheAnnotations( DefaultCacheConfig cachingConfig, AnnotatedElement ae, boolean localOnly) { Collection<? extends Annotation> anns = (localOnly ? AnnotatedElementUtils.getAllMergedAnnotations(ae, CACHE_OPERATION_ANNOTATIONS) : AnnotatedElementUtils.findAllMergedAnnotations(ae, CACHE_OPERATION_ANNOTATIONS)); if (anns.isEmpty()) { return null; } final Collection<CacheOperation> ops = new ArrayList<>(1); anns.stream().filter(ann -> ann instanceof Cacheable).forEach( ann -> ops.add(parseCacheableAnnotation(ae, cachingConfig, (Cacheable) ann))); anns.stream().filter(ann -> ann instanceof CacheEvict).forEach( ann -> ops.add(parseEvictAnnotation(ae, cachingConfig, (CacheEvict) ann))); anns.stream().filter(ann -> ann instanceof CachePut).forEach( ann -> ops.add(parsePutAnnotation(ae, cachingConfig, (CachePut) ann))); anns.stream().filter(ann -> ann instanceof Caching).forEach( ann -> parseCachingAnnotation(ae, cachingConfig, (Caching) ann, ops)); return ops; }
public SortedMap<String, Double> getWeightVector() { SortedMap<String, Double> m = new TreeMap<>((f1, f2) -> { double weightDifference = Math.abs(weights.getCount(f2)) - Math.abs(weights.getCount(f1)); return weightDifference == 0 ? f1.compareTo(f2) : (int) Math.signum(weightDifference); }); weights.entrySet().stream().forEach(e -> m.put(e.getKey(), e.getValue())); return m; }
@Override public List<UserInfo> findByUserIds(List<String> userIds) { if (CollectionUtils.isEmpty(userIds)) { return null; } else { ContainerCriteria criteria = query().where(loginIdAttrName).is(userIds.get(0)); userIds.stream().skip(1).forEach(userId -> criteria.or(loginIdAttrName).is(userId)); return ldapTemplate.search(ldapQueryCriteria().and(criteria), ldapUserInfoMapper); } }
public void setEnableAllChecksAsWarnings(boolean enableAllChecksAsWarnings) { // Checks manually disabled before this flag are reset to warning-level severityMap.entrySet().stream() .filter(e -> e.getValue() == Severity.OFF) .forEach(e -> e.setValue(Severity.WARN)); this.enableAllChecksAsWarnings = enableAllChecksAsWarnings; }
public static <T> void registerQuerySuppiler(Class<T> type, Function<T, Query<T, QueryParamEntity>> querySupplier) { validatorCache.computeIfAbsent(type, instrance::createValidator) .values() .stream() .filter(DefaultValidator.class::isInstance) .map(DefaultValidator.class::cast) .forEach(validator -> validator.querySupplier = querySupplier); }