reactor.util.context.Context.isEmpty()方法的使用及代码示例

x33g5p2x  于2022-01-18 转载在 其他  
字(9.4k)|赞(0)|评价(0)|浏览(241)

本文整理了Java中reactor.util.context.Context.isEmpty()方法的一些代码示例,展示了Context.isEmpty()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Context.isEmpty()方法的具体详情如下:
包路径:reactor.util.context.Context
类名称:Context
方法名:isEmpty

Context.isEmpty介绍

[英]Return true if the Context is empty.
[中]如果上下文为空,则返回true。

代码示例

代码示例来源:origin: reactor/reactor-core

/**
 * Creates and returns a {@code Signal} of variety {@code Type.COMPLETE}, associated
 * with a specific {@link Context}.
 *
 * @param <T> the value type
 * @param context the {@link Context} associated with the completing source.
 *
 * @return an {@code OnCompleted} variety of {@code Signal}
 */
@SuppressWarnings({"deprecation", "unchecked"})
static <T> Signal<T> complete(Context context) {
  if (context.isEmpty()) {
    return (Signal<T>) ImmutableSignal.ON_COMPLETE;
  }
  return new ImmutableSignal<>(context, SignalType.ON_COMPLETE, null, null, null);
}

代码示例来源:origin: reactor/reactor-core

@Override
public Context currentContext() {
  Context c = actual.currentContext();
  final Consumer<? super Context> contextHook = parent.onCurrentContextCall();
  if(!c.isEmpty() && contextHook != null) {
    contextHook.accept(c);
  }
  return c;
}

代码示例来源:origin: reactor/reactor-core

@Override
public Context currentContext() {
  Context c = actual.currentContext();
  final Consumer<? super Context> contextHook = parent.onCurrentContextCall();
  if(!c.isEmpty() && contextHook != null) {
    contextHook.accept(c);
  }
  return c;
}

代码示例来源:origin: reactor/reactor-core

/**
   * Create a new {@link Context} by merging the content of this context and a given
   * {@link Context}. If the other context is empty, the same {@link Context} instance
   * is returned.
   *
   * @param other the other Context to get values from
   * @return a new Context with a merge of the entries from this context and the given context.
   */
  default Context putAll(Context other) {
    if (other.isEmpty()) return this;

    return other.stream()
          .reduce(this,
              (c, e) -> c.put(e.getKey(), e.getValue()),
              (c1, c2) -> { throw new UnsupportedOperationException("Context.putAll should not use a parallelized stream");}
          );
  }
}

代码示例来源:origin: reactor/reactor-core

@Override
public Context putAll(Context other) {
  if (other.isEmpty()) return this;
  if (other instanceof ContextN) return new ContextN(this, ((ContextN) other));
  Map<?, ?> mapOther = other.stream()
               .collect(Collectors.toMap(Entry::getKey, Entry::getValue));
  return new ContextN(this, mapOther);
}

代码示例来源:origin: reactor/reactor-core

@Override
public Context currentContext() {
  Context c = actual.currentContext();
  if(!c.isEmpty() && parent.onCurrentContextCall() != null) {
    parent.onCurrentContextCall().accept(c);
  }
  return c;
}

代码示例来源:origin: reactor/reactor-core

@Override
public Context currentContext() {
  Context c = actual.currentContext();
  if(!c.isEmpty() && parent.onCurrentContextCall() != null) {
    parent.onCurrentContextCall().accept(c);
  }
  return c;
}

代码示例来源:origin: reactor/reactor-core

@Test
public void of2() throws Exception {
  Context c = Context.of(1, 100, 2, 200);
  assertThat(c).isInstanceOf(Context2.class);
  assertThat(c.isEmpty()).as("isEmpty").isFalse();
  assertThat(c.stream()).hasSize(2);
}

代码示例来源:origin: reactor/reactor-core

@Test
public void of5() throws Exception {
  Context c = Context.of(1, 100, 2, 200, 3, 300, 4, 400, 5, 500);
  assertThat(c).isInstanceOf(Context5.class);
  assertThat(c.isEmpty()).as("isEmpty").isFalse();
  assertThat(c.stream()).hasSize(5);
}

代码示例来源:origin: reactor/reactor-core

@Test
public void of4() throws Exception {
  Context c = Context.of(1, 100, 2, 200, 3, 300, 4, 400);
  assertThat(c).isInstanceOf(Context4.class);
  assertThat(c.isEmpty()).as("isEmpty").isFalse();
  assertThat(c.stream()).hasSize(4);
}

代码示例来源:origin: reactor/reactor-core

@Test
  public void equalsIgnoresContext() {
    Signal<String> next1 = Signal.next("foo");
    Signal<String> next2 = Signal.next("foo", Context.of("bar", "baz"));

    assertThat(next1.getContext().isEmpty()).as("next1 context empty").isTrue();
    assertThat(next2.getContext().isEmpty()).as("next2 context not empty").isFalse();
    assertThat(next1).isEqualTo(next2);
  }
}

代码示例来源:origin: reactor/reactor-core

@Test
public void of1() throws Exception {
  Context c = Context.of(1, 100);
  assertThat(c).isInstanceOf(Context1.class);
  assertThat(c.isEmpty()).as("isEmpty").isFalse();
  assertThat(c.stream()).hasSize(1);
}

代码示例来源:origin: reactor/reactor-core

@Test
public void of3() throws Exception {
  Context c = Context.of(1, 100, 2, 200, 3, 300);
  assertThat(c).isInstanceOf(Context3.class);
  assertThat(c.isEmpty()).as("isEmpty").isFalse();
  assertThat(c.stream()).hasSize(3);
}

代码示例来源:origin: reactor/reactor-core

@Test
public void empty() throws Exception {
  Context c = Context.empty();
  assertThat(c).isInstanceOf(Context0.class);
  assertThat(c.isEmpty()).as("isEmpty").isTrue();
}

代码示例来源:origin: reactor/reactor-core

@Test
public void isEmpty() {
  assertThat(Context.empty().isEmpty()).as("empty().isEmpty()").isTrue();
  assertThat(new Context0().isEmpty()).as("new Context0().isEmpty()").isTrue();
}

代码示例来源:origin: reactor/reactor-core

@Test
public void errorStateWithContext(){
  Context context = Context.of("foo", "bar");
  Signal<Integer> s = Signal.error(e, context);
  assertThat(s.getContext().isEmpty()).as("has context").isFalse();
  assertThat(s.isOnComplete()).isFalse();
  assertThat(s.isOnSubscribe()).isFalse();
  assertThat(s.hasError()).isTrue();
  assertThat(s.hasValue()).isFalse();
  assertThat(s).isEqualTo(Signal.error(e));
  assertThat(s).isNotEqualTo(Signal.error(new Exception("test2")));
  assertThat(s).isNotEqualTo(Signal.complete());
  assertThat(s).isNotEqualTo(Signal.subscribe(Operators.emptySubscription()));
  assertThat(s).isNotEqualTo(Signal.next(1));
  assertThat(s.hashCode()).isEqualTo(Signal.error(e).hashCode());
  assertThat(s.hashCode()).isNotEqualTo(Signal.error(new Exception("test2")).hashCode());
  assertThat(s.hashCode()).isNotEqualTo(Signal.complete().hashCode());
  assertThat(s.hashCode()).isNotEqualTo(Signal.next(1).hashCode());
  assertThat(s.hashCode()).isNotEqualTo(Signal.subscribe(Operators.emptySubscription()).hashCode());
  assertThat(Signal.isComplete(s)).isFalse();
  assertThat(Signal.isError(s)).isTrue();
  assertThat(s.getThrowable()).isEqualTo(e);
  assertThat(s.getType()).isEqualTo(SignalType.ON_ERROR);
  assertThat(s.toString()).contains("onError");
  StepVerifier.create(Flux.<Integer>from(sub -> {
    sub.onSubscribe(Operators.emptySubscription());
    s.accept(sub);
  }))
        .verifyErrorMessage("test");
}

代码示例来源:origin: reactor/reactor-core

@Test
public void completeStateWithContext(){
  Context context = Context.of("foo", "bar");
  Signal<Integer> s = Signal.complete(context);
  assertThat(s.getContext().isEmpty()).as("has context").isFalse();
  assertThat(s.isOnComplete()).isTrue();
  assertThat(s.isOnSubscribe()).isFalse();
  assertThat(s.hasError()).isFalse();
  assertThat(s.hasValue()).isFalse();
  assertThat(s).isEqualTo(Signal.complete());
  assertThat(s).isNotEqualTo(Signal.error(e));
  assertThat(s).isNotEqualTo(Signal.subscribe(Operators.emptySubscription()));
  assertThat(s).isNotEqualTo(Signal.next(1));
  assertThat(s.hashCode()).isEqualTo(Signal.complete().hashCode());
  assertThat(s.hashCode()).isNotEqualTo(Signal.error(e).hashCode());
  assertThat(s.hashCode()).isNotEqualTo(Signal.next(1).hashCode());
  assertThat(s.hashCode()).isNotEqualTo(Signal.subscribe(Operators.emptySubscription()).hashCode());
  assertThat(Signal.isComplete(s)).isTrue();
  assertThat(Signal.isError(s)).isFalse();
  assertThat(s.getType()).isEqualTo(SignalType.ON_COMPLETE);
  assertThat(s.toString()).contains("onComplete");
  StepVerifier.create(Flux.<Integer>from(sub -> {
    sub.onSubscribe(Operators.emptySubscription());
    s.accept(sub);
  }))
        .verifyComplete();
}

代码示例来源:origin: reactor/reactor-core

Signal<Integer> s = Signal.next(1, context);
assertThat(s.getContext().isEmpty()).as("has context").isFalse();

代码示例来源:origin: reactor/reactor-core

@Test
public void subscribeStateWithContext(){
  Context context = Context.of("foo", "bar");
  Signal<Integer> s = Signal.subscribe(Operators.emptySubscription(), context);
  assertThat(s.getContext().isEmpty()).as("has context").isFalse();
  assertThat(s.isOnComplete()).isFalse();
  assertThat(s.isOnSubscribe()).isTrue();
  assertThat(s.hasError()).isFalse();
  assertThat(s.hasValue()).isFalse();
  assertThat(s).isEqualTo(Signal.subscribe(Operators.emptySubscription()));
  assertThat(s).isNotEqualTo(Signal.subscribe(Operators.cancelledSubscription()));
  assertThat(s).isNotEqualTo(Signal.next(1));
  assertThat(s).isNotEqualTo(Signal.error(e));
  assertThat(s).isNotEqualTo(Signal.complete());
  assertThat(s.hashCode()).isEqualTo(Signal.subscribe(Operators.emptySubscription()).hashCode());
  assertThat(s.hashCode()).isNotEqualTo(Signal.subscribe(Operators.cancelledSubscription()).hashCode());
  assertThat(s.hashCode()).isNotEqualTo(Signal.next(1).hashCode());
  assertThat(s.hashCode()).isNotEqualTo(Signal.error(e).hashCode());
  assertThat(s.hashCode()).isNotEqualTo(Signal.complete().hashCode());
  assertThat(Signal.isComplete(s)).isFalse();
  assertThat(Signal.isError(s)).isFalse();
  assertThat(s.getSubscription()).isEqualTo(Operators.emptySubscription());
  assertThat(s.getType()).isEqualTo(SignalType.ON_SUBSCRIBE);
  assertThat(s.toString()).contains("onSubscribe");
  StepVerifier.create(Flux.<Integer>from(s::accept))
        .expectSubscription()
        .thenCancel()
        .verify();
}
@Test

代码示例来源:origin: io.projectreactor/reactor-core

@Override
public Context currentContext() {
  Context c = actual.currentContext();
  final Consumer<? super Context> contextHook = parent.onCurrentContextCall();
  if(!c.isEmpty() && contextHook != null) {
    contextHook.accept(c);
  }
  return c;
}

相关文章