Skip to content

Commit 9c4cdba

Browse files
committed
fix rx java dep, add part4, progress
1 parent b27d42d commit 9c4cdba

File tree

4 files changed

+126
-6
lines changed

4 files changed

+126
-6
lines changed

dev_projects/RxJava/RxJava/pom.xml

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,23 @@
1919
rxjava
2020
https://mvnrepository.com/artifact/io.reactivex/rxjava
2121
-->
22+
<!-- <dependency>-->
23+
<!-- <groupId>io.reactivex</groupId>-->
24+
<!-- <artifactId>rxjava</artifactId>-->
25+
<!-- <version>1.3.8</version>-->
26+
<!-- </dependency>-->
27+
28+
<!-- https://mvnrepository.com/artifact/com.netflix.rxjava/rxjava-core -->
29+
<dependency>
30+
<groupId>com.netflix.rxjava</groupId>
31+
<artifactId>rxjava-core</artifactId>
32+
<version>0.20.7</version>
33+
</dependency>
34+
2235
<dependency>
23-
<groupId>io.reactivex</groupId>
36+
<groupId>io.reactivex.rxjava3</groupId>
2437
<artifactId>rxjava</artifactId>
25-
<version>1.3.8</version>
38+
<version>3.1.6</version>
2639
</dependency>
2740

2841
</dependencies>

dev_projects/RxJava/RxJava/src/main/java/com/yen/courseV1/part3.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66
import java.util.Scanner;
77
import java.util.concurrent.TimeUnit;
88
import javax.swing.*;
9-
import rx.Completable;
9+
10+
import io.reactivex.rxjava3.core.Completable;
1011
import rx.Observable;
11-
import rx.functions.Action0;
1212

1313
public class part3 {
1414
public static void main(String[] args) {
@@ -36,6 +36,7 @@ public static void main(String[] args) {
3636
System.out.println("5 sec passed " + item);
3737
});
3838

39+
// TODO : FIX BELOW
3940
//Action action2 = () -> System.out.println("hello world!!");
4041
Action action =
4142
new AbstractAction() {
@@ -45,7 +46,7 @@ public void actionPerformed(ActionEvent e) {
4546
}
4647
};
4748

48-
Completable completable = Completable.fromAction((Action0) action);
49+
Completable completable = Completable.fromAction((io.reactivex.rxjava3.functions.Action) action);
4950

5051
completable.subscribe(() -> {
5152
System.out.println("---> Action ends");
Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
package com.yen.courseV1;
2+
3+
// https://youtu.be/EIwAerzQDvA?si=NQNL6Lgl9tc9qsU8
4+
5+
import io.reactivex.rxjava3.annotations.NonNull;
6+
import io.reactivex.rxjava3.core.Maybe;
7+
import io.reactivex.rxjava3.core.MaybeObserver;
8+
import io.reactivex.rxjava3.core.Single;
9+
import io.reactivex.rxjava3.core.SingleObserver;
10+
import io.reactivex.rxjava3.disposables.Disposable;
11+
12+
13+
public class part4 {
14+
public static void main(String[] args) {
15+
16+
/** Example 1 : Single
17+
*
18+
* Single : ONLY emit once and ONLY one item, other situation treated as error
19+
*/
20+
// Single<String>, NOTE how this different from regular Obervable
21+
Single<String> single = createSingle();
22+
single.subscribe(new SingleObserver<String>(){
23+
@Override
24+
public void onSubscribe(@NonNull Disposable d) {
25+
26+
}
27+
28+
@Override
29+
public void onSuccess(@NonNull String s) {
30+
System.out.println("(onSuccess) s = " + s);
31+
}
32+
33+
@Override
34+
public void onError(@NonNull Throwable e) {
35+
System.out.println("(onError) = " + e.getMessage());
36+
}
37+
});
38+
39+
/** Example 2 : Maybe
40+
*
41+
* Maybe : emit one or no item
42+
*/
43+
44+
// Maybe
45+
Maybe<String> maybe = createMaybe();
46+
47+
maybe.subscribe(new MaybeObserver<String>() {
48+
@Override
49+
public void onSubscribe(@NonNull Disposable d) {
50+
51+
}
52+
53+
@Override
54+
public void onSuccess(@NonNull String s) {
55+
System.out.println("(onSuccess) s = " + s);
56+
}
57+
58+
@Override
59+
public void onError(@NonNull Throwable e) {
60+
System.out.println("(onError) = " + e.getMessage());
61+
}
62+
63+
@Override
64+
public void onComplete() {
65+
System.out.println("completed! no new content");
66+
}
67+
});
68+
69+
}
70+
71+
public static Single<String> createSingle(){
72+
return Single.create(emitter -> {
73+
String user = fetchUser();
74+
if (user != null){
75+
emitter.onSuccess(user);
76+
}else{
77+
emitter.onError(new Exception("user not found"));
78+
}
79+
});
80+
}
81+
82+
public static String fetchUser(){
83+
//return "May";
84+
return null;
85+
}
86+
87+
public static Maybe createMaybe(){
88+
return Maybe.create(emitter -> {
89+
String newContent = readFile();
90+
if (newContent != null){
91+
emitter.onSuccess(newContent);
92+
}else{
93+
emitter.onComplete();
94+
}
95+
});
96+
}
97+
98+
public static String readFile(){
99+
//return "content of some file";
100+
return null;
101+
}
102+
103+
}
104+

dev_projects/RxJava/progress.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,6 @@
33
## 20240719
44
- https://youtu.be/7mbjhNCWqvs?si=GtCY3Wk5AFTdjYgS
55
- https://youtu.be/ApUUN55V2RE?si=zOpzZ14He9IzmqGZ
6-
- https://youtu.be/ApUUN55V2RE?si=ZpZ6K7coesyXk3nO
6+
- https://youtu.be/ApUUN55V2RE?si=ZpZ6K7coesyXk3nO
7+
- https://youtu.be/EIwAerzQDvA?si=RufdyI47fIpTJ0JU
8+
- https://youtu.be/EIwAerzQDvA?si=YyLHTw7Wut_qw8QZ

0 commit comments

Comments
 (0)