Skip to content

Commit

Permalink
Suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
Stephan202 authored and rickie committed Oct 9, 2023
1 parent aeb79f9 commit 788d555
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1056,34 +1056,26 @@ Flux<S> after(Flux<T> flux) {
/** Prefer {@link Mono#ofType(Class)} over more contrived alternatives. */
static final class MonoOfType<T, S> {
@BeforeTemplate
Mono<S> before(Mono<T> mono) {
return mono.filter(
Refaster.anyOf(
Refaster.<S>clazz()::isInstance,
x -> Refaster.<S>clazz().isAssignableFrom(x.getClass())))
.cast(Refaster.<S>clazz());
Mono<S> before(Mono<T> mono, Class<S> clazz) {
return mono.filter(clazz::isInstance).cast(clazz);
}

@AfterTemplate
Mono<S> after(Mono<T> mono) {
return mono.ofType(Refaster.<S>clazz());
Mono<S> after(Mono<T> mono, Class<S> clazz) {
return mono.ofType(clazz);
}
}

/** Prefer {@link Flux#ofType(Class)} over more contrived alternatives. */
static final class FluxOfType<T, S> {
@BeforeTemplate
Flux<S> before(Flux<T> flux) {
return flux.filter(
Refaster.anyOf(
Refaster.<S>clazz()::isInstance,
x -> Refaster.<S>clazz().isAssignableFrom(x.getClass())))
.cast(Refaster.<S>clazz());
Flux<S> before(Flux<T> flux, Class<S> clazz) {
return flux.filter(clazz::isInstance).cast(clazz);
}

@AfterTemplate
Flux<S> after(Flux<T> flux) {
return flux.ofType(Refaster.<S>clazz());
Flux<S> after(Flux<T> flux, Class<S> clazz) {
return flux.ofType(clazz);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -364,16 +364,12 @@ Flux<Number> testFluxCast() {
return Flux.just(1).map(Number.class::cast);
}

ImmutableSet<Mono<Number>> testMonoOfType() {
return ImmutableSet.of(
Mono.just(1).filter(Number.class::isInstance).cast(Number.class),
Mono.just(2).filter(n -> Number.class.isAssignableFrom(n.getClass())).cast(Number.class));
Mono<Number> testMonoOfType() {
return Mono.just(1).filter(Number.class::isInstance).cast(Number.class);
}

ImmutableSet<Flux<Number>> testFluxOfType() {
return ImmutableSet.of(
Flux.just(1).filter(Number.class::isInstance).cast(Number.class),
Flux.just(2).filter(n -> Number.class.isAssignableFrom(n.getClass())).cast(Number.class));
Flux<Number> testFluxOfType() {
return Flux.just(1).filter(Number.class::isInstance).cast(Number.class);
}

Mono<String> testMonoFlatMap() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -357,12 +357,12 @@ Flux<Number> testFluxCast() {
return Flux.just(1).cast(Number.class);
}

ImmutableSet<Mono<Number>> testMonoOfType() {
return ImmutableSet.of(Mono.just(1).ofType(Number.class), Mono.just(2).ofType(Number.class));
Mono<Number> testMonoOfType() {
return Mono.just(1).ofType(Number.class);
}

ImmutableSet<Flux<Number>> testFluxOfType() {
return ImmutableSet.of(Flux.just(1).ofType(Number.class), Flux.just(2).ofType(Number.class));
Flux<Number> testFluxOfType() {
return Flux.just(1).ofType(Number.class);
}

Mono<String> testMonoFlatMap() {
Expand Down

0 comments on commit 788d555

Please sign in to comment.