/** * Return method model for the given method on consumer side * * @param method method object * @return method model */ public ConsumerMethodModel getMethodModel(String method) { Optional<Map.Entry<Method, ConsumerMethodModel>> consumerMethodModelEntry = methodModels.entrySet().stream().filter(entry -> entry.getKey().getName().equals(method)).findFirst(); return consumerMethodModelEntry.map(Map.Entry::getValue).orElse(null); }
@SuppressWarnings("unchecked") @Override public Optional<? extends ExecutableMethod<?, ?>> findFirst() { return Stream.of(functions, suppliers, consumers, biFunctions) .map(all -> { Collection<ExecutableMethod<?, ?>> values = all.values(); return values.stream().findFirst(); }).filter(Optional::isPresent) .map(Optional::get) .findFirst(); }
/** * Returns the topmost interface that extends Remote for a given * class - if one exists. * @param testClass the class to be tested * @return the topmost interface that extends Remote, or null if there * is none. */ public Class<?> getRemoteInterface(Class<?> testClass) { return Stream.of(testClass.getInterfaces()) .filter(Remote.class::isAssignableFrom).findFirst().orElse(null); }
private static <T> HttpMessageWriter<T> findWriter( BodyInserter.Context context, ResolvableType elementType, @Nullable MediaType mediaType) { return context.messageWriters().stream() .filter(messageWriter -> messageWriter.canWrite(elementType, mediaType)) .findFirst() .map(BodyInserters::<T>cast) .orElseThrow(() -> new IllegalStateException( "No HttpMessageWriter for \"" + mediaType + "\" and \"" + elementType + "\"")); }
private void migrateGlobalWebhooks(Context context, Collection<PropertyRow> rows) throws SQLException { Multimap<String, PropertyRow> rowsByPropertyKey = rows.stream() .collect(MoreCollectors.index(PropertyRow::getPropertyKey)); Optional<PropertyRow> rootProperty = rowsByPropertyKey.get("sonar.webhooks.global").stream().findFirst(); if (rootProperty.isPresent()) { PropertyRow row = rootProperty.get(); // can't lambda due to checked exception. for (Webhook webhook : extractGlobalWebhooksFrom(context, rowsByPropertyKey, row.value().split(","))) { insert(context, webhook); } } }
/** * Return the first {@link Locale} of the content languages, * as specified by the {@literal Content-Language} header. * <p>Returns {@code null} when the content language is unknown. * <p>Use {@code getValuesAsList(CONTENT_LANGUAGE)} if you need * to get multiple content languages.</p> * @since 5.0 */ @Nullable public Locale getContentLanguage() { return getValuesAsList(CONTENT_LANGUAGE) .stream() .findFirst() .map(Locale::forLanguageTag) .orElse(null); }
/** * Determine a media type for the given file name, if possible. * @param filename the file name plus extension * @return the corresponding media type, or {@code null} if none found */ public static Optional<MediaType> getMediaType(@Nullable String filename) { return getMediaTypes(filename).stream().findFirst(); }
@Override public Mono<Void> handle(ServerHttpRequest request, ServerHttpResponse response) { // Remove underlying context path first (e.g. Servlet container) String path = request.getPath().pathWithinApplication().value(); return this.handlerMap.entrySet().stream() .filter(entry -> path.startsWith(entry.getKey())) .findFirst() .map(entry -> { String contextPath = request.getPath().contextPath().value() + entry.getKey(); ServerHttpRequest newRequest = request.mutate().contextPath(contextPath).build(); return entry.getValue().handle(newRequest, response); }) .orElseGet(() -> { response.setStatusCode(HttpStatus.NOT_FOUND); return response.setComplete(); }); }
private String guessResponseType(String path, String action) { return guessResponseOuterClassName(path).flatMap( potentialClassName -> guessResponseInnerClassName(action).flatMap(potentialInnerClassName -> { try { String guess = "org.sonarqube.ws." + potentialClassName + "$" + potentialInnerClassName; Helper.class.forName(guess); return Stream.of(guess.replaceFirst("\\$", ".")); } catch (ClassNotFoundException e) { } return Stream.empty(); })).findFirst().orElseGet(() -> { return "String"; }); }
private static <T> HttpMessageReader<T> findReader( ResolvableType elementType, MediaType mediaType, BodyExtractor.Context context) { return context.messageReaders().stream() .filter(messageReader -> messageReader.canRead(elementType, mediaType)) .findFirst() .map(BodyExtractors::<T>cast) .orElseThrow(() -> new IllegalStateException( "No HttpMessageReader for \"" + mediaType + "\" and \"" + elementType + "\"")); }
/** * Return method model for the given method on consumer side * * @param method method object * @return method model */ public ConsumerMethodModel getMethodModel(String method) { Optional<Map.Entry<Method, ConsumerMethodModel>> consumerMethodModelEntry = methodModels.entrySet().stream().filter(entry -> entry.getKey().getName().equals(method)).findFirst(); return consumerMethodModelEntry.map(Map.Entry::getValue).orElse(null); }