All Downloads are FREE. Search and download functionalities are using the official Maven repository.

nl.vpro.domain.Changes Maven / Gradle / Ivy

Go to download

Several domains like 'media', pages' and 'subtitles' in the POMS system share some common properties which are collected here

There is a newer version: 8.3.1
Show newest version
package nl.vpro.domain;

import lombok.*;

import java.time.Instant;
import java.time.temporal.ChronoUnit;
import java.util.Optional;
import java.util.function.Supplier;

import org.checkerframework.checker.nullness.qual.NonNull;

import nl.vpro.util.CloseableIterator;

/**
 * Represent an iterable of {@link Change}'s.
 * @author Michiel Meeuwissen
 * @since 5.1
 */
@Getter
@Setter
public class Changes implements AutoCloseable, Iterable> {

    private final Instant until;
    private final Instant since;
    private final Long count;
    private final CloseableIterator> iterator;


    @Getter(AccessLevel.NONE)
    private final Supplier eta;

    @lombok.Builder
    public Changes(
        Instant since,
        Instant until,
        Long count,
        CloseableIterator> iterator,
        Supplier eta) {
        this.since = since;
        this.until = until;
        this.count = count;
        this.iterator = iterator;
        this.eta = eta == null ? () -> null : eta;
    }

    public Changes(
        Instant since,
        Instant until,
        Long count,
        CloseableIterator> iterator) {
        this(since, until, count, iterator, null);
    }

    @Override
    public void close() throws Exception {
        iterator.close();
    }
    @NonNull
    @Override
    public CloseableIterator> iterator() {
        return (CloseableIterator>) iterator;
    }

    public Optional getETA() {
        return Optional.ofNullable(this.eta.get()).map((i) -> i.truncatedTo(ChronoUnit.MINUTES));
    }

    @Override
    public String toString() {
        return "Changes until " + until + ", count:" + count + ", iterator: " + iterator;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy