本文整理了Java中reactor.util.function.Tuple2
类的一些代码示例,展示了Tuple2
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Tuple2
类的具体详情如下:
包路径:reactor.util.function.Tuple2
类名称:Tuple2
[英]A tuple that holds two non-null values.
[中]包含两个非空值的元组。
代码示例来源:origin: lettuce-io/lettuce-core
@Override
protected void onAccept(Tuple2<RedisURI, StatefulRedisConnection<String, String>> value) {
if (this.closed) {
value.getT2().closeAsync();
return;
}
synchronized (this.connections) {
this.connections.put(value.getT1(), value.getT2());
}
}
代码示例来源:origin: reactor/reactor-core
@Test
public void fnAnyDelegate() {
Integer[] source = new Integer[] { 1, 2, 3, 4, 5, 6, 7, 8 };
Function<Tuple2, Tuple2<Object, Object>> invert = t2 -> new Tuple2<>(t2.getT2(), t2.getT1());
Tuple2<Object, Object> tuple = Tuples.fnAny(invert).apply(source);
assertThat(tuple.getT1()).isEqualTo(2);
assertThat(tuple.getT2()).isEqualTo(1);
assertThat(tuple)
.isExactlyInstanceOf(Tuple2.class)
.containsExactly(2, 1);
}
代码示例来源:origin: reactor/reactor-core
@Test
public void sanityTestHashcode() {
Tuple2<Integer, Integer> same = new Tuple2<>(1, 2);
Tuple2<Integer, Integer> different = new Tuple2<>(2, 1);
assertThat(full.hashCode())
.isEqualTo(same.hashCode())
.isNotEqualTo(different.hashCode());
}
代码示例来源:origin: reactor/reactor-core
@Override
public StepVerifier.Assertions hasOperatorErrorOfType(Class<? extends Throwable> clazz) {
//noinspection ConstantConditions
satisfies(() -> clazz != null, () -> "Require non-null clazz");
hasOneOperatorErrorWithError();
return satisfies(
() -> clazz.isInstance(hookRecorder.operatorErrors.peek().getT1().get()),
() -> String.format("Expected operator error to be of type %s, was %s.",
clazz.getCanonicalName(),
hookRecorder.operatorErrors.peek().getT1().get().getClass().getCanonicalName()));
}
代码示例来源:origin: lettuce-io/lettuce-core
@Override
protected void onDrop(Tuple2<RedisURI, StatefulRedisConnection<String, String>> value) {
value.getT2().closeAsync();
}
代码示例来源:origin: reactor/reactor-core
@Test
public void mapT2() {
Tuple2<Integer, String> base = Tuples.of(100, "Foo");
Tuple2<?,?> mapped = base.mapT2(String::length);
assertThat(mapped).isNotSameAs(base)
.hasSize(2)
.containsExactly(base.getT1(), 3);
}
代码示例来源:origin: reactor/reactor-core
@Test
public void mapT1() {
Tuple2<String, Integer> base = Tuples.of("Foo", 200);
Tuple2<?,?> mapped = base.mapT1(String::length);
assertThat(mapped).isNotSameAs(base)
.hasSize(2)
.containsExactly(3, base.getT2());
}
代码示例来源:origin: reactor/reactor-core
/**
* Create a {@link Tuple2} 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 <T1> The type of the first value.
* @param <T2> The type of the second value.
* @return The new {@link Tuple2}.
*/
public static <T1, T2> Tuple2<T1, T2> of(T1 t1, T2 t2) {
return new Tuple2<>(t1, t2);
}
代码示例来源:origin: reactor/reactor-core
@Override
public int hashCode() {
int result = super.hashCode();
result = 31 * result + t3.hashCode();
return result;
}
}
代码示例来源:origin: reactor/reactor-core
StepVerifier.Assertions hasOneOperatorErrorWithError() {
satisfies(() -> hookRecorder.operatorErrors.size() == 1,
() -> String.format("Expected exactly one operator error, %d found.", hookRecorder.operatorErrors.size()));
satisfies(() -> hookRecorder.operatorErrors.peek().getT1().isPresent(),
() -> "Expected exactly one operator error with an actual throwable content, no throwable found.");
return this;
}
代码示例来源:origin: reactor/reactor-core
@Test
public void errorHandlingIntervalMillisRetried() throws InterruptedException {
VirtualTimeScheduler virtualTimeScheduler = VirtualTimeScheduler.create();
VirtualTimeScheduler.set(virtualTimeScheduler);
Flux<Tuple2<Long,String>> flux =
Flux.interval(Duration.ofMillis(250))
.map(input -> {
if (input < 3) return "tick " + input;
throw new RuntimeException("boom");
})
.retry(1)
.elapsed(); // <1>
flux.subscribe(System.out::println, System.err::println); // <2>
//Thread.sleep(2100); // <3>
virtualTimeScheduler.advanceTimeBy(Duration.ofHours(1));
StepVerifier.withVirtualTime(() -> flux, () -> virtualTimeScheduler, Long.MAX_VALUE)
.thenAwait(Duration.ofSeconds(3))
.expectNextMatches(t -> t.getT2().equals("tick 0"))
.expectNextMatches(t -> t.getT2().equals("tick 1"))
.expectNextMatches(t -> t.getT2().equals("tick 2"))
.expectNextMatches(t -> t.getT2().equals("tick 0"))
.expectNextMatches(t -> t.getT2().equals("tick 1"))
.expectNextMatches(t -> t.getT2().equals("tick 2"))
.verifyErrorMessage("boom");
}
代码示例来源:origin: reactor/reactor-core
/**
* Map the left-hand part (T1) of this {@link Tuple2} into a different value and type,
* keeping the right-hand part (T2).
*
* @param mapper the mapping {@link Function} for the left-hand part
* @param <R> the new type for the left-hand part
* @return a new {@link Tuple2} with a different left (T1) value
*/
public <R> Tuple2<R, T2> mapT1(Function<T1, R> mapper) {
return new Tuple2<>(mapper.apply(t1), t2);
}
代码示例来源:origin: io.projectreactor/reactor-core
@Override
public int hashCode() {
int result = super.hashCode();
result = 31 * result + t3.hashCode();
return result;
}
}
代码示例来源:origin: spring-projects/spring-data-redis
@Override
public BiConsumer<Properties, Tuple2<RedisClusterNode, Properties>> accumulator() {
return (properties, tuple) -> {
for (Entry<Object, Object> entry : tuple.getT2().entrySet()) {
properties.put(tuple.getT1().asString() + "." + entry.getKey(), entry.getValue());
}
};
}
代码示例来源:origin: reactor/reactor-core
@Override
public StepVerifier.Assertions hasOperatorErrorMatching(Predicate<Throwable> matcher) {
//noinspection ConstantConditions
satisfies(() -> matcher != null, () -> "Require non-null matcher");
hasOneOperatorErrorWithError();
return satisfies(
() -> matcher.test(hookRecorder.operatorErrors.peek().getT1().orElse(null)),
() -> String.format(
"Expected operator error matching the given predicate, did not match: <%s>.",
hookRecorder.operatorErrors.peek()));
}
代码示例来源:origin: reactor/reactor-core
/**
* Map the right-hand part (T2) of this {@link Tuple2} into a different value and type,
* keeping the left-hand part (T1).
*
* @param mapper the mapping {@link Function} for the right-hand part
* @param <R> the new type for the right-hand part
* @return a new {@link Tuple2} with a different right (T2) value
*/
public <R> Tuple2<T1, R> mapT2(Function<T2, R> mapper) {
return new Tuple2<>(t1, mapper.apply(t2));
}
代码示例来源:origin: reactor/reactor-core
/**
* For testing purposes.
*
* @param candidate the registry to use, as a plain {@link Object} to avoid leaking dependency
*/
FluxMetricsFuseable(Flux<? extends T> flux, @Nullable MeterRegistry candidate) {
super(flux);
Tuple2<String, List<Tag>> nameAndTags = resolveNameAndTags(flux);
this.name = nameAndTags.getT1();
this.tags = nameAndTags.getT2();
this.registryCandidate = candidate;
}
代码示例来源:origin: reactor/reactor-core
@Override
public StepVerifier.Assertions hasOperatorErrorWithMessage(String message) {
//noinspection ConstantConditions
satisfies(() -> message != null, () -> "Require non-null message");
hasOneOperatorErrorWithError();
String actual = hookRecorder.operatorErrors.peek().getT1().get().getMessage();
return satisfies(() -> message.equals(actual),
() -> String.format("Expected operator error with message <\"%s\">, was <\"%s\">.", message, actual));
}
代码示例来源:origin: reactor/reactor-core
@Test
public void equals() {
Tuple2<Integer, Integer> otherFull = new Tuple2<>(1, 2);
assertThat(full)
.isEqualTo(otherFull);
}
代码示例来源:origin: reactor/reactor-core
/**
* For testing purposes.
*
* @param registryCandidate the registry to use, as a plain {@link Object} to avoid leaking dependency
*/
MonoMetricsFuseable(Mono<? extends T> mono, @Nullable MeterRegistry registryCandidate) {
super(mono);
Tuple2<String, List<Tag>> nameAndTags = FluxMetrics.resolveNameAndTags(mono);
this.name = nameAndTags.getT1();
this.tags = nameAndTags.getT2();
this.registryCandidate = registryCandidate;
}
内容来源于网络,如有侵权,请联系作者删除!