/** * Combine query params and form data for multipart form data from the body * of the request into a {@code Map<String, Object>} of values to use for * data binding purposes. * @param exchange the current exchange * @return a {@code Mono} with the values to bind * @see org.springframework.http.server.reactive.ServerHttpRequest#getQueryParams() * @see ServerWebExchange#getFormData() * @see ServerWebExchange#getMultipartData() */ public static Mono<Map<String, Object>> extractValuesToBind(ServerWebExchange exchange) { MultiValueMap<String, String> queryParams = exchange.getRequest().getQueryParams(); Mono<MultiValueMap<String, String>> formData = exchange.getFormData(); Mono<MultiValueMap<String, Part>> multipartData = exchange.getMultipartData(); return Mono.zip(Mono.just(queryParams), formData, multipartData) .map(tuple -> { Map<String, Object> result = new TreeMap<>(); tuple.getT1().forEach((key, values) -> addBindValue(result, key, values)); tuple.getT2().forEach((key, values) -> addBindValue(result, key, values)); tuple.getT3().forEach((key, values) -> addBindValue(result, key, values)); return result; }); }
@Test public void fn3Delegate() { Integer[] source = new Integer[] { 1, 2, 3, 4, 5, 6, 7, 8 }; Function<Tuple3<Integer, Integer, Integer>, Tuple3> invert = t3 -> new Tuple3<>(t3.getT3(), t3.getT2(), t3.getT1()); Tuple3 tuple = Tuples.fn3(invert).apply(source); assertThat(tuple.getT1()).isEqualTo(3); assertThat(tuple.getT2()).isEqualTo(2); assertThat(tuple.getT3()).isEqualTo(1); assertThat((Object) tuple).isExactlyInstanceOf(Tuple3.class); }
@Override public String getMessage() { //skip the "error has been observed" traceback if mapped traceback is empty synchronized (chainOrder) { if (chainOrder.isEmpty()) { return super.getMessage(); } StringBuilder sb = new StringBuilder(super.getMessage()).append( "Error has been observed by the following operator(s):\n"); for(Tuple3<Integer, String, Integer> t : chainOrder) { //noinspection ConstantConditions mapLine(t.getT3(), sb, t.getT2()); } return sb.toString(); } } }
@Test public void nonPairWisePairWise() { Flux<Tuple2<Tuple3<Integer, String, String>, String>> f = Flux.zip(Flux.just(1), Flux.just("test"), Flux.just("test0")) .zipWith(Flux.just("test2")); Assert.assertTrue(f instanceof FluxZip); FluxZip<?, ?> s = (FluxZip<?, ?>) f; Assert.assertTrue(s.sources != null); Assert.assertTrue(s.sources.length == 2); Flux<Tuple2<Integer, String>> ff = f.map(t -> Tuples.of(t.getT1() .getT1(), t.getT1() .getT2() + t.getT2())); ff.subscribeWith(AssertSubscriber.create()) .assertValues(Tuples.of(1, "testtest2")) .assertComplete(); }
Flux<Tuple3<IJavaModuleData, ClassInfo, Double>> fuzzySearchTypes(String searchTerm) { Flux<Tuple3<IJavaModuleData, ClassInfo, Double>> flux = Flux.fromIterable(modules).publishOn(Schedulers.parallel()) .flatMap(m -> Flux.fromIterable(getKnownTypeTuples(m))) .map(t -> Tuples.of(t.getT1(), t.getT2(), FuzzyMatcher.matchScore(searchTerm, t.getT2().name().toString()))) .filter(t -> t.getT3() != 0.0); return flux; }
/** * Create a {@link Tuple3} with the given objects. * * @param t1 The first value in the tuple. Not null. * @param t2 The second value in the tuple. Not null. * @param t3 The third value in the tuple. Not null. * @param <T1> The type of the first value. * @param <T2> The type of the second value. * @param <T3> The type of the third value. * @return The new {@link Tuple3}. */ public static <T1, T2, T3> Tuple3<T1, T2, T3> of(T1 t1, T2 t2, T3 t3) { return new Tuple3<>(t1, t2, t3); }
@Override public int hashCode() { int result = super.hashCode(); result = 31 * result + t4.hashCode(); return result; }
@Override public String getMessage() { //skip the "error has been observed" traceback if mapped traceback is empty synchronized (chainOrder) { if (chainOrder.isEmpty()) { return super.getMessage(); } StringBuilder sb = new StringBuilder(super.getMessage()).append( "Error has been observed by the following operator(s):\n"); for(Tuple3<Integer, String, Integer> t : chainOrder) { //noinspection ConstantConditions mapLine(t.getT3(), sb, t.getT2()); } return sb.toString(); } } }
/** * Map the 2nd part (T2) of this {@link Tuple3} into a different value and type, * keeping the other parts. * * @param mapper the mapping {@link Function} for the T2 part * @param <R> the new type for the T2 part * @return a new {@link Tuple3} with a different T2 value */ public <R> Tuple3<T1, R, T3> mapT2(Function<T2, R> mapper) { return new Tuple3<>(t1, mapper.apply(t2), t3); }
@Override public int hashCode() { int result = super.hashCode(); result = 31 * result + t4.hashCode(); return result; }
Mono<Request> createDefaultedRequest(String clientRegistrationId, Authentication authentication, ServerWebExchange exchange) { Mono<Authentication> defaultedAuthentication = Mono.justOrEmpty(authentication) .switchIfEmpty(currentAuthentication()); Mono<String> defaultedRegistrationId = Mono.justOrEmpty(clientRegistrationId) .switchIfEmpty(Mono.justOrEmpty(this.defaultClientRegistrationId)) .switchIfEmpty(clientRegistrationId(defaultedAuthentication)); Mono<Optional<ServerWebExchange>> defaultedExchange = Mono.justOrEmpty(exchange) .switchIfEmpty(currentServerWebExchange()).map(Optional::of) .defaultIfEmpty(Optional.empty()); return Mono.zip(defaultedRegistrationId, defaultedAuthentication, defaultedExchange) .map(t3 -> new Request(t3.getT1(), t3.getT2(), t3.getT3().orElse(null))); }
/** * Map the 1st part (T1) of this {@link Tuple3} into a different value and type, * keeping the other parts. * * @param mapper the mapping {@link Function} for the T1 part * @param <R> the new type for the T1 part * @return a new {@link Tuple3} with a different T1 value */ public <R> Tuple3<R, T2, T3> mapT1(Function<T1, R> mapper) { return new Tuple3<>(mapper.apply(t1), t2, t3); }