com.spotify.mobius.Next.hasModel()方法的使用及代码示例

x33g5p2x  于2022-01-25 转载在 其他  
字(5.4k)|赞(0)|评价(0)|浏览(96)

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

Next.hasModel介绍

[英]Check if this Next contains a model.
[中]检查下一步是否包含模型。

代码示例

代码示例来源:origin: spotify/mobius

@Override
protected boolean matchesSafely(Next<M, F> item, Description mismatchDescription) {
 if (item.hasModel()) {
  mismatchDescription.appendText("has a model");
  return false;
 } else {
  mismatchDescription.appendText("no model");
  return true;
 }
}

代码示例来源:origin: spotify/mobius

@Override
protected boolean matchesSafely(Next<M, F> item, Description mismatchDescription) {
 if (item.hasModel()) {
  mismatchDescription.appendText("has a model");
  return true;
 } else {
  mismatchDescription.appendText("no model");
  return false;
 }
}

代码示例来源:origin: spotify/mobius

/**
 * Get the model of this Next. This version is unsafe - if this next doesn't have a model, calling
 * this method will cause an exception to be thrown.
 *
 * <p>In almost all cases you should use {@link #modelOrElse} or {@link #ifHasModel} instead.
 *
 * @throws NoSuchElementException if this Next has no model
 */
@Nonnull
public M modelUnsafe() {
 if (!hasModel()) {
  throw new NoSuchElementException("there is no model in this Next<>");
 }
 // we know model is never null here since we just checked it.
 //noinspection ConstantConditions
 return model();
}

代码示例来源:origin: com.spotify.mobius/mobius-core

/**
 * Get the model of this Next. This version is unsafe - if this next doesn't have a model, calling
 * this method will cause an exception to be thrown.
 *
 * <p>In almost all cases you should use {@link #modelOrElse} or {@link #ifHasModel} instead.
 *
 * @throws NoSuchElementException if this Next has no model
 */
@Nonnull
public M modelUnsafe() {
 if (!hasModel()) {
  throw new NoSuchElementException("there is no model in this Next<>");
 }
 // we know model is never null here since we just checked it.
 //noinspection ConstantConditions
 return model();
}

代码示例来源:origin: spotify/mobius

@Override
public void afterUpdate(M model, E event, Next<M, F> result) {
 if (result.hasModel()) {
  LOGGER.debug(LOGGING_PREFIX + "Model updated: {}", loggingTag, result.modelUnsafe());
 }
 for (F effect : result.effects()) {
  LOGGER.debug(LOGGING_PREFIX + "Effect dispatched: {}", loggingTag, effect);
 }
}

代码示例来源:origin: spotify/mobius

@Override
public void afterUpdate(M model, E event, Next<M, F> result) {
 if (result.hasModel()) {
  Log.d(tag, "Model updated: " + result.modelUnsafe());
 }
 for (F effect : result.effects()) {
  Log.d(tag, "Effect dispatched: " + effect);
 }
}

代码示例来源:origin: spotify/mobius

/**
 * Try to get the model from this Next, with a fallback if there isn't one.
 *
 * @param fallbackModel the default model to use if the Next doesn't have a model
 */
@Nonnull
public M modelOrElse(M fallbackModel) {
 checkNotNull(fallbackModel);
 if (hasModel()) {
  return modelUnsafe();
 } else {
  return fallbackModel;
 }
}

代码示例来源:origin: com.spotify.mobius/mobius-core

/**
 * Try to get the model from this Next, with a fallback if there isn't one.
 *
 * @param fallbackModel the default model to use if the Next doesn't have a model
 */
@Nonnull
public M modelOrElse(M fallbackModel) {
 checkNotNull(fallbackModel);
 if (hasModel()) {
  return modelUnsafe();
 } else {
  return fallbackModel;
 }
}

代码示例来源:origin: spotify/mobius

@Override
protected boolean matchesSafely(Next<M, F> item, Description mismatchDescription) {
 if (!item.hasModel()) {
  mismatchDescription.appendText("no model");
  return false;
 } else if (!matcher.matches(item.modelUnsafe())) {
  mismatchDescription.appendText("bad model: ");
  matcher.describeMismatch(item.modelUnsafe(), mismatchDescription);
  return false;
 } else {
  mismatchDescription.appendText("has a model: ");
  matcher.describeMismatch(item.modelUnsafe(), mismatchDescription);
  return true;
 }
}

代码示例来源:origin: spotify/mobius

/** If the model is present, call the given consumer with it, otherwise do nothing. */
public void ifHasModel(Consumer<M> consumer) {
 checkNotNull(consumer);
 if (hasModel()) {
  consumer.accept(modelUnsafe());
 }
}

代码示例来源:origin: com.spotify.mobius/mobius-core

/** If the model is present, call the given consumer with it, otherwise do nothing. */
public void ifHasModel(Consumer<M> consumer) {
 checkNotNull(consumer);
 if (hasModel()) {
  consumer.accept(modelUnsafe());
 }
}

代码示例来源:origin: spotify/mobius

@Test
public void nextNoEffectsOnlyHasModel() throws Exception {
 Next<String, String> next = Next.next("foo");
 assertTrue(next.hasModel());
 assertFalse(next.hasEffects());
}

代码示例来源:origin: spotify/mobius

@Test
public void nextNoopHasNoModelAndNoEffects() throws Exception {
 Next<String, String> next = noChange();
 assertFalse(next.hasModel());
 assertFalse(next.hasEffects());
}

代码示例来源:origin: spotify/mobius

@Nonnull
public final Next<M, F> update(M model, E event) {
 MI innerModel = checkNotNull(modelExtractor().apply(model));
 EI innerEvent = checkNotNull(eventExtractor().apply(event));
 Next<MI, FI> innerNext = checkNotNull(innerUpdate().update(innerModel, innerEvent));
 M newModel = model;
 boolean modelUpdated = innerNext.hasModel();
 if (modelUpdated) {
  newModel = checkNotNull(modelUpdater().apply(model, innerNext.modelUnsafe()));
 }
 return checkNotNull(
   innerEffectHandler().handleInnerEffects(newModel, modelUpdated, innerNext.effects()));
}

代码示例来源:origin: spotify/mobius

@Test
public void nextEffectsOnlyHasEffects() throws Exception {
 Next<String, String> next = dispatch(effects("foo"));
 assertFalse(next.hasModel());
 assertTrue(next.hasEffects());
}

代码示例来源:origin: spotify/mobius

@Test
public void nextModelAndEffectsHasBothModelAndEffects() throws Exception {
 Next<String, String> next = Next.next("m", effects("f"));
 assertTrue(next.hasModel());
 assertTrue(next.hasEffects());
}

相关文章