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

com.kolibrifx.plovercrest.server.internal.streams.NonOverlappingRangeObserver Maven / Gradle / Ivy

The newest version!
/*
 * Copyright (c) 2010-2017, KolibriFX AS. Licensed under the Apache License, version 2.0.
 */

package com.kolibrifx.plovercrest.server.internal.streams;

import com.kolibrifx.plovercrest.server.streams.StreamObserver;

public class NonOverlappingRangeObserver extends RangeStreamObserver {

    private final long startTimestamp;
    private final long endTimestamp;
    private int skipCount;

    public NonOverlappingRangeObserver(final StreamObserver wrappedObserver,
                                       final long startTimestamp,
                                       final long endTimestamp,
                                       final int skipCount) {
        super(wrappedObserver);
        this.startTimestamp = startTimestamp;
        this.endTimestamp = endTimestamp;
        this.skipCount = skipCount;
    }

    @Override
    public void onObserveImpl(final long timestamp, final long index, final T element) {
        if (skipCount > 0) {
            skipCount--;
            return;
        }
        if (timestamp < startTimestamp) {
            // skip first element if needed
            return;
        }
        if (timestamp >= endTimestamp) {
            throwEndOfRange();
        }
        callWrappedObserver(timestamp, index, element);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy