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

org.zalando.nakadiproducer.snapshots.SimpleSnapshotEventGenerator Maven / Gradle / Ivy

There is a newer version: 30.0.0-RC1
Show newest version
package org.zalando.nakadiproducer.snapshots;

import org.springframework.lang.Nullable;

import java.util.List;
import java.util.function.BiFunction;
import java.util.function.Function;

/**
 * This is a simple implementation of the {@link SnapshotEventGenerator}. It is
 * meant to be used in a functional style.
 *
 * @see SnapshotEventGenerator
 * @deprecated Please use the {@link SnapshotEventGenerator#of} methods instead.
 */
@Deprecated
public final class SimpleSnapshotEventGenerator implements SnapshotEventGenerator {
    private final String supportedEventType;
    private final BiFunction> getSnapshotFunction;

    /**
     * Creates a SnapshotEventGenerator for an event type, which doesn't support
     * filtering.
     *
     * @param supportedEventType
     *            the eventType that this SnapShotEventProvider will support.
     * @param snapshotEventFactory
     *            a snapshot event factory function conforming to the
     *            specification of
     *            {@link SnapshotEventGenerator#generateSnapshots(Object, String)}
     *            (but without the filter parameter). Any filter provided by the
     *            caller will be thrown away.
     */
    public SimpleSnapshotEventGenerator(String supportedEventType,
            Function> snapshotEventFactory) {
        this.supportedEventType = supportedEventType;
        this.getSnapshotFunction = (id, filter) -> snapshotEventFactory.apply(id);
    }

    /**
     * Creates a SnapshotEventGenerator for an event type, with filtering
     * support.
     *
     * @param supportedEventType
     *            the eventType that this SnapShotEventProvider will support.
     * @param snapshotEventFactory
     *            a snapshot event factory function conforming to the
     *            specification of
     *            {@link SnapshotEventGenerator#generateSnapshots(Object, String)}.
     */
    public SimpleSnapshotEventGenerator(String supportedEventType,
            BiFunction> snapshotEventFactory) {
        this.supportedEventType = supportedEventType;
        this.getSnapshotFunction = snapshotEventFactory;
    }

    @Override
    public List generateSnapshots(@Nullable Object withIdGreaterThan, String filter) {
        return getSnapshotFunction.apply(withIdGreaterThan, filter);
    }

    @Override
    public String getSupportedEventType() {
        return supportedEventType;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy