Commit 94a2882b authored by Julien Sadaoui's avatar Julien Sadaoui
Browse files

fix: code cleanup

parent 1d3b807e
......@@ -125,7 +125,7 @@ public class Level5 {
log.info("Start Level5/Exercise4");
Flowable.range(1, 5)
.scan((result, item) -> result + item)
.scan(Integer::sum)
.doOnComplete(() -> log.info("Completed"))
.subscribe(value -> log.info("Next: {}", value));
}
......@@ -187,7 +187,7 @@ public class Level5 {
* <li>Completed</li>
* </ul>
*
* Note : La méthode {@Flowable#concat} génère un flux ou les éléments du premier flux apparaissent avant les éléments du second flux.
* Note : La méthode {@link Flowable#concat} génère un flux ou les éléments du premier flux apparaissent avant les éléments du second flux.
*/
public static void exercise6() {
log.info("Start Level5/Exercise6");
......@@ -227,7 +227,7 @@ public class Level5 {
* <li>Completed</li>
* </ul>
*
* Note : La méthode {@Observable#merge} génère un flux ou les éléments des deux flux apparaissent au fur et à mesure
* Note : La méthode {@link Flowable#merge} génère un flux ou les éléments des deux flux apparaissent au fur et à mesure
* qu'ils sont émis par l'un des deux flux.
*/
public static void exercise7() {
......
......@@ -97,8 +97,6 @@ public class Level6 {
* <li>[RxSingleScheduler-1] Received: 3</li>
* <li>[RxSingleScheduler-1] Sending: 4</li>
* <li>[RxSingleScheduler-1] Received: 4</li>
* <li>[RxSingleScheduler-1] Sending: 5</li>
* <li>[RxSingleScheduler-1] Received: 5</li>
* <li>[RxSingleScheduler-1] Completed</li>
* </ul>
*
......@@ -121,7 +119,7 @@ public class Level6 {
log.info("Subscribing ...");
observable
.subscribeOn(Schedulers.single())
.doOnComplete(() -> latch.countDown())
.doOnComplete(latch::countDown)
.subscribe(
value -> log.info("Received: {}", value),
Helpers::log,
......@@ -132,7 +130,7 @@ public class Level6 {
}
/**
* Crée un flux synchrone et receptionne les données dans une tâche asynchrone à l'aide
* Crée un flux dans le thread principal et receptionne les données dans une tâche asynchrone à l'aide
* de la méthode {@link Observable#observeOn}.
* <p><p>
*
......@@ -140,24 +138,21 @@ public class Level6 {
* <ul>
* <li>Start Level6/Exercise1</li>
* <li>[main] Subscribing ...</li>
* <li>[main] Subscribed</li>
* <li>[RxSingleScheduler-1] Sending: 1</li>
* <li>[main] Received: 1</li>
* <li>[RxSingleScheduler-1] Sending: 2</li>
* <li>[main] Received: 2</li>
* <li>[RxSingleScheduler-1] Sending: 3</li>
* <li>[main] Received: 3</li>
* <li>[main] Sending: 1</li>
* <li>[RxSingleScheduler-1] Received: 1</li>
* <li>[main] Sending: 2</li>
* <li>[RxSingleScheduler-1] Received: 2</li>
* <li>[main] Sending: 3</li>
* <li>[xSingleScheduler-1] Received: 3</li>
* <li>[main] Sending: 4</li>
* <li>[RxSingleScheduler-1] Received: 4</li>
* <li>[main] Sending: 5</li>
* <li>[RxSingleScheduler-1] Received: 5</li>
* <li>[RxSingleScheduler-1] Completed</li>
* <li>[main] Subscribed</li>
* <li>[RxSingleScheduler-1] Completed</li>
* </ul>
*
* Remarque: La méthode {@link Observable#subscribeOn} permet de changer le {@link Thread} du consommateur.
*/
public static void exercise3() throws Exception {
public static void exercise3() {
log.info("Start Level6/Exercise3");
Observable<Integer> observable = Observable.create(subscriber -> {
......
......@@ -31,7 +31,7 @@ public class Account {
private BigDecimal balance;
@Builder.Default
private Set<Transaction> transactions = new HashSet<>();
private Set<Transaction> transactions;
@NotEmpty
private String customerId;
......
......@@ -4,8 +4,8 @@ import java.math.BigDecimal;
import java.util.function.BiFunction;
public enum Operation {
DEBIT((balance, amount) -> balance.subtract(amount)),
CREDIT((balance, amount) -> balance.add(amount));
DEBIT(BigDecimal::subtract),
CREDIT(BigDecimal::add);
private final BiFunction<BigDecimal, BigDecimal, BigDecimal> compute;
......
......@@ -82,6 +82,7 @@ public class AccountServiceImpl implements AccountService {
@PreAuthorize("hasRole('CUSTOMER')")
public Flux<Transaction> getTransactions(String customerId, String accountNumber) {
return accountRepository.findByCustomerIdAndNumber(customerId, accountNumber)
.flatMapMany(account -> Flux.fromIterable(account.getTransactions()));
.map(Account::getTransactions)
.flatMapMany(Flux::fromIterable);
}
}
......@@ -5,8 +5,6 @@ spring:
mongodb:
database: spring-reactor-mongomongo
port: 27017
reactive-repositories:
enabled: true
auto-index-creation: true
logging:
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment