private void purchase(final PurchaseStrategy strategy) { boolean invested; do { invested = strategy.recommend(getAvailable(), tenant.getPortfolio().getOverview(), tenant.getRestrictions()) .filter(r -> tenant.getPortfolio().getBalance().compareTo(r.amount()) >= 0) .peek(r -> tenant.fire(purchaseRecommended(r))) .anyMatch(this::purchase); // keep trying until investment opportunities are exhausted } while (invested); }
private void purchase(final PurchaseStrategy strategy) { boolean invested; do { invested = strategy.recommend(getAvailable(), tenant.getPortfolio().getOverview(), tenant.getRestrictions()) .filter(r -> tenant.getPortfolio().getBalance().compareTo(r.amount()) >= 0) .peek(r -> tenant.fire(purchaseRecommended(r))) .anyMatch(this::purchase); // keep trying until investment opportunities are exhausted } while (invested); }
@Test void recommend() { final Participation p = mockParticipation(BigDecimal.TEN); final ParticipationDescriptor pd = new ParticipationDescriptor(p, () -> LOAN); final Optional<RecommendedParticipation> r = pd.recommend(p.getRemainingPrincipal()); assertThat(r).isPresent(); assertSoftly(softly -> { softly.assertThat(r.get().amount()).isEqualTo(p.getRemainingPrincipal()); softly.assertThat(r.get().descriptor().related()).isSameAs(LOAN); softly.assertThat(r.get().descriptor()).isEqualTo(pd); }); }
private boolean purchase(final RecommendedParticipation recommendation) { tenant.fire(purchaseRequested(recommendation)); final Participation participation = recommendation.descriptor().item(); final Loan l = recommendation.descriptor().related(); final boolean succeeded = tenant.getSessionInfo().isDryRun() || actualPurchase(participation); final Investment i = Investment.fresh(participation, l, recommendation.amount()); discarded.put(recommendation.descriptor()); // don't purchase this one again in dry run if (succeeded) { markSuccessfulPurchase(i); tenant.fire(investmentPurchasedLazy(() -> investmentPurchased(i, l, tenant.getPortfolio().getOverview()))); } return succeeded; }
private boolean purchase(final RecommendedParticipation recommendation) { tenant.fire(purchaseRequested(recommendation)); final Participation participation = recommendation.descriptor().item(); final Loan l = recommendation.descriptor().related(); final boolean succeeded = tenant.getSessionInfo().isDryRun() || actualPurchase(participation); final Investment i = Investment.fresh(participation, l, recommendation.amount()); discarded.put(recommendation.descriptor()); // don't purchase this one again in dry run if (succeeded) { markSuccessfulPurchase(i); tenant.fire(investmentPurchasedLazy(() -> investmentPurchased(i, l, tenant.getPortfolio().getOverview()))); } return succeeded; }