<commit_before>package org.yamcs.web.rest;

import java.util.List;

import org.yamcs.parameter.ParameterValueWithId;
import org.yamcs.parameter.ParameterWithIdConsumer;


/**
 * Expected class type for use with {@link org.yamcs.web.rest.archive.RestReplays}
 * Adds functionality for stopping a replay, and has support for pagination
 */
public abstract class RestReplayListener implements ParameterWithIdConsumer {
    
    private final boolean paginate;
    private final long pos;
    private final int limit;
    
    private int rowNr = 0; // zero-based
    private int emitted = 0;
    
    private boolean abortReplay = false;
    
    public RestReplayListener() {
        paginate = false;
        pos = -1;
        limit = -1;
    }
    
    public RestReplayListener(long pos, int limit) {
        paginate = true;
        this.pos = Math.max(pos, 0);
        this.limit = Math.max(limit, 0);
    }
    
    public void requestReplayAbortion() {
        abortReplay = true;
    }
    
    public boolean isReplayAbortRequested() {
        return abortReplay;
    }

    
    
    @Override
    public void update(int subscriptionId, List<ParameterValueWithId> params) {
        List<ParameterValueWithId> filteredData = filter(params);
        if (filteredData == null) return;
        
        if (paginate) {
            if (rowNr >= pos) {
                if (emitted < limit) {
                    emitted++;
                    onParameterData(filteredData);
                } else {
                    requestReplayAbortion();
                }
            }
            rowNr++;
        } else {
            onParameterData(filteredData);
        }
    }
    
    //fast path for one parameter only
    public void update(ParameterValueWithId pvwid) {
        pvwid = filter(pvwid);
        if (pvwid == null) return;
        if (paginate) {
            if (rowNr >= pos) {
                if (emitted < limit) {
                    emitted++;
                    onParameterData(pvwid);
                } else {
                    requestReplayAbortion();
                }
            }
            rowNr++;
        } else {
            onParameterData(pvwid);
        }
    }
    /**
     * Override to filter out some replay data. Null means excluded.
     * (which also means it will not be counted towards the pagination.
     */
    public List<ParameterValueWithId> filter(List<ParameterValueWithId> params) {
        return params;
    }
    
    //fast path of the above with one parameter
    public ParameterValueWithId filter(ParameterValueWithId pvwid) {
        return pvwid;
    }
    
    protected void onParameterData(List<ParameterValueWithId> params){};
    
    protected void onParameterData(ParameterValueWithId pvwid){};
    
    public void replayFinished(){};
}<commit_msg>doc update<commit_after>package org.yamcs.web.rest;

import java.util.List;

import org.yamcs.parameter.ParameterValueWithId;
import org.yamcs.parameter.ParameterWithIdConsumer;


/**
 * Expected class type for use with {@link org.yamcs.web.rest.archive.RestReplays}
 * Adds functionality for stopping a replay, and has support for pagination
 */
public abstract class RestReplayListener implements ParameterWithIdConsumer {
    
    private final boolean paginate;
    private final long pos;
    private final int limit;
    
    private int rowNr = 0; // zero-based
    private int emitted = 0;
    
    private boolean abortReplay = false;
    
    public RestReplayListener() {
        paginate = false;
        pos = -1;
        limit = -1;
    }
    
    public RestReplayListener(long pos, int limit) {
        paginate = true;
        this.pos = Math.max(pos, 0);
        this.limit = Math.max(limit, 0);
    }
    
    public void requestReplayAbortion() {
        abortReplay = true;
    }
    
    public boolean isReplayAbortRequested() {
        return abortReplay;
    }

    
    
    @Override
    public void update(int subscriptionId, List<ParameterValueWithId> params) {
        List<ParameterValueWithId> filteredData = filter(params);
        if (filteredData == null) return;
        
        if (paginate) {
            if (rowNr >= pos) {
                if (emitted < limit) {
                    emitted++;
                    onParameterData(filteredData);
                } else {
                    requestReplayAbortion();
                }
            }
            rowNr++;
        } else {
            onParameterData(filteredData);
        }
    }
    
    //fast path for one parameter only
    public void update(ParameterValueWithId pvwid) {
        pvwid = filter(pvwid);
        if (pvwid == null) return;
        if (paginate) {
            if (rowNr >= pos) {
                if (emitted < limit) {
                    emitted++;
                    onParameterData(pvwid);
                } else {
                    requestReplayAbortion();
                }
            }
            rowNr++;
        } else {
            onParameterData(pvwid);
        }
    }
    /**
     * Override to filter out some replay data. Null means excluded.
     * (which also means it will not be counted towards the pagination.
     * @param params 
     * @return filtered data
     */
    public List<ParameterValueWithId> filter(List<ParameterValueWithId> params) {
        return params;
    }
    
    //fast path of the above with one parameter
    public ParameterValueWithId filter(ParameterValueWithId pvwid) {
        return pvwid;
    }
    
    protected void onParameterData(List<ParameterValueWithId> params){};
    
    protected void onParameterData(ParameterValueWithId pvwid){};
    
    public void replayFinished(){};
}
{'fraction_non_alphanumeric': 0.0843585237258348, 'fraction_numerical': 0.00210896309314587, 'mean_word_length': 1.8426573426573427, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '16710', 'n_tokens_mistral': 1594, 'n_tokens_neox': 1539, 'n_words': 408}