|
@@ -1,7 +1,17 @@
|
|
|
package com.caimei.www;
|
|
|
|
|
|
+import lombok.Data;
|
|
|
import org.junit.jupiter.api.Test;
|
|
|
import org.springframework.boot.test.context.SpringBootTest;
|
|
|
+import reactor.core.publisher.Flux;
|
|
|
+
|
|
|
+import java.time.Duration;
|
|
|
+import java.time.temporal.ChronoUnit;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.Arrays;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Random;
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
@SpringBootTest
|
|
|
class WwwApplicationTests {
|
|
@@ -10,4 +20,82 @@ class WwwApplicationTests {
|
|
|
void contextLoads() {
|
|
|
}
|
|
|
|
|
|
+ @Test
|
|
|
+ void test1() {
|
|
|
+
|
|
|
+// Flux.just("Hello", "World").subscribe(System.out::println);
|
|
|
+// Flux.fromArray(new Integer[] {1, 2, 3}).subscribe(System.out::println);
|
|
|
+// Flux.empty().subscribe(System.out::println);
|
|
|
+// Flux.range(1, 10).subscribe(System.out::println);
|
|
|
+// Flux.interval(Duration.of(10, ChronoUnit.SECONDS)).subscribe(System.out::println);
|
|
|
+
|
|
|
+ Flux.generate(sink -> {
|
|
|
+ sink.next("Hello");
|
|
|
+ sink.complete();
|
|
|
+ }).subscribe(System.out::println);
|
|
|
+
|
|
|
+
|
|
|
+// final Random random = new Random();
|
|
|
+// Flux.generate(ArrayList::new, (list, sink) -> {
|
|
|
+// int value = random.nextInt(100);
|
|
|
+// list.add(value);
|
|
|
+// sink.next(value);
|
|
|
+// if (list.size() == 10) {
|
|
|
+// sink.complete();
|
|
|
+// }
|
|
|
+// return list;
|
|
|
+// }).subscribe(System.out::println);
|
|
|
+//
|
|
|
+// Flux.create(sink -> {
|
|
|
+// for (int i = 0; i < 10; i++) {
|
|
|
+// sink.next(i);
|
|
|
+// }
|
|
|
+// sink.complete();
|
|
|
+// }).subscribe(System.out::println);
|
|
|
+
|
|
|
+// Flux.range(1, 100).buffer(20).subscribe(System.out::println);
|
|
|
+// Flux.range(1, 10).bufferUntil(i -> i % 2 == 0).subscribe(System.out::println);
|
|
|
+// Flux.range(1, 10).bufferWhile(i -> i % 2 == 0).subscribe(System.out::println);
|
|
|
+
|
|
|
+
|
|
|
+ List<String> list = Arrays.asList("item1", "item2");
|
|
|
+ list.forEach(System.out::println);
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ @Test
|
|
|
+ void test2(){
|
|
|
+ List<String> strs = Arrays.asList("1","4","3","2");
|
|
|
+ // strs.sort((s1,s2) -> s1.compareTo(s2));
|
|
|
+ strs.sort(String::compareTo);
|
|
|
+ strs.forEach(System.out::println);
|
|
|
+ }
|
|
|
+ @Data
|
|
|
+ private static class Student{
|
|
|
+ private String name;
|
|
|
+ private int age;
|
|
|
+ public Student(String name, int age) {
|
|
|
+ this.name = name;
|
|
|
+ this.age = age;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Test
|
|
|
+ void test3(){
|
|
|
+ List<Student> students = new ArrayList<>(3);
|
|
|
+ students.add(new Student("路飞", 22));
|
|
|
+ students.add(new Student("红发", 40));
|
|
|
+ students.add(new Student("白胡子", 50));
|
|
|
+
|
|
|
+ List<Student> list = students.stream()
|
|
|
+ .filter(stu -> stu.getAge() < 50)
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ System.out.println(list);
|
|
|
+
|
|
|
+
|
|
|
+ List<String> names = students.stream().map(Student::getName)
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ System.out.println(names);
|
|
|
+ }
|
|
|
+
|
|
|
}
|