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

com.opencredo.concursus.domain.events.state.StateRepository Maven / Gradle / Ivy

The newest version!
package com.opencredo.concursus.domain.events.state;

import java.time.Instant;
import java.util.*;

/**
 * A repository of state objects.
 * @param  The type of the state objects made available by this repository.
 */
public interface StateRepository {

    /**
     * Fetch an object representing the state of the aggregate with this id, at the given moment in time.
     * @param aggregateId The aggregate id to query for.
     * @param upTo The moment in time (exclusive) at which to obtain the aggregate's state.
     * @return The state of the aggregate, if it existed at that moment.
     */
    Optional getState(String aggregateId, Instant upTo);

    /**
     * Fetch an object representing the current state of the aggregate with this id.
     * @param aggregateId The aggregate id to query for.
     * @return The state of the aggregate, if it exists.
     */
    default Optional getState(String aggregateId) {
        return getState(aggregateId, Instant.MAX);
    }

    /**
     * Fetch a collection of objects representing the state of the aggregates with the requested ids, at the given
     * moment in time.
     * @param aggregateIds The aggregate ids to retrieve states for.
     * @param upTo The moment in time (exclusive) at which to obtain the aggregates' state.
     * @return The aggregates' states, mapped by aggregate id.
     */
    Map getStates(Collection aggregateIds, Instant upTo);

    /**
     * Fetch a collection of objects representing the current state of the aggregates with the requested ids.
     * moment in time.
     * @param aggregateIds The aggregate ids to retrieve states for.
     * @return The aggregates' states, mapped by aggregate id.
     */
    default Map getStates(Collection aggregateIds) {
        return getStates(aggregateIds, Instant.MAX);
    }

    /**
     * Fetch a collection of objects representing the current state of the aggregates with the requested ids.
     * moment in time.
     * @param aggregateIds The aggregate ids to retrieve states for.
     * @return The aggregates' states, mapped by aggregate id.
     */
    default Map getStates(String...aggregateIds) {
        return getStates(Arrays.asList(aggregateIds));
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy