Search in sources :

Example 1 with Delinquent

use of com.github.robozonky.app.portfolio.Delinquent in project robozonky by RoboZonky.

the class Delinquency method getOlderThan.

/**
 * Returns all loans that are presently delinquent.
 * @param days Minimum number of days a loan is in delinquency in order to be reported. 0 returns all delinquents.
 * @return All loans that are delinquent for more than the given number of days.
 */
private SortedMap<Integer, LocalDate> getOlderThan(final int days) {
    final ZoneId zone = Defaults.ZONE_ID;
    final ZonedDateTime now = LocalDate.now().atStartOfDay(zone);
    return source.get().flatMap(d -> d.getActiveDelinquency().map(Stream::of).orElse(Stream.empty())).filter(d -> d.getPaymentMissedDate().atStartOfDay(zone).plusDays(days).isBefore(now)).collect(Collectors.toMap(d -> d.getParent().getLoanId(), d -> d.getPaymentMissedDate(), (a, b) -> a, TreeMap::new));
}
Also used : ZonedDateTime(java.time.ZonedDateTime) Delinquent(com.github.robozonky.app.portfolio.Delinquent) Delinquents(com.github.robozonky.app.portfolio.Delinquents) Supplier(java.util.function.Supplier) Collectors(java.util.stream.Collectors) ZoneId(java.time.ZoneId) OffsetDateTime(java.time.OffsetDateTime) Stream(java.util.stream.Stream) TreeMap(java.util.TreeMap) LocalDate(java.time.LocalDate) Map(java.util.Map) Defaults(com.github.robozonky.internal.api.Defaults) SortedMap(java.util.SortedMap) ZoneId(java.time.ZoneId) ZonedDateTime(java.time.ZonedDateTime) Stream(java.util.stream.Stream)

Example 2 with Delinquent

use of com.github.robozonky.app.portfolio.Delinquent in project robozonky by RoboZonky.

the class DelinquencyTest method something.

@Test
void something() {
    final Delinquent delinquent = new Delinquent(1, EPOCH.toLocalDate());
    final Supplier<Stream<Delinquent>> supplier = () -> Stream.of(delinquent);
    final Delinquency d = new Delinquency(supplier);
    final int loanId = delinquent.getLoanId();
    assertSoftly(softly -> {
        softly.assertThat(d.getAll()).containsOnlyKeys(loanId);
        softly.assertThat(d.get10Plus()).containsOnlyKeys(loanId);
        softly.assertThat(d.get30Plus()).containsOnlyKeys(loanId);
        softly.assertThat(d.get60Plus()).containsOnlyKeys(loanId);
        softly.assertThat(d.get90Plus()).containsOnlyKeys(loanId);
    });
}
Also used : Delinquent(com.github.robozonky.app.portfolio.Delinquent) Stream(java.util.stream.Stream) Test(org.junit.jupiter.api.Test) AbstractRoboZonkyTest(com.github.robozonky.test.AbstractRoboZonkyTest)

Aggregations

Delinquent (com.github.robozonky.app.portfolio.Delinquent)2 Stream (java.util.stream.Stream)2 Delinquents (com.github.robozonky.app.portfolio.Delinquents)1 Defaults (com.github.robozonky.internal.api.Defaults)1 AbstractRoboZonkyTest (com.github.robozonky.test.AbstractRoboZonkyTest)1 LocalDate (java.time.LocalDate)1 OffsetDateTime (java.time.OffsetDateTime)1 ZoneId (java.time.ZoneId)1 ZonedDateTime (java.time.ZonedDateTime)1 Map (java.util.Map)1 SortedMap (java.util.SortedMap)1 TreeMap (java.util.TreeMap)1 Supplier (java.util.function.Supplier)1 Collectors (java.util.stream.Collectors)1 Test (org.junit.jupiter.api.Test)1