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

com.opencredo.concourse.domain.events.sourcing.EventCache Maven / Gradle / Ivy

package com.opencredo.concourse.domain.events.sourcing;

import com.opencredo.concourse.domain.common.AggregateId;
import com.opencredo.concourse.domain.events.Event;
import com.opencredo.concourse.domain.events.matching.EventTypeMatcher;
import com.opencredo.concourse.domain.time.TimeRange;

import java.util.*;

import static com.opencredo.concourse.domain.events.selection.EventSelection.*;

class EventCache implements EventRetriever, CachedEventSource {

    static EventCache containing(Map> events) {
        return new EventCache(events);
    }

    private final Map> events;

    private EventCache(Map> events) {
        this.events = events;
    }

    @Override
    public List getEvents(EventTypeMatcher matcher, AggregateId aggregateId, TimeRange timeRange) {
        return selectEvents(events, inRange(timeRange).and(matchedBy(matcher)), aggregateId);
    }

    @Override
    public List getEvents(AggregateId aggregateId, TimeRange timeRange) {
        return selectEvents(events, inRange(timeRange), aggregateId);
    }

    @Override
    public Map> getEvents(EventTypeMatcher matcher, String aggregateType, Collection aggregateIds, TimeRange timeRange) {
        return selectEvents(events, inRange(timeRange).and(matchedBy(matcher)), aggregateType, aggregateIds);
    }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy