/** * Determine the media types for the given file name, if possible. * @param filename the file name plus extension * @return the corresponding media types, or an empty list if none found */ public static List<MediaType> getMediaTypes(@Nullable String filename) { return Optional.ofNullable(StringUtils.getFilenameExtension(filename)) .map(s -> s.toLowerCase(Locale.ENGLISH)) .map(fileExtensionToMediaTypes::get) .orElse(Collections.emptyList()); }
private static <T, S extends Publisher<T>> S readWithMessageReaders( ReactiveHttpInputMessage message, BodyExtractor.Context context, ResolvableType elementType, Function<HttpMessageReader<T>, S> readerFunction, Function<UnsupportedMediaTypeException, S> errorFunction, Supplier<S> emptySupplier) { if (VOID_TYPE.equals(elementType)) { return emptySupplier.get(); } MediaType contentType = Optional.ofNullable(message.getHeaders().getContentType()) .orElse(MediaType.APPLICATION_OCTET_STREAM); return context.messageReaders().stream() .filter(reader -> reader.canRead(elementType, contentType)) .findFirst() .map(BodyExtractors::<T>cast) .map(readerFunction) .orElseGet(() -> { List<MediaType> mediaTypes = context.messageReaders().stream() .flatMap(reader -> reader.getReadableMediaTypes().stream()) .collect(Collectors.toList()); return errorFunction.apply( new UnsupportedMediaTypeException(contentType, mediaTypes, elementType)); }); }
@Override public synchronized void notify(List<URL> urls) { List<URL> categoryUrls = urls.stream() .filter(this::isValidCategory) .filter(this::isNotCompatibleFor26x) .collect(Collectors.toList()); /** * TODO Try to refactor the processing of these three type of urls using Collectors.groupBy()? */ this.configurators = Configurator.toConfigurators(classifyUrls(categoryUrls, UrlUtils::isConfigurator)) .orElse(configurators); toRouters(classifyUrls(categoryUrls, UrlUtils::isRoute)).ifPresent(this::addRouters); // providers refreshOverrideAndInvoker(classifyUrls(categoryUrls, UrlUtils::isProvider)); }
public Type[] getRelationCoercion(Relation relation) { return Optional.ofNullable(relationCoercions.get(NodeRef.of(relation))) .map(types -> types.stream().toArray(Type[]::new)) .orElse(null); }
@Override public WebClient build() { ExchangeFunction exchange = initExchangeFunction(); ExchangeFunction filteredExchange = (this.filters != null ? this.filters.stream() .reduce(ExchangeFilterFunction::andThen) .map(filter -> filter.apply(exchange)) .orElse(exchange) : exchange); return new DefaultWebClient(filteredExchange, initUriBuilderFactory(), this.defaultHeaders != null ? unmodifiableCopy(this.defaultHeaders) : null, this.defaultCookies != null ? unmodifiableCopy(this.defaultCookies) : null, this.defaultRequest, new DefaultWebClientBuilder(this)); }
private void validatePullRequestParamsWhenPluginAbsent(List<String> validationMessages) { Stream.of(PULL_REQUEST_KEY, PULL_REQUEST_BRANCH, PULL_REQUEST_BASE) .filter(param -> nonNull(settings.get(param).orElse(null))) .forEach(param -> validationMessages.add(format("To use the property \"%s\", the branch plugin is required but not installed. " + "See the documentation of branch support: %s.", param, BRANCHES_DOC_LINK))); }
public List<GroupingOperation> getGroupingOperations(QuerySpecification querySpecification) { return Optional.ofNullable(groupingOperations.get(NodeRef.of(querySpecification))) .orElse(emptyList()); }
public Resource[] resolveMapperLocations() { return Stream.of(Optional.ofNullable(this.mapperLocations).orElse(new String[0])) .flatMap(location -> Stream.of(getResources(location))) .toArray(Resource[]::new); }
@Override public Result apply(SemiJoinNode semiJoinNode, Captures captures, Context context) { Set<Symbol> requiredFilteringSourceInputs = Streams.concat( Stream.of(semiJoinNode.getFilteringSourceJoinSymbol()), semiJoinNode.getFilteringSourceHashSymbol().map(Stream::of).orElse(Stream.empty())) .collect(toImmutableSet()); return restrictOutputs(context.getIdAllocator(), semiJoinNode.getFilteringSource(), requiredFilteringSourceInputs) .map(newFilteringSource -> semiJoinNode.replaceChildren(ImmutableList.of(semiJoinNode.getSource(), newFilteringSource))) .map(Result::ofPlanNode) .orElse(Result.empty()); } }
/** * register route to container */ public void register() { routes.values().forEach(route -> logAddRoute(log, route)); hooks.values().stream().flatMap(Collection::stream).forEach(route -> logAddRoute(log, route)); Stream.of(routes.values(), hooks.values().stream().findAny().orElse(new ArrayList<>())) .flatMap(Collection::stream).forEach(this::registerRoute); regexMapping.register(); webSockets.keySet().forEach(path -> logWebSocket(log, path)); }
private Charset getCharset() { return Optional.ofNullable(this.headers.getContentType()) .map(MimeType::getCharset).orElse(StandardCharsets.UTF_8); }
public boolean putCreatorId(OwnCreatedDataAccessConfig access, AuthorizingContext context) { RecordCreationEntity entity = context.getParamContext().getParams() .values().stream() .filter(RecordCreationEntity.class::isInstance) .map(RecordCreationEntity.class::cast) .findAny().orElse(null); if (entity != null) { entity.setCreatorId(context.getAuthentication().getUser().getId()); } else { logger.warn("try put creatorId property,but not found any RecordCreationEntity!"); } return true; }
@Override public synchronized void notify(List<URL> urls) { List<URL> categoryUrls = urls.stream() .filter(this::isValidCategory) .filter(this::isNotCompatibleFor26x) .collect(Collectors.toList()); /** * TODO Try to refactor the processing of these three type of urls using Collectors.groupBy()? */ this.configurators = Configurator.toConfigurators(classifyUrls(categoryUrls, UrlUtils::isConfigurator)) .orElse(configurators); toRouters(classifyUrls(categoryUrls, UrlUtils::isRoute)).ifPresent(this::addRouters); // providers refreshOverrideAndInvoker(classifyUrls(categoryUrls, UrlUtils::isProvider)); }
/** * A shortcut for creating a {@code ResponseEntity} with the given body * and the {@linkplain HttpStatus#OK OK} status, or an empty body and a * {@linkplain HttpStatus#NOT_FOUND NOT FOUND} status in case of a * {@linkplain Optional#empty()} parameter. * @return the created {@code ResponseEntity} * @since 5.1 */ public static <T> ResponseEntity<T> of(Optional<T> body) { Assert.notNull(body, "Body must not be null"); return body.map(ResponseEntity::ok).orElse(notFound().build()); }
public static String fromResource(AbstractFileResolvingResource resource) { String filename = Optional.ofNullable(resource.getFilename()).orElse(""); return getMimeType(filename); }