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

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

本文整理了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

  1. @Override
  2. protected boolean matchesSafely(Next<M, F> item, Description mismatchDescription) {
  3. if (item.hasModel()) {
  4. mismatchDescription.appendText("has a model");
  5. return false;
  6. } else {
  7. mismatchDescription.appendText("no model");
  8. return true;
  9. }
  10. }

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

  1. @Override
  2. protected boolean matchesSafely(Next<M, F> item, Description mismatchDescription) {
  3. if (item.hasModel()) {
  4. mismatchDescription.appendText("has a model");
  5. return true;
  6. } else {
  7. mismatchDescription.appendText("no model");
  8. return false;
  9. }
  10. }

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

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

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

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

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

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

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

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

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

  1. /**
  2. * Try to get the model from this Next, with a fallback if there isn't one.
  3. *
  4. * @param fallbackModel the default model to use if the Next doesn't have a model
  5. */
  6. @Nonnull
  7. public M modelOrElse(M fallbackModel) {
  8. checkNotNull(fallbackModel);
  9. if (hasModel()) {
  10. return modelUnsafe();
  11. } else {
  12. return fallbackModel;
  13. }
  14. }

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

  1. /**
  2. * Try to get the model from this Next, with a fallback if there isn't one.
  3. *
  4. * @param fallbackModel the default model to use if the Next doesn't have a model
  5. */
  6. @Nonnull
  7. public M modelOrElse(M fallbackModel) {
  8. checkNotNull(fallbackModel);
  9. if (hasModel()) {
  10. return modelUnsafe();
  11. } else {
  12. return fallbackModel;
  13. }
  14. }

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

  1. @Override
  2. protected boolean matchesSafely(Next<M, F> item, Description mismatchDescription) {
  3. if (!item.hasModel()) {
  4. mismatchDescription.appendText("no model");
  5. return false;
  6. } else if (!matcher.matches(item.modelUnsafe())) {
  7. mismatchDescription.appendText("bad model: ");
  8. matcher.describeMismatch(item.modelUnsafe(), mismatchDescription);
  9. return false;
  10. } else {
  11. mismatchDescription.appendText("has a model: ");
  12. matcher.describeMismatch(item.modelUnsafe(), mismatchDescription);
  13. return true;
  14. }
  15. }

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

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

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

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

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

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

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

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

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

  1. @Nonnull
  2. public final Next<M, F> update(M model, E event) {
  3. MI innerModel = checkNotNull(modelExtractor().apply(model));
  4. EI innerEvent = checkNotNull(eventExtractor().apply(event));
  5. Next<MI, FI> innerNext = checkNotNull(innerUpdate().update(innerModel, innerEvent));
  6. M newModel = model;
  7. boolean modelUpdated = innerNext.hasModel();
  8. if (modelUpdated) {
  9. newModel = checkNotNull(modelUpdater().apply(model, innerNext.modelUnsafe()));
  10. }
  11. return checkNotNull(
  12. innerEffectHandler().handleInnerEffects(newModel, modelUpdated, innerNext.effects()));
  13. }

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

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

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

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

相关文章