Tabnine Logo
List.stream
Code IndexAdd Tabnine to your IDE (free)

How to use
stream
method
in
java.util.List

Best Java code snippets using java.util.List.stream (Showing top 20 results out of 79,794)

Refine searchRefine arrow

  • Stream.map
  • Stream.collect
  • Collectors.toList
  • Stream.filter
  • List.size
origin: spring-projects/spring-framework

/**
 * Re-create the given mime types as media types.
 * @since 5.0
 */
public static List<MediaType> asMediaTypes(List<MimeType> mimeTypes) {
  return mimeTypes.stream().map(MediaType::asMediaType).collect(Collectors.toList());
}
origin: spring-projects/spring-framework

/**
 * 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));
}
origin: spring-projects/spring-framework

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 + "\""));
}
origin: spring-projects/spring-framework

@Test
public void convertFromStreamToRawList() throws NoSuchFieldException {
  Stream<Integer> stream = Arrays.asList(1, 2, 3).stream();
  TypeDescriptor listOfStrings = new TypeDescriptor(Types.class.getField("rawList"));
  Object result = this.conversionService.convert(stream, listOfStrings);
  assertNotNull("Converted object must not be null", result);
  assertTrue("Converted object must be a list", result instanceof List);
  @SuppressWarnings("unchecked")
  List<Object> content = (List<Object>) result;
  assertEquals(1, content.get(0));
  assertEquals(2, content.get(1));
  assertEquals(3, content.get(2));
  assertEquals("Wrong number of elements", 3, content.size());
}
origin: eclipse-vertx/vert.x

@Test
public void testEntries() {
 map.set("foo", Arrays.<String>asList("foo_value_1", "foo_value_2"));
 List<Map.Entry<String, String>> entries = map.entries();
 assertEquals(entries.size(), 1);
 assertEquals("foo", entries.get(0).getKey());
 assertEquals("foo_value_1", entries.get(0).getValue());
 map.set("bar", "bar_value");
 Map<String, String> collected = map.entries().stream().collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
 assertEquals("foo_value_1", collected.get("foo"));
 assertEquals("bar_value", collected.get("bar"));
}
origin: spring-projects/spring-framework

/**
 * 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));
}
origin: apache/incubator-dubbo

private <T> List<Invoker<T>> filterInvoker(List<Invoker<T>> invokers, Predicate<Invoker<T>> predicate) {
  return invokers.stream()
      .filter(predicate)
      .collect(Collectors.toList());
}
origin: spring-projects/spring-framework

@Test
public void convertFromStreamToList() throws NoSuchFieldException {
  this.conversionService.addConverter(Number.class, String.class, new ObjectToStringConverter());
  Stream<Integer> stream = Arrays.asList(1, 2, 3).stream();
  TypeDescriptor listOfStrings = new TypeDescriptor(Types.class.getField("listOfStrings"));
  Object result = this.conversionService.convert(stream, listOfStrings);
  assertNotNull("Converted object must not be null", result);
  assertTrue("Converted object must be a list", result instanceof List);
  @SuppressWarnings("unchecked")
  List<String> content = (List<String>) result;
  assertEquals("1", content.get(0));
  assertEquals("2", content.get(1));
  assertEquals("3", content.get(2));
  assertEquals("Wrong number of elements", 3, content.size());
}
origin: spring-projects/spring-framework

private void assertDecoderInstance(Decoder<?> decoder) {
  assertSame(decoder, this.configurer.getReaders().stream()
      .filter(writer -> writer instanceof DecoderHttpMessageReader)
      .map(writer -> ((DecoderHttpMessageReader<?>) writer).getDecoder())
      .filter(e -> decoder.getClass().equals(e.getClass()))
      .findFirst()
      .filter(e -> e == decoder).orElse(null));
}
origin: spring-projects/spring-framework

/**
 * 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));
}
origin: spring-projects/spring-framework

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 + "\""));
}
origin: apache/incubator-dubbo

private <T> List<Invoker<T>> filterInvoker(List<Invoker<T>> invokers, Predicate<Invoker<T>> predicate) {
  return invokers.stream()
      .filter(predicate)
      .collect(Collectors.toList());
}
origin: spring-projects/spring-framework

@Test
public void conditionalConversionForAllTypes() {
  MyConditionalGenericConverter converter = new MyConditionalGenericConverter();
  conversionService.addConverter(converter);
  assertEquals((Integer) 3, conversionService.convert(3, Integer.class));
  assertThat(converter.getSourceTypes().size(), greaterThan(2));
  assertTrue(converter.getSourceTypes().stream().allMatch(td -> Integer.class.equals(td.getType())));
}
origin: spring-projects/spring-framework

private void assertEncoderInstance(Encoder<?> encoder) {
  assertSame(encoder, this.configurer.getWriters().stream()
      .filter(writer -> writer instanceof EncoderHttpMessageWriter)
      .map(writer -> ((EncoderHttpMessageWriter<?>) writer).getEncoder())
      .filter(e -> encoder.getClass().equals(e.getClass()))
      .findFirst()
      .filter(e -> e == encoder).orElse(null));
}
origin: spring-projects/spring-framework

public DefaultExchangeFunction(ClientHttpConnector connector, ExchangeStrategies strategies) {
  Assert.notNull(connector, "ClientHttpConnector must not be null");
  Assert.notNull(strategies, "ExchangeStrategies must not be null");
  this.connector = connector;
  this.strategies = strategies;
  strategies.messageWriters().stream()
      .filter(LoggingCodecSupport.class::isInstance)
      .forEach(reader -> {
        if (((LoggingCodecSupport) reader).isEnableLoggingRequestDetails()) {
          this.enableLoggingRequestDetails = true;
        }
      });
}
origin: spring-projects/spring-framework

/**
 * Return all registered interceptors.
 */
protected List<Object> getInterceptors() {
  return this.registrations.stream()
      .sorted(INTERCEPTOR_ORDER_COMPARATOR)
      .map(InterceptorRegistration::getInterceptor)
      .collect(Collectors.toList());
}
origin: spring-projects/spring-framework

@ParameterizedTest
@ValueSource(strings = { "Dilbert", "Wally" })
void people(String name, @Autowired List<Person> people) {
  assertTrue(people.stream().map(Person::getName).filter(str -> name.equals(str)).findFirst().isPresent());
}
origin: spring-projects/spring-framework

@Override
protected WebExchangeDataBinder initDataBinder(WebExchangeDataBinder dataBinder, ServerWebExchange exchange) {
  this.binderMethods.stream()
      .filter(binderMethod -> {
        InitBinder ann = binderMethod.getMethodAnnotation(InitBinder.class);
        Assert.state(ann != null, "No InitBinder annotation");
        String[] names = ann.value();
        return (ObjectUtils.isEmpty(names) ||
            ObjectUtils.containsElement(names, dataBinder.getObjectName()));
      })
      .forEach(method -> invokeBinderMethod(dataBinder, exchange, method));
  return dataBinder;
}
origin: apache/incubator-dubbo

public static List<URL> classifyUrls(List<URL> urls, Predicate<URL> predicate) {
  return urls.stream().filter(predicate).collect(Collectors.toList());
}
origin: spring-projects/spring-framework

@Test
public void jackson2EncoderOverride() {
  Jackson2JsonEncoder encoder = new Jackson2JsonEncoder();
  this.configurer.defaultCodecs().jackson2JsonEncoder(encoder);
  assertSame(encoder, this.configurer.getWriters().stream()
      .filter(writer -> ServerSentEventHttpMessageWriter.class.equals(writer.getClass()))
      .map(writer -> (ServerSentEventHttpMessageWriter) writer)
      .findFirst()
      .map(ServerSentEventHttpMessageWriter::getEncoder)
      .filter(e -> e == encoder).orElse(null));
}
java.utilListstream

Popular methods of List

  • add
  • size
    Returns the number of elements in this List.
  • get
    Returns the element at the specified location in this List.
  • isEmpty
    Returns whether this List contains no elements.
  • addAll
  • toArray
    Returns an array containing all elements contained in this List. If the specified array is large eno
  • contains
    Tests whether this List contains the specified object.
  • remove
    Removes the first occurrence of the specified object from this List.
  • iterator
    Returns an iterator on the elements of this List. The elements are iterated in the same order as the
  • clear
  • forEach
  • set
    Replaces the element at the specified position in this list with the specified element (optional ope
  • forEach,
  • set,
  • subList,
  • indexOf,
  • equals,
  • hashCode,
  • removeAll,
  • listIterator,
  • sort

Popular in Java

  • Making http requests using okhttp
  • scheduleAtFixedRate (Timer)
  • startActivity (Activity)
  • getApplicationContext (Context)
  • SecureRandom (java.security)
    This class generates cryptographically secure pseudo-random numbers. It is best to invoke SecureRand
  • Timestamp (java.sql)
    A Java representation of the SQL TIMESTAMP type. It provides the capability of representing the SQL
  • LinkedHashMap (java.util)
    LinkedHashMap is an implementation of Map that guarantees iteration order. All optional operations a
  • Locale (java.util)
    Locale represents a language/country/variant combination. Locales are used to alter the presentatio
  • SortedMap (java.util)
    A map that has its keys ordered. The sorting is according to either the natural ordering of its keys
  • SSLHandshakeException (javax.net.ssl)
    The exception that is thrown when a handshake could not be completed successfully.
  • Best IntelliJ plugins
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now