[BAEL-3392] Formatted code examples for [BAEL-3392]
This commit is contained in:
@@ -1,17 +1,17 @@
|
|||||||
package com.baeldung.streams.debug;
|
package com.baeldung.streams.debug;
|
||||||
|
|
||||||
import org.junit.Test;
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
|
||||||
import java.util.stream.IntStream;
|
import java.util.stream.IntStream;
|
||||||
|
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
import org.junit.Test;
|
||||||
|
|
||||||
public class Example1 {
|
public class Example1 {
|
||||||
@Test
|
@Test
|
||||||
public void whenDebugging_thenInformationIsShown() {
|
public void whenDebugging_thenInformationIsShown() {
|
||||||
int[] listOutputSorted = IntStream.of(-3, 10, -4, 1, 3)
|
int[] listOutputSorted = IntStream.of(-3, 10, -4, 1, 3)
|
||||||
.sorted()
|
.sorted()
|
||||||
.toArray();
|
.toArray();
|
||||||
|
|
||||||
assertThat(listOutputSorted).isSorted();
|
assertThat(listOutputSorted).isSorted();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,35 +1,35 @@
|
|||||||
package com.baeldung.streams.debug;
|
package com.baeldung.streams.debug;
|
||||||
|
|
||||||
import com.baeldung.streams.debug.entity.Customer;
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
import org.junit.Test;
|
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import java.util.stream.Stream;
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import com.baeldung.streams.debug.entity.Customer;
|
||||||
|
|
||||||
public class Example2 {
|
public class Example2 {
|
||||||
@Test
|
@Test
|
||||||
public void whenDebugging_thenInformationIsShown() {
|
public void whenDebugging_thenInformationIsShown() {
|
||||||
List<Optional<Customer>> customers = Arrays.asList(
|
List<Optional<Customer>> customers = Arrays.asList(
|
||||||
Optional.of(new Customer("John P.", 15)),
|
Optional.of(new Customer("John P.", 15)),
|
||||||
Optional.of(new Customer("Sarah M.", 78)),
|
Optional.of(new Customer("Sarah M.", 78)),
|
||||||
Optional.empty(),
|
Optional.empty(),
|
||||||
Optional.of(new Customer("Mary T.", 20)),
|
Optional.of(new Customer("Mary T.", 20)),
|
||||||
Optional.empty(),
|
Optional.empty(),
|
||||||
Optional.of(new Customer("Florian G.", 89)),
|
Optional.of(new Customer("Florian G.", 89)),
|
||||||
Optional.empty());
|
Optional.empty()
|
||||||
|
);
|
||||||
|
|
||||||
long numberOf65PlusCustomers = customers
|
long numberOf65PlusCustomers = customers.stream()
|
||||||
.stream()
|
.flatMap(c -> c.map(Stream::of)
|
||||||
.flatMap(c -> c
|
.orElseGet(Stream::empty))
|
||||||
.map(Stream::of)
|
.mapToInt(Customer::getAge)
|
||||||
.orElseGet(Stream::empty))
|
.filter(c -> c > 65)
|
||||||
.mapToInt(Customer::getAge)
|
.count();
|
||||||
.filter(c -> c > 65)
|
|
||||||
.count();
|
|
||||||
|
|
||||||
assertThat(numberOf65PlusCustomers).isEqualTo(2);
|
assertThat(numberOf65PlusCustomers).isEqualTo(2);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user