<commit_before>/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package net.domesdaybook.searcher.multisequence;

/**
 *
 * @author matt
 */
public class NaiveMultiSequenceSearcher {
    //TODO: write me.
}<commit_msg>First draft of generic multisequencesearcher.<commit_after>/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package net.domesdaybook.searcher.multisequence;

import net.domesdaybook.matcher.multisequence.MultiSequenceMatcher;
import net.domesdaybook.reader.ByteReader;
import net.domesdaybook.searcher.Searcher;

/**
 *
 * @author matt
 */
public class NaiveMultiSequenceSearcher implements Searcher {
    
    private final MultiSequenceMatcher matcher;

    NaiveMultiSequenceSearcher(final MultiSequenceMatcher matcher) {
        if (matcher == null) {
            throw new IllegalArgumentException("Null matcher passed in.");
        }
        this.matcher = matcher;
    }
    
    
    public long searchForwards(ByteReader reader, long fromPosition, long toPosition) {
        final long lastPossiblePosition = reader.length() - 1;
        final long upToPosition = toPosition < lastPossiblePosition? toPosition : lastPossiblePosition;
        long currentPosition = fromPosition > 0? fromPosition : 0;
        while (currentPosition <= upToPosition) {
            if (matcher.matches(reader, currentPosition)) {
                return currentPosition;
            }
            currentPosition++;
        }
        return Searcher.NOT_FOUND;
    }

    
    public long searchBackwards(ByteReader reader, long fromPosition, long toPosition) {
        final long lastPossiblePosition = reader.length() - 1;
        final long upToPosition = toPosition > 0? toPosition : 0;
        long currentPosition = fromPosition < lastPossiblePosition? fromPosition : lastPossiblePosition;
        while (currentPosition >= upToPosition) {
            if (matcher.matches(reader, currentPosition)) {
                return currentPosition;
            }
            currentPosition--;
        }
        
        return Searcher.NOT_FOUND;
    }
    
    
    
}
{'fraction_non_alphanumeric': 0.0799265043638034, 'fraction_numerical': 0.002756086357372531, 'mean_word_length': 2.7746967071057194, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 6, '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': '3753349', 'n_tokens_mistral': 589, 'n_tokens_neox': 578, 'n_words': 151}