本文整理汇总了Java中reactor.core.publisher.Mono.flatMap方法的典型用法代码示例。如果您正苦于以下问题:Java Mono.flatMap方法的具体用法?Java Mono.flatMap怎么用?Java Mono.flatMap使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类reactor.core.publisher.Mono
的用法示例。
在下文中一共展示了Mono.flatMap方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: geometryLocation
import reactor.core.publisher.Mono; //导入方法依赖的package包/类
Mono<GeographicCoordinates> geometryLocation(final Mono<GeoLocationResponse> geoLocationResponseMono) {
return geoLocationResponseMono.flatMap(geoLocationResponse -> {
if (geoLocationResponse.getStatus() != null) {
switch (geoLocationResponse.getStatus()) {
case OK_STATUS:
return Mono.just(
new GeographicCoordinates(geoLocationResponse.getResults()[0].getGeometry().getLocation().getLat(),
geoLocationResponse.getResults()[0].getGeometry().getLocation().getLng()));
case ZERO_RESULTS:
return Mono.error(new GeoLocationNotFoundException(ADDRESS_NOT_FOUND));
default:
return Mono.error(new GetGeoLocationException(ERROR_GETTING_LOCATION));
}
} else {
return Mono.error(new GetGeoLocationException(ERROR_LOCATION_WAS_NULL));
}
}
);
}
示例2: count
import reactor.core.publisher.Mono; //导入方法依赖的package包/类
@GetMapping("/mate")
public Flux<Mate> count(@RequestParam Integer limit) {
Flux<Mate> goodGuys = repository.findAll();
Flux<GitterUser> usersInRoom = gitterClient.getUsersInRoom(props.getRoom(), limit);
Mono<List<GitterUser>> listOfUsers = usersInRoom.collectList();
return listOfUsers.flatMap(gitterUsers -> {
return goodGuys.map(mate -> {
Optional<GitterUser> first = gitterUsers.stream()
.filter(u -> u.getUsername().equals(mate.nickname))
.findFirst();
return new Mate(mate.nickname, mate.firstName, first.isPresent());
});
});
}
示例3: serverResponse
import reactor.core.publisher.Mono; //导入方法依赖的package包/类
Mono<ServerResponse> serverResponse(Mono<LocationResponse> locationResponseMono) {
return locationResponseMono.flatMap(locationResponse ->
ServerResponse.ok().body(Mono.just(locationResponse), LocationResponse.class));
}
示例4: buildUrl
import reactor.core.publisher.Mono; //导入方法依赖的package包/类
Mono<String> buildUrl(final Mono<String> addressMono) {
return addressMono.flatMap(address -> {
if (address.equals("")) {
return Mono.error(new InvalidParametersException(MISSING_ADDRESS));
}
return Mono.just(endPoint.concat(ADDRESS_PARAMETER).concat(address));
});
}
示例5: get
import reactor.core.publisher.Mono; //导入方法依赖的package包/类
Mono<GeoLocationResponse> get(final Mono<String> urlMono) {
return urlMono.flatMap(url -> webClient
.get()
.uri(url)
.accept(MediaType.APPLICATION_JSON)
.exchange()
.flatMap(clientResponse -> clientResponse.bodyToMono(GeoLocationResponse.class)));
}
示例6: buildUrl
import reactor.core.publisher.Mono; //导入方法依赖的package包/类
Mono<String> buildUrl(final Mono<GeographicCoordinates> geographicCoordinatesMono) {
return geographicCoordinatesMono.flatMap(geographicCoordinates -> Mono.just(endPoint
.concat(BEGIN_PARAMETERS)
.concat(LATITUDE_PARAMETER).concat(Double.toString(geographicCoordinates.getLatitude()))
.concat(NEXT_PARAMETER)
.concat(LONGITUDE_PARAMETER).concat(Double.toString(geographicCoordinates.getLongitude()))
.concat(NEXT_PARAMETER)
.concat(DATE_PARAMETER).concat(TODAY_DATE)
.concat(NEXT_PARAMETER)
.concat(FORMATTED_PARAMETER).concat(NOT_FORMATTED)
));
}
示例7: get
import reactor.core.publisher.Mono; //导入方法依赖的package包/类
Mono<GeoTimesResponse> get(final Mono<String> monoUrl) {
return monoUrl.flatMap(url -> webClient
.get()
.uri(url)
.accept(MediaType.APPLICATION_JSON)
.exchange()
.flatMap(clientResponse -> clientResponse.bodyToMono(GeoTimesResponse.class)));
}
示例8: createResult
import reactor.core.publisher.Mono; //导入方法依赖的package包/类
Mono<SunriseSunset> createResult(final Mono<GeoTimesResponse> geoTimesResponseMono) {
return geoTimesResponseMono.flatMap(geoTimesResponse -> {
if ((geoTimesResponse.getStatus() != null) && (geoTimesResponse.getStatus().equals(STATUS_OK))) {
return Mono.just(new SunriseSunset(geoTimesResponse.getResults().getSunrise(),
geoTimesResponse.getResults().getSunset()));
} else {
return Mono.error(new GetSunriseSunsetException(SUNRISE_RESULT_NOT_OK));
}
});
}
示例9: translate
import reactor.core.publisher.Mono; //导入方法依赖的package包/类
static <T extends Throwable> Mono<ThrowableTranslator> translate(final Mono<T> throwable) {
return throwable.flatMap(error -> Mono.just(new ThrowableTranslator(error)));
}
示例10: toMono
import reactor.core.publisher.Mono; //导入方法依赖的package包/类
private <T> Mono<T> toMono(Mono<ClientResponse> monoResponse, Class<T> monoContentType) {
return monoResponse
.flatMap(response -> bodyToPublisher(response,
BodyExtractors.toMono(monoContentType),
ErrorBodyExtractors.toMono(httpErrorReaders)));
}