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

com.exasol.adapter.document.documentfetcher.files.segmentation.FileSegmentDescriptionMatcher Maven / Gradle / Ivy

There is a newer version: 8.1.3
Show newest version
package com.exasol.adapter.document.documentfetcher.files.segmentation;

import java.util.List;

/**
 * This class matches part descriptions of a file against a {@link FileSegmentDescription}.
 */
public class FileSegmentDescriptionMatcher {
    private final FileSegmentDescription segmentDescription;

    /**
     * Create a new {@link FileSegmentDescriptionMatcher}.
     * 
     * @param segmentDescription segment description
     */
    public FileSegmentDescriptionMatcher(final FileSegmentDescription segmentDescription) {
        this.segmentDescription = segmentDescription;
    }

    /**
     * Matches part descriptions of a file against a {@link FileSegmentDescription}.
     * 
     * @param splits list of parts
     * @param     type of the part descriptions
     * @return matched parts
     */
    public  List filter(final List splits) {
        final int numberOfSegments = this.segmentDescription.getNumberOfSegments();
        final double segmentSize = (double) splits.size() / (double) numberOfSegments;
        final int segmentId = this.segmentDescription.getSegmentId();
        final int start = (int) Math.round(segmentId * segmentSize);
        final int end = (int) Math.round((segmentId + 1) * segmentSize);
        return splits.subList(start, end);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy