@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; } }
@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); } }
@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); } }
/** * 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; } }
/** * 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; } }
/** 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()); } }
/** 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()); } }
@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())); }